mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Add work type option for config gui.
Removed some useless function for setting guis. fix work penalty increase_only not working.
This commit is contained in:
parent
519ab1853c
commit
ce01702cea
16 changed files with 400 additions and 151 deletions
|
|
@ -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<String> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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> 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<String> 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);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
|||
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
||||
|
||||
return IntSettingsGui.intFactory(prettyKey + " Level Limit", this,
|
||||
return new IntSettingsGui.IntSettingFactory(prettyKey + " Level Limit", this,
|
||||
SECTION_NAME + '.' + key, ConfigHolder.DEFAULT_CONFIG,
|
||||
Collections.singletonList(
|
||||
"§7Maximum applied level of " + prettyKey
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
|||
protected DoubleSettingGui.DoubleSettingFactory createFactory(String materialName) {
|
||||
String materialDisplayName = CasedStringUtil.snakeToUpperSpacedCase(materialName);
|
||||
|
||||
return DoubleSettingGui.doubleFactory(
|
||||
return new DoubleSettingGui.DoubleSettingFactory(
|
||||
"§0%§8" + materialDisplayName +" Repair",
|
||||
this,
|
||||
ConfigHolder.UNIT_REPAIR_HOLDER,
|
||||
|
|
|
|||
|
|
@ -77,32 +77,32 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
|
|||
// Displayed item will be updated later
|
||||
|
||||
IntRange costRange = AnvilCustomRecipe.Companion.getXP_COST_CONFIG_RANGE();
|
||||
this.exactCountFactory = BoolSettingsGui.boolFactory("§8Exact count ?", this,
|
||||
this.exactCountFactory = new BoolSettingsGui.BoolSettingFactory("§8Exact count ?", this,
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
this.anvilRecipe + "." + AnvilCustomRecipe.EXACT_COUNT_CONFIG, AnvilCustomRecipe.DEFAULT_EXACT_COUNT_CONFIG);
|
||||
|
||||
this.xpCostFactory = IntSettingsGui.intFactory("§8Recipe Xp Cost", this,
|
||||
this.xpCostFactory = new IntSettingsGui.IntSettingFactory("§8Recipe Xp Cost", this,
|
||||
this.anvilRecipe +"."+AnvilCustomRecipe.XP_COST_CONFIG,
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
null,
|
||||
costRange.getFirst(), costRange.getLast(), AnvilCustomRecipe.DEFAULT_XP_COST_CONFIG, 1, 5, 10);
|
||||
|
||||
|
||||
this.leftItemFactory = ItemSettingGui.itemFactory("§eRecipe Left §8Item", this,
|
||||
this.leftItemFactory = new ItemSettingGui.ItemSettingFactory("§eRecipe Left §8Item", this,
|
||||
this.anvilRecipe + "." + AnvilCustomRecipe.LEFT_ITEM_CONFIG,
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
AnvilCustomRecipe.Companion.getDEFAULT_LEFT_ITEM_CONFIG(),
|
||||
"§7Set the left item of the custom craft",
|
||||
"§7\u25A0 + \u25A1 = \u25A1");
|
||||
|
||||
this.rightItemFactory = ItemSettingGui.itemFactory("§eRecipe Right §8Item", this,
|
||||
this.rightItemFactory = new ItemSettingGui.ItemSettingFactory("§eRecipe Right §8Item", this,
|
||||
this.anvilRecipe + "." + AnvilCustomRecipe.RIGHT_ITEM_CONFIG,
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
AnvilCustomRecipe.Companion.getDEFAULT_RIGHT_ITEM_CONFIG(),
|
||||
"§7Set the right item of the custom craft",
|
||||
"§7\u25A1 + \u25A0 = \u25A1");
|
||||
|
||||
this.resultItemFactory = ItemSettingGui.itemFactory("§aRecipe Result §8Item", this,
|
||||
this.resultItemFactory = new ItemSettingGui.ItemSettingFactory("§aRecipe Result §8Item", this,
|
||||
this.anvilRecipe + "." + AnvilCustomRecipe.RESULT_ITEM_CONFIG,
|
||||
ConfigHolder.CUSTOM_RECIPE_HOLDER,
|
||||
AnvilCustomRecipe.Companion.getDEFAULT_RESULT_ITEM_CONFIG(),
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
|||
enchantGui.show(event.getWhoClicked());
|
||||
}, CustomAnvil.instance);
|
||||
|
||||
this.minBeforeActiveSettingFactory = IntSettingsGui.intFactory(
|
||||
this.minBeforeActiveSettingFactory = new IntSettingsGui.IntSettingFactory(
|
||||
"§8Minimum enchantment count",
|
||||
this, this.enchantConflict + ".maxEnchantmentBeforeConflict", ConfigHolder.CONFLICT_HOLDER,
|
||||
Arrays.asList(
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
|||
*/
|
||||
public abstract class AbstractSettingGui extends ChestGui implements SettingGui {
|
||||
|
||||
protected static final String CLICK_LORE = "§7Click Here to change the value";
|
||||
public static final String CLICK_LORE = "§7Click Here to change the value";
|
||||
|
||||
private PatternPane pane;
|
||||
|
||||
|
|
|
|||
|
|
@ -161,28 +161,6 @@ public class BoolSettingsGui extends AbstractSettingGui {
|
|||
return now != before;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a bool setting factory from setting's parameters.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param defaultVal Default value if not found on the config.
|
||||
* @param displayLore Gui display item lore.
|
||||
* @return A factory for a boolean setting gui.
|
||||
*/
|
||||
public static BoolSettingFactory boolFactory(@NotNull String title, @NotNull ValueUpdatableGui parent,
|
||||
@NotNull ConfigHolder config,
|
||||
@NotNull String configPath, boolean defaultVal,
|
||||
String... displayLore) {
|
||||
return new BoolSettingFactory(
|
||||
title, parent,
|
||||
config,
|
||||
configPath, defaultVal,
|
||||
displayLore);
|
||||
}
|
||||
|
||||
/**
|
||||
* A factory for a boolean setting gui that hold setting's information.
|
||||
*/
|
||||
|
|
@ -206,7 +184,7 @@ public class BoolSettingsGui extends AbstractSettingGui {
|
|||
* @param defaultVal Default value if not found on the config.
|
||||
* @param displayLore Gui display item lore.
|
||||
*/
|
||||
protected BoolSettingFactory(
|
||||
public BoolSettingFactory(
|
||||
@NotNull String title, @NotNull ValueUpdatableGui parent,
|
||||
@NotNull ConfigHolder config, @NotNull String configPath,
|
||||
boolean defaultVal, String... displayLore) {
|
||||
|
|
|
|||
|
|
@ -352,42 +352,6 @@ public class DoubleSettingGui extends AbstractSettingGui {
|
|||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a double setting factory from setting's parameters.
|
||||
*
|
||||
* @param title The title of the gui.
|
||||
* @param parent Parent gui to go back when completed.
|
||||
* @param config Configuration holder of this setting.
|
||||
* @param configPath Configuration path of this setting.
|
||||
* @param displayLore Gui display item lore.
|
||||
* @param scale The scale of the decimal.
|
||||
* @param asPercentage If we should display the value as a %.
|
||||
* @param nullOnZero Set the value as null (deleting it) when equal to 0
|
||||
* @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 a double setting gui.
|
||||
*/
|
||||
@NotNull
|
||||
public static DoubleSettingFactory doubleFactory(@NotNull String title, @NotNull ValueUpdatableGui parent,
|
||||
@NotNull ConfigHolder config,
|
||||
@NotNull String configPath,
|
||||
@Nullable List<String> 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,
|
||||
|
|
|
|||
|
|
@ -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<T extends Enum<T> & EnumSettingGui.ConfigurableEnum> extends AbstractSettingGui {
|
||||
|
||||
private final EnumSettingFactory<T> 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<T> 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<InventoryClickEvent> 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<T extends Enum<T> & 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<String> getDisplayLore(T value);
|
||||
|
||||
/**
|
||||
* @return Next value for a given enum
|
||||
*/
|
||||
@NotNull
|
||||
public T next(@NotNull T now){
|
||||
Class<T> 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();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<String> 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<String> displayLore,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
#
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue