diff --git a/src/main/java/xyz/alexcrea/cuanvil/config/WorkPenaltyType.java b/src/main/java/xyz/alexcrea/cuanvil/config/WorkPenaltyType.java index e172662..95edca6 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/config/WorkPenaltyType.java +++ b/src/main/java/xyz/alexcrea/cuanvil/config/WorkPenaltyType.java @@ -1,23 +1,36 @@ package xyz.alexcrea.cuanvil.config; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui; +import xyz.alexcrea.cuanvil.gui.config.settings.EnumSettingGui; -public enum WorkPenaltyType { - DEFAULT("default", true, true), - INCREASE("increase_only", true, false), - ADDITIVE("add_only", false, true), - DISABLED("disabled", false, false), +import java.util.ArrayList; +import java.util.List; + +public enum WorkPenaltyType implements EnumSettingGui.ConfigurableEnum { + DEFAULT("default", true, true, "§aDefault", Material.LIME_TERRACOTTA), + ADDITIVE("add_only", false, true, "§eAdd Only", Material.YELLOW_TERRACOTTA), + INCREASE("increase_only", true, false, "§eIncrease Only", Material.YELLOW_TERRACOTTA), + DISABLED("disabled", false, false, "§cDisabled", Material.RED_TERRACOTTA), ; private final String name; private final boolean penaltyIncrease; private final boolean penaltyAdditive; - WorkPenaltyType(String name, boolean penaltyIncrease, boolean penaltyAdditive) { + private final String configName; + private final Material configMaterial; + + WorkPenaltyType(String name, boolean penaltyIncrease, boolean penaltyAdditive, String configName, Material configMaterial) { this.name = name; this.penaltyIncrease = penaltyIncrease; this.penaltyAdditive = penaltyAdditive; + this.configName = configName; + this.configMaterial = configMaterial; } public boolean isPenaltyIncreasing() { @@ -47,4 +60,55 @@ public enum WorkPenaltyType { return DEFAULT; } + @NotNull + public static WorkPenaltyType next(@NotNull WorkPenaltyType now){ + return switch (now){ + case DEFAULT -> ADDITIVE; + case ADDITIVE -> INCREASE; + case INCREASE -> DISABLED; + case DISABLED -> DEFAULT; + + }; + + } + + @Override + public ItemStack configurationGuiItem() { + ItemStack displayedItem = new ItemStack(this.configMaterial); + ItemMeta valueMeta = displayedItem.getItemMeta(); + assert valueMeta != null; + + valueMeta.setDisplayName(this.configName); + + List lore = new ArrayList<>(); + + lore.add(configDisplayForAdd()); + lore.add(configDisplayForIncrease()); + lore.add(""); + + lore.add(AbstractSettingGui.CLICK_LORE); + valueMeta.setLore(lore); + + displayedItem.setItemMeta(valueMeta); + + return displayedItem; + } + + public String configDisplayForAdd(){ + return ("§7Add penalty: " + (penaltyAdditive ? "§aYes" : "§cNo")); + } + + public String configDisplayForIncrease(){ + return ("§7Increase penalty: " + (penaltyIncrease ? "§aYes" : "§cNo")); + } + + @Override + public String configName() { + return this.name; + } + + @Override + public String configurationGuiName() { + return this.configName; + } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java index 235e1d4..4f98cc3 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta; import xyz.alexcrea.cuanvil.dependency.packet.PacketManager; import xyz.alexcrea.cuanvil.gui.config.global.*; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; +import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import java.util.Collections; @@ -28,7 +29,7 @@ public class MainConfigGui extends ChestGui { public void init(PacketManager packetManager) { Pattern pattern = new Pattern( - "000000000", + GuiSharedConstant.EMPTY_GUI_FULL_LINE, "012304567", "Q00000000" ); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java index bb7e3fb..d689921 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java @@ -14,10 +14,12 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.config.WorkPenaltyType; import xyz.alexcrea.cuanvil.dependency.packet.PacketManager; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui; +import xyz.alexcrea.cuanvil.gui.config.settings.EnumSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; @@ -26,6 +28,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.List; /** * Global config to edit basic basic settings. @@ -59,7 +62,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { private void init() { Pattern pattern = new Pattern( GuiSharedConstant.EMPTY_GUI_FULL_LINE, - "LT0I0S0cp", + "LT0IWS0cp", "CR0U0r0hP", "B00000000" ); @@ -86,6 +89,8 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { private IntSettingsGui.IntSettingFactory itemRenameCost; // r character private IntSettingsGui.IntSettingFactory sacrificeIllegalEnchantCost; // S character + private EnumSettingGui.EnumSettingFactory workPenaltyType; // W character + private BoolSettingsGui.BoolSettingFactory allowColorCode; // c character private BoolSettingsGui.BoolSettingFactory allowHexColor; // h character @@ -99,7 +104,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { */ protected void prepareValues() { // cap anvil cost - this.capAnvilCost = BoolSettingsGui.boolFactory("§8Cap Anvil Cost ?", this, + this.capAnvilCost = new BoolSettingsGui.BoolSettingFactory("§8Cap Anvil Cost ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.CAP_ANVIL_COST, ConfigOptions.DEFAULT_CAP_ANVIL_COST, "§7All anvil cost will be capped to §aMax Anvil Cost§7 if enabled.", @@ -118,7 +123,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // repair cost item IntRange range = ConfigOptions.MAX_ANVIL_COST_RANGE; - this.maxAnvilCost = IntSettingsGui.intFactory("§8Max Anvil Cost", this, + this.maxAnvilCost = new IntSettingsGui.IntSettingFactory("§8Max Anvil Cost", this, ConfigOptions.MAX_ANVIL_COST, ConfigHolder.DEFAULT_CONFIG, Arrays.asList( "§7Max cost the Anvil can get to.", @@ -142,7 +147,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // remove repair limit item - this.removeAnvilCostLimit = BoolSettingsGui.boolFactory("§8Remove Anvil Cost Limit ?", this, + this.removeAnvilCostLimit = new BoolSettingsGui.BoolSettingFactory("§8Remove Anvil Cost Limit ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.REMOVE_ANVIL_COST_LIMIT, ConfigOptions.DEFAULT_REMOVE_ANVIL_COST_LIMIT, "§7Whether the anvil's cost limit should be removed entirely.", @@ -150,7 +155,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { "§7However, the action will be completable if xp requirement is meet."); // replace too expensive item - this.replaceTooExpensive = BoolSettingsGui.boolFactory("§8Replace Too Expensive ?", this, + this.replaceTooExpensive = new BoolSettingsGui.BoolSettingFactory("§8Replace Too Expensive ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.REPLACE_TOO_EXPENSIVE, ConfigOptions.DEFAULT_REPLACE_TOO_EXPENSIVE, getReplaceToExpensiveLore()); @@ -161,7 +166,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // item repair cost range = ConfigOptions.REPAIR_COST_RANGE; - this.itemRepairCost = IntSettingsGui.intFactory("§8Item Repair Cost", this, + this.itemRepairCost = new IntSettingsGui.IntSettingFactory("§8Item Repair Cost", this, ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, Arrays.asList( "§7XP Level amount added to the anvil when the item", @@ -172,7 +177,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { 1, 5, 10, 50, 100); // unit repair cost - this.unitRepairCost = IntSettingsGui.intFactory("§8Unit Repair Cost", this, + this.unitRepairCost = new IntSettingsGui.IntSettingFactory("§8Unit Repair Cost", this, ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, Arrays.asList( "§7XP Level amount added to the anvil when the item is repaired by an §eunit§7.", @@ -185,7 +190,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // item rename cost range = ConfigOptions.ITEM_RENAME_COST_RANGE; - this.itemRenameCost = IntSettingsGui.intFactory("§8Rename Cost", this, + this.itemRenameCost = new IntSettingsGui.IntSettingFactory("§8Rename Cost", this, ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG, Arrays.asList( "§7XP Level amount added to the anvil when the item is renamed." @@ -196,7 +201,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // sacrifice illegal enchant cost range = ConfigOptions.SACRIFICE_ILLEGAL_COST_RANGE; - this.sacrificeIllegalEnchantCost = IntSettingsGui.intFactory("§8Sacrifice Illegal Enchant Cost", this, + this.sacrificeIllegalEnchantCost = new IntSettingsGui.IntSettingFactory("§8Sacrifice Illegal Enchant Cost", this, ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG, Arrays.asList( "§7XP Level amount added to the anvil when a sacrifice enchantment", @@ -206,12 +211,52 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { ConfigOptions.DEFAULT_SACRIFICE_ILLEGAL_COST, 1, 5, 10, 50, 100); + // ------------- + // Work Penalty + // ------------- + + this.workPenaltyType = new EnumSettingGui.EnumSettingFactory<>("§8Work Penalty Type", this, + ConfigOptions.WORK_PENALTY_TYPE, ConfigHolder.DEFAULT_CONFIG + ) { + @NotNull + @Override + public WorkPenaltyType getConfiguredValue() { + return ConfigOptions.INSTANCE.getWorkPenaltyType(); + } + + @NotNull + @Override + public WorkPenaltyType getDefault() { + return WorkPenaltyType.DEFAULT; + } + + @NotNull + @Override + public List getDisplayLore(WorkPenaltyType value) { + return List.of( + "§7Work penalty increase the price for every anvil use.", + "§7This config allow you to choose the comportment of work penalty.", + "", + value.configDisplayForAdd(), + value.configDisplayForIncrease() + + ); + } + + @NotNull + @Override + public WorkPenaltyType next(@NotNull WorkPenaltyType now) { + return WorkPenaltyType.next(now); + } + + }; + // ------------- // Color config // ------------- // Allow us of color code - this.allowColorCode = BoolSettingsGui.boolFactory("§8Allow Use Of Color Code ?", this, + this.allowColorCode = new BoolSettingsGui.BoolSettingFactory("§8Allow Use Of Color Code ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.ALLOW_COLOR_CODE, ConfigOptions.DEFAULT_ALLOW_COLOR_CODE, "§7Whether players can use color code.", @@ -219,7 +264,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { "§7Player may need permission to use color code if §ePlayer need permission to use color§7 is enabled."); // Allow us of hexadecimal color - this.allowHexColor = BoolSettingsGui.boolFactory("§8Allow Use Of Hexadecimal Color ?", this, + this.allowHexColor = new BoolSettingsGui.BoolSettingFactory("§8Allow Use Of Hexadecimal Color ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.ALLOW_HEXADECIMAL_COLOR, ConfigOptions.DEFAULT_ALLOW_HEXADECIMAL_COLOR, "§7Whether players can use hexadecimal color.", @@ -227,7 +272,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { "§7Player may need permission to use color code if §ePermission Needed For Color§7 is enabled."); // Permission needed for color - this.permissionNeededForColor = BoolSettingsGui.boolFactory("§8Need Permission To Use Color ?", this, + this.permissionNeededForColor = new BoolSettingsGui.BoolSettingFactory("§8Need Permission To Use Color ?", this, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.PERMISSION_NEEDED_FOR_COLOR, ConfigOptions.DEFAULT_PERMISSION_NEEDED_FOR_COLOR, "§7Whether players should have permission to be able to use colors.", @@ -248,7 +293,7 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { // Cost of using color range = ConfigOptions.USE_OF_COLOR_COST_RANGE; - this.useOfColorCost = IntSettingsGui.intFactory("§8Cost Of Using Color", this, + this.useOfColorCost = new IntSettingsGui.IntSettingFactory("§8Cost Of Using Color", this, ConfigOptions.USE_OF_COLOR_COST, ConfigHolder.DEFAULT_CONFIG, Arrays.asList( "§7XP level cost when using color code or hexadecimal color using the anvil.", @@ -331,6 +376,10 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { GuiItem illegalCostItem = this.sacrificeIllegalEnchantCost.getItem(Material.ENCHANTED_BOOK); pane.bindItem('S', illegalCostItem); + // work penalty type + GuiItem workPenaltyType = this.workPenaltyType.getItem(Material.DAMAGED_ANVIL, "§aWork Penalty Type"); + pane.bindItem('W', workPenaltyType); + // allow color code GuiItem allowColorCodeItem = this.allowColorCode.getItem(); pane.bindItem('c', allowColorCodeItem); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java index f06d364..0aaf0ee 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java @@ -40,7 +40,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui displayLore, - int scale, boolean asPercentage, boolean nullOnZero, - double min, double max, double defaultVal, double... steps) { - return new DoubleSettingFactory( - title, parent, - config, - configPath, - displayLore, - scale, asPercentage, nullOnZero, - min, max, defaultVal, steps); - } - /** * A factory for a double setting gui that hold setting's information. */ @@ -427,7 +391,7 @@ public class DoubleSettingGui extends AbstractSettingGui { * it is visually preferable to have an odd number of step. * If step only contain 1 value, no step item should be displayed. */ - protected DoubleSettingFactory( + public DoubleSettingFactory( @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull ConfigHolder config, @NotNull String configPath, diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnumSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnumSettingGui.java new file mode 100644 index 0000000..5bf4c24 --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnumSettingGui.java @@ -0,0 +1,242 @@ +package xyz.alexcrea.cuanvil.gui.config.settings; + +import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; +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.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; +import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; +import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; + +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +public class EnumSettingGui & EnumSettingGui.ConfigurableEnum> extends AbstractSettingGui { + + private final EnumSettingFactory holder; + private final T before; + private T now; + + /** + * Create an item setting config gui. + * + * @param holder Configuration factory of this setting. + * @param now The defined value of this setting. + */ + protected EnumSettingGui(EnumSettingFactory holder, T now) { + super(3, holder.getTitle(), holder.parent); + this.holder = holder; + this.before = now; + this.now = now; + + prepareStaticItems(); + updateValueDisplay(); + } + + @Override + public Pattern getGuiPattern() { + return new Pattern( + GuiSharedConstant.EMPTY_GUI_FULL_LINE, + "D000v0000", + "B0000000S" + ); + } + + + public void prepareStaticItems(){ + prepareReturnToDefault(); + } + + + protected GuiItem returnToDefault; + + /** + * Prepare "return to default value" gui item. + */ + protected void prepareReturnToDefault() { + ItemStack item = new ItemStack(Material.COMMAND_BLOCK); + ItemMeta meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§eReset to default value"); + meta.setLore(Collections.singletonList("§7Default value is §e" + holder.getDefault().configurationGuiName())); + item.setItemMeta(meta); + returnToDefault = new GuiItem(item, event -> { + event.setCancelled(true); + now = holder.getDefault(); + updateValueDisplay(); + update(); + }, CustomAnvil.instance); + } + + /** + * Update item using the setting value to match the new value + */ + protected void updateValueDisplay() { + PatternPane pane = getPane(); + + // Get displayed value for this config. + ItemStack displayedItem = now.configurationGuiItem(); + + GuiItem resultItem = new GuiItem(displayedItem, selectNext(), CustomAnvil.instance); + pane.bindItem('v', resultItem); + + // reset to default + GuiItem returnToDefault; + if (now != holder.getDefault()) { + returnToDefault = this.returnToDefault; + } else { + returnToDefault = GuiGlobalItems.backgroundItem(); + } + pane.bindItem('D', returnToDefault); + + } + + /** + * @return A consumer to update the current setting's value. + */ + protected Consumer selectNext() { + return event -> { + event.setCancelled(true); + + this.now = this.holder.next(this.now); + + updateValueDisplay(); + update(); + }; + + } + + @Override + public boolean onSave() { + holder.config.getConfig().set(holder.configPath, this.now.configName()); + + if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) { + return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE); + } + return true; + } + + @Override + public boolean hadChange() { + return !now.equals(before); + } + + + /** + * A factory for an enum setting gui that hold setting's information. + */ + public abstract static class EnumSettingFactory & ConfigurableEnum> extends SettingGuiFactory { + @NotNull + String title; + @NotNull + ValueUpdatableGui parent; + + /** + * Constructor for an enum settings gui factory + * + * @param title The title of the gui. + * @param parent Parent gui to go back when completed. + * @param configPath Configuration path of this setting. + * @param config Configuration holder of this setting. + */ + protected EnumSettingFactory( + @NotNull String title, @NotNull ValueUpdatableGui parent, + @NotNull String configPath, @NotNull ConfigHolder config) { + super(configPath, config); + this.title = title; + this.parent = parent; + + } + /** + * @return Get setting's gui title. + */ + @NotNull + public String getTitle() { + return title; + } + + /** + * @return The configured value for the associated setting. + */ + @NotNull + public abstract T getConfiguredValue(); + + @NotNull + public abstract List getDisplayLore(T value); + + /** + * @return Next value for a given enum + */ + @NotNull + public T next(@NotNull T now){ + Class clazz = now.getDeclaringClass(); + T[] values = clazz.getEnumConstants(); + + int index = now.ordinal(); + if(index == values.length - 1) + return values[0]; + + return values[index + 1]; + } + + /** + * Get default value value + * @return default value + */ + @NotNull + public abstract T getDefault(); + + @Override + public Gui create() { + // Get value or default + T now = getConfiguredValue(); + + // create new gui + return new EnumSettingGui<>(this, now); + } + + /** + * Create a new enum setting GuiItem. + * This item will create and open an enum setting GUI from the factory. + * + * @param name Name of the display. + * @return A formatted GuiItem that will create and open a GUI for the enum setting. + */ + public GuiItem getItem(@NotNull Material material, @NotNull String name) { + T value = getConfiguredValue(); + + ItemStack item = new ItemStack(material); + ItemMeta meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName(name); + meta.setLore(getDisplayLore(value)); + meta.addItemFlags(ItemFlag.values()); + + item.setItemMeta(meta); + + return GuiGlobalItems.openSettingGuiItem(item, this); + } + } + + public interface ConfigurableEnum { + + String configName(); + + ItemStack configurationGuiItem(); + String configurationGuiName(); + + + } + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java index 8a9059f..af977e9 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java @@ -275,38 +275,11 @@ public class IntSettingsGui extends AbstractSettingGui { return now != before; } - /** - * Create an int setting factory from setting's parameters. - * - * @param title The title of the gui. - * @param parent Parent gui to go back when completed. - * @param configPath Configuration path of this setting. - * @param config Configuration holder of this setting. - * @param displayLore Gui display item lore. - * @param min Minimum value of this setting. - * @param max Maximum value of this setting. - * @param defaultVal Default value if not found on the config. - * @param steps List of step the value can increment/decrement. - * List's size should be between 1 (included) and 5 (included). - * it is visually preferable to have an odd number of step. - * If step only contain 1 value, no step item should be displayed. - * @return A factory for an int setting gui. - */ - public static IntSettingFactory intFactory(@NotNull String title, ValueUpdatableGui parent, - String configPath, ConfigHolder config, - @Nullable List displayLore, - int min, int max, int defaultVal, int... steps) { - return new IntSettingFactory( - title, parent, - configPath, config, - displayLore, - min, max, defaultVal, steps); - } - /** * A factory for an int setting gui that hold setting's information. */ public static class IntSettingFactory extends SettingGuiFactory { + @NotNull String title; @NotNull @@ -335,7 +308,7 @@ public class IntSettingsGui extends AbstractSettingGui { * it is visually preferable to have an odd number of step. * If step only contain 1 value, no step item should be displayed. */ - protected IntSettingFactory( + public IntSettingFactory( @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull String configPath, @NotNull ConfigHolder config, @Nullable List displayLore, diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java index 2fba278..3df2af8 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/ItemSettingGui.java @@ -163,27 +163,6 @@ public class ItemSettingGui extends AbstractSettingGui { return !now.equals(before); } - /** - * Create aa item setting factory from setting's parameters. - * - * @param title The title of the gui. - * @param parent Parent gui to go back when completed. - * @param configPath Configuration path of this setting. - * @param config Configuration holder of this setting. - * @param defaultVal Default value if not found on the config. - * @param displayLore Gui display item lore. - * @return A factory for an item setting gui. - */ - public static ItemSettingGui.ItemSettingFactory itemFactory(@NotNull String title, @NotNull ValueUpdatableGui parent, - @NotNull String configPath, @NotNull ConfigHolder config, - @Nullable ItemStack defaultVal, - String... displayLore) { - return new ItemSettingGui.ItemSettingFactory( - title, parent, - configPath, config, - defaultVal, displayLore); - } - /** * A factory for an item setting gui that hold setting's information. */ @@ -207,7 +186,7 @@ public class ItemSettingGui extends AbstractSettingGui { * @param defaultVal Default value if not found on the config. * @param displayLore Gui display item lore. */ - protected ItemSettingFactory( + public ItemSettingFactory( @NotNull String title, @NotNull ValueUpdatableGui parent, @NotNull String configPath, @NotNull ConfigHolder config, @Nullable ItemStack defaultVal, diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiSharedConstant.java b/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiSharedConstant.java index 08b739a..11f3657 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiSharedConstant.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/util/GuiSharedConstant.java @@ -27,7 +27,7 @@ public class GuiSharedConstant { public static final boolean TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE = true; public static final boolean TEMPORARY_DO_BACKUP_EVERY_SAVE = true; - public static final PatternPane BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE; //TODO CHECK USAGE AND FIX + public static final PatternPane BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE; static { Pattern pattern = new Pattern( diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt index 2694f43..d655c93 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/AnvilXpUtil.kt @@ -86,17 +86,13 @@ object AnvilXpUtil { // Extracted From https://minecraft.fandom.com/wiki/Anvil_mechanics#Enchantment_equation // Calculate work penalty val penaltyType = ConfigOptions.workPenaltyType; - val leftPenalty = - if(!penaltyType.isPenaltyAdditive) 0 - else { - (left.itemMeta as? Repairable)?.repairCost ?: 0 - } + val leftPenalty = (left.itemMeta as? Repairable)?.repairCost ?: 0 + val rightPenalty = - if (right == null || !penaltyType.isPenaltyAdditive) 0 - else { - (right.itemMeta as? Repairable)?.repairCost ?: 0 - } + if (right == null) 0 + else (right.itemMeta as? Repairable)?.repairCost ?: 0 + // Increase penalty on fusing or unit repair if(penaltyType.isPenaltyIncreasing && (right != null || unitRepair)){ @@ -114,6 +110,8 @@ object AnvilXpUtil { "result penalty: ${(result.itemMeta as? Repairable)?.repairCost ?: "none"}" ) + if(!penaltyType.isPenaltyAdditive) return 0 + return leftPenalty + rightPenalty } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 38dff51..09f142c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -72,7 +72,8 @@ permission_needed_for_color: true # Valid values include 0 to 1000. use_of_color_cost: 0 -# Every time an item is used on the anvil. item work penalty is added to the price and increase +# Work penalty increase the price for every anvil use. +# This config allow you to choose the comportment of work penalty. # Vanilla work penalty formula can be represented as 2 * previous_penalty + 1. with start value equal to 0 # See https://minecraft.wiki/w/Anvil_mechanics#Anvil_uses for more detail #