mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
Add int value item.
This commit is contained in:
parent
942e7e861e
commit
ad7f56357c
4 changed files with 39 additions and 14 deletions
|
|
@ -5,11 +5,9 @@ import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
|||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.utils.GuiGlobalItems;
|
||||
|
|
@ -46,9 +44,8 @@ public class BasicConfigGui extends ValueUpdatableGui {
|
|||
@Override
|
||||
public void updateGuiValues() {
|
||||
// Update item with value
|
||||
ItemStack setting1Item = new ItemStack(Material.STONE);
|
||||
AbstractSettingGui.SettingGuiFactory factory1 = IntSettingsGui.factory( "Test GUI", this, "test", ConfigHolder.DEFAULT_CONFIG, 0,255,2,1, 5, 10, 50, 100);
|
||||
GuiItem setting1 = GuiGlobalItems.openSettingGuiItem(setting1Item, factory1);
|
||||
IntSettingsGui.IntSettingFactory factory1 = IntSettingsGui.factory( "Test GUI", this, "test", ConfigHolder.DEFAULT_CONFIG, 0,255,2,1, 5, 10, 50, 100);
|
||||
GuiItem setting1 = GuiGlobalItems.intSettingGuiItem(factory1, Material.COMMAND_BLOCK);
|
||||
pane.bindItem('1', setting1);
|
||||
|
||||
BoolSettingsGui.BoolSettingFactory factory2 = BoolSettingsGui.factory("Test Gui bool",this, "test2", ConfigHolder.DEFAULT_CONFIG, false);
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
|||
return true;
|
||||
}
|
||||
|
||||
public static SettingGuiFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
||||
public static IntSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
||||
String configPath, ConfigHolder config,
|
||||
int min, int max, int defaultVal, int... steps){
|
||||
return new IntSettingFactory(
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ public class GuiGlobalItems {
|
|||
}
|
||||
|
||||
private static final String SETTING_ITEM_LORE_PREFIX = "\u00A77value: ";
|
||||
|
||||
public static GuiItem boolSettingGuiItem(
|
||||
@NotNull BoolSettingsGui.BoolSettingFactory factory
|
||||
){
|
||||
|
|
@ -87,21 +89,42 @@ public class GuiGlobalItems {
|
|||
boolean value = factory.getConfiguredValue();
|
||||
|
||||
Material itemMat;
|
||||
StringBuilder itemName = new StringBuilder("\u00A7");
|
||||
StringBuilder partOfItemName = new StringBuilder("\u00A7");
|
||||
if(value){
|
||||
itemMat = Material.GREEN_TERRACOTTA;
|
||||
itemName.append("a");
|
||||
partOfItemName.append("a");
|
||||
}else{
|
||||
itemMat = Material.RED_TERRACOTTA;
|
||||
itemName.append("c");
|
||||
partOfItemName.append("c");
|
||||
}
|
||||
itemName.append(getConfigNameFromPath(factory.getConfigPath()));
|
||||
return createGuiItemFromProperties(factory, itemMat, partOfItemName, value);
|
||||
}
|
||||
|
||||
|
||||
public static GuiItem intSettingGuiItem(
|
||||
@NotNull IntSettingsGui.IntSettingFactory factory,
|
||||
@NotNull Material itemMat
|
||||
){
|
||||
// Get item properties
|
||||
int value = factory.getConfiguredValue();
|
||||
StringBuilder partOfItemName = new StringBuilder("\u00A7a");
|
||||
|
||||
return createGuiItemFromProperties(factory, itemMat, partOfItemName, value);
|
||||
}
|
||||
|
||||
private static GuiItem createGuiItemFromProperties(
|
||||
@NotNull AbstractSettingGui.SettingGuiFactory factory,
|
||||
@NotNull Material itemMat,
|
||||
@NotNull StringBuilder partOfItemName,
|
||||
@NotNull Object value
|
||||
){
|
||||
partOfItemName.append(getConfigNameFromPath(factory.getConfigPath()));
|
||||
|
||||
// Create item
|
||||
ItemStack item = new ItemStack(itemMat);
|
||||
ItemMeta itemMeta = item.getItemMeta();
|
||||
|
||||
itemMeta.setDisplayName(itemName.toString());
|
||||
itemMeta.setDisplayName(partOfItemName.toString());
|
||||
itemMeta.setLore(Collections.singletonList(SETTING_ITEM_LORE_PREFIX+value));
|
||||
|
||||
item.setItemMeta(itemMeta);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.bukkit.command.Command
|
|||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.gui.config.BasicConfigGui
|
||||
|
||||
class ReloadExecutor : CommandExecutor {
|
||||
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
||||
|
|
@ -30,11 +31,15 @@ class ReloadExecutor : CommandExecutor {
|
|||
* Execute the command, return true if success or false otherwise
|
||||
*/
|
||||
private fun commandBody(hardfail: Boolean): Boolean{
|
||||
return try {
|
||||
ConfigHolder.reloadAllFromDisk(hardfail)
|
||||
try {
|
||||
if(!ConfigHolder.reloadAllFromDisk(hardfail)) return false;
|
||||
|
||||
// Then update all global gui containing value from config
|
||||
BasicConfigGui.INSTANCE.updateGuiValues();
|
||||
return true;
|
||||
}catch (e: Exception){
|
||||
e.printStackTrace()
|
||||
false
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue