diff --git a/src/main/java/xyz/alexcrea/cuanvil/config/ConfigHolder.java b/src/main/java/xyz/alexcrea/cuanvil/config/ConfigHolder.java index 6fafded..eb74480 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/config/ConfigHolder.java +++ b/src/main/java/xyz/alexcrea/cuanvil/config/ConfigHolder.java @@ -89,6 +89,7 @@ public abstract class ConfigHolder { // Save logic public boolean saveToDisk(boolean doBackup) { + CustomAnvil.Companion.log("Saving "+getConfigFileName()); if (doBackup) { if (!saveBackup()) { CustomAnvil.instance.getLogger().severe("Could not save backup. see above."); @@ -110,6 +111,7 @@ public abstract class ConfigHolder { return false; } + CustomAnvil.Companion.log(getConfigFileName()+" saved successfully"); return true; } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java index ed00af6..0663347 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java @@ -22,7 +22,7 @@ public class CustomRecipeConfigGui extends MappedElementListConfigGui extends ValueUpdatableGui { + private final String namePrefix; public ElementListGlobalConfigGui(@NotNull String title) { super(6, title, CustomAnvil.instance); + this.namePrefix = title; } @@ -229,7 +231,12 @@ public abstract class ElementListGlobalConfigGui< T > extends ValueUpdatableGui addPane(page); // set title - setTitle("Conflict Config (" + (pageID + 1) + "/" + (pages.size()) + ")"); + StringBuilder title = new StringBuilder(this.namePrefix); + int pagesSize = this.pages.size(); + if(pagesSize > 1){ + title.append(" (").append(pageID + 1).append('/').append(pagesSize).append(')'); + } + setTitle(title.toString()); super.show(humanEntity); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/CustomRecipeSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/CustomRecipeSubSettingGui.java index 7cea19d..9465968 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/CustomRecipeSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/CustomRecipeSubSettingGui.java @@ -37,7 +37,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { @NotNull CustomRecipeConfigGui parent, @NotNull AnvilCustomRecipe anvilRecipe, @NotNull GuiItem parentItemForThisGui) { - super(parentItemForThisGui, 3, "title"); + super(parentItemForThisGui, 3, "\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(anvilRecipe.getName()) + " \u00A78Config"); this.parent = parent; this.anvilRecipe = anvilRecipe; @@ -76,24 +76,24 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { // Displayed item will be updated later IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE(); - exactCountFactory = BoolSettingsGui.boolFactory("title", this, + this.exactCountFactory = BoolSettingsGui.boolFactory("\u00A78Exact count ?", this, this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, AnvilCustomRecipe.Companion.getDEFAULT_EXACT_COUNT_CONFIG()); - xpCostFactory = IntSettingsGui.intFactory("title", this, + this.xpCostFactory = IntSettingsGui.intFactory("\u00A78Recipe Xp Cost", this, this.anvilRecipe.getName()+"."+AnvilCustomRecipe.XP_COST_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.Companion.getDEFAULT_XP_COST_CONFIG(), 1, 5, 10); - leftItemFactory = ItemSettingGui.itemFactory("title", this, + this.leftItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7eLeft \u00A78Item", this, this.anvilRecipe.getName()+"."+AnvilCustomRecipe.LEFT_ITEM_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG()); - rightItemFactory = ItemSettingGui.itemFactory("title", this, + this.rightItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7eLeft \u00A78Item", this, this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG()); - resultItemFactory = ItemSettingGui.itemFactory("title", this, + this.resultItemFactory = ItemSettingGui.itemFactory("\u00A78Recipe \u00A7aResult \u00A78Item", this, this.anvilRecipe.getName()+"."+AnvilCustomRecipe.EXACT_COUNT_CONFIG, ConfigHolder.CUSTOM_RECIPE_HOLDER, AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG()); } @@ -131,83 +131,23 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui { @Override public void updateGuiValues() { + // update value from config to conflict + this.anvilRecipe.updateFromFile(); + + // Parent should call updateLocal with this call this.parent.updateValueForGeneric(this.anvilRecipe, true); - // Parent should call updateLocal } public void updateLocal() { if (!this.shouldWork) return; - /*// Prepare enchantment lore - ArrayList enchantLore = new ArrayList<>(); - enchantLore.add("\u00A77Allow you to select a list of \u00A75Enchantments \u00A77that this conflict should include"); - Set enchants = getSelectedEnchantments(); - if (enchants.isEmpty()) { - enchantLore.add("\u00A77There is no included enchantment for this conflict."); - } else { - enchantLore.add("\u00A77List of included enchantment for this conflict:"); - Iterator enchantIterator = enchants.iterator(); + GuiItem exactCountItem = GuiGlobalItems.boolSettingGuiItem(this.exactCountFactory); + pane.bindItem('1', exactCountItem); - boolean greaterThanMax = enchants.size() > 5; - int maxindex = (greaterThanMax ? 4 : enchants.size()); - for (int i = 0; i < maxindex; i++) { - // format string like "- Fire Protection" - String formattedName = CasedStringUtil.snakeToUpperSpacedCase(enchantIterator.next().getKey().getKey()); - enchantLore.add("\u00A77- \u00A75" + formattedName); - } - if (greaterThanMax) { - enchantLore.add("\u00A77And " + (enchants.size() - 4) + " more..."); - } - - } - - // Prepare group lore - ArrayList groupLore = new ArrayList<>(); - groupLore.add("\u00A77Allow you to select a list of \u00A73Groups \u00A77that this conflict should include"); - Set grouos = getSelectedGroups(); - if (grouos.isEmpty()) { - groupLore.add("\u00A77There is no excluded groups for this conflict."); - } else { - groupLore.add("\u00A77List of excluded groups for this conflict:"); - Iterator groupIterator = grouos.iterator(); - - boolean greaterThanMax = grouos.size() > 5; - int maxindex = (greaterThanMax ? 4 : grouos.size()); - for (int i = 0; i < maxindex; i++) { - // format string like "- Melee Weapons" - String formattedName = CasedStringUtil.snakeToUpperSpacedCase(groupIterator.next().getName()); - groupLore.add("\u00A77- \u00A73" + formattedName); - - } - if (greaterThanMax) { - groupLore.add("\u00A77And " + (grouos.size() - 4) + " more..."); - } - } - - // Configure enchant setting item - ItemStack enchantItem = this.enchantSettingItem.getItem(); - ItemMeta enchantMeta = enchantItem.getItemMeta(); - - enchantMeta.setDisplayName("\u00A7aSelect included \u00A75Enchantments \u00A7aSettings"); - enchantMeta.setLore(enchantLore); - - enchantItem.setItemMeta(enchantMeta); - - this.enchantSettingItem.setItem(enchantItem); // Just in case - - // Configure group setting item - ItemStack groupItem = this.groupSettingItem.getItem(); - ItemMeta groupMeta = groupItem.getItemMeta(); - - groupMeta.setDisplayName("\u00A7aSelect excluded \u00A73Groups \u00A7aSettings"); - groupMeta.setLore(groupLore); - - groupItem.setItemMeta(groupMeta); - - this.groupSettingItem.setItem(groupItem); // Just in case + GuiItem xpCostItem = GuiGlobalItems.intSettingGuiItem(this.xpCostFactory, Material.EXPERIENCE_BOTTLE); + pane.bindItem('2', xpCostItem); - this.pane.bindItem('M', GuiGlobalItems.intSettingGuiItem(this.minBeforeActiveSettingFactory, Material.COMMAND_BLOCK));*/ update(); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/EnchantConflictSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/EnchantConflictSubSettingGui.java index 0acaa8c..b9cfefa 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/EnchantConflictSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/subsetting/EnchantConflictSubSettingGui.java @@ -148,8 +148,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl @Override public void updateGuiValues() { + // update value from config to conflict + int minBeforeBlock = ConfigHolder.CONFLICT_HOLDER.getConfig().getInt(this.enchantConflict.getName()+'.'+EnchantConflictManager.ENCH_MAX_PATH, 0); + this.enchantConflict.setMinBeforeBlock(minBeforeBlock); + + // Parent should call updateLocal with this call this.parent.updateValueForGeneric(this.enchantConflict, true); - // Parent should call updateLocal } @Override diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt index 7acf857..44a4bef 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt @@ -8,7 +8,7 @@ import xyz.alexcrea.cuanvil.interfaces.Named class EnchantConflictGroup( private val name: String, private val cantConflict: AbstractMaterialGroup, - val minBeforeBlock: Int + var minBeforeBlock: Int ): Named { private val enchantments = HashSet() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt index edb1a18..41b7b09 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt @@ -89,10 +89,38 @@ class AnvilCustomRecipe( if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) { - ConfigHolder.CONFLICT_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE); + ConfigHolder.CUSTOM_RECIPE_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE); } } + fun updateFromFile(){ + this.exactCount = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getBoolean( + "$name.$EXACT_COUNT_CONFIG", + DEFAULT_EXACT_COUNT_CONFIG + ) + + this.xpCostPerCraft = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getInt( + "$name.$XP_COST_CONFIG", + DEFAULT_XP_COST_CONFIG + ) + + // Update items + this.leftItem = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getItemStack( + "$name.$LEFT_ITEM_CONFIG", + DEFAULT_LEFT_ITEM_CONFIG + ) + + this.rightItem = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getItemStack( + "$name.$RIGHT_ITEM_CONFIG", + DEFAULT_RIGHT_ITEM_CONFIG + ) + + this.resultItem = ConfigHolder.CUSTOM_RECIPE_HOLDER.config.getItemStack( + "$name.$RESULT_ITEM_CONFIG", + DEFAULT_RESULT_ITEM_CONFIG + ) + } + fun testItem(item1: ItemStack, item2: ItemStack?): Boolean { // We assume this function can be call only if leftItem != null