diff --git a/pom.xml b/pom.xml index c4ff511..12ac140 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ net.knarcraft knarlib - 1.2.6 + 1.2.7 compile diff --git a/src/main/java/net/knarcraft/blacksmith/command/blacksmith/BlackSmithConfigTabCompleter.java b/src/main/java/net/knarcraft/blacksmith/command/blacksmith/BlackSmithConfigTabCompleter.java index c8a749a..19087b6 100644 --- a/src/main/java/net/knarcraft/blacksmith/command/blacksmith/BlackSmithConfigTabCompleter.java +++ b/src/main/java/net/knarcraft/blacksmith/command/blacksmith/BlackSmithConfigTabCompleter.java @@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.command.blacksmith; import net.knarcraft.blacksmith.config.SettingValueType; import net.knarcraft.blacksmith.config.blacksmith.BlacksmithSetting; import net.knarcraft.blacksmith.util.InputParsingHelper; +import net.knarcraft.knarlib.util.TabCompletionHelper; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -53,7 +54,7 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { return new ArrayList<>(); } } - return null; + return new ArrayList<>(); } /** @@ -119,6 +120,11 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { */ private List getCompletions(@NotNull BlacksmithSetting blacksmithSetting, @NotNull String commandValue) { + if (blacksmithSetting == BlacksmithSetting.ENCHANTMENT_BLOCK_LIST) { + return TabCompletionHelper.getStringList(getTabCompletions(SettingValueType.ENCHANTMENT), + commandValue, TabCompletionHelper::filterMatchingContains); + } + List returnValues = filterMatchingContains( getTabCompletions(blacksmithSetting.getValueType()), commandValue); if (blacksmithSetting == BlacksmithSetting.BASE_PRICE || diff --git a/src/main/java/net/knarcraft/blacksmith/config/SettingValueType.java b/src/main/java/net/knarcraft/blacksmith/config/SettingValueType.java index 942a3bf..ba08cea 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/SettingValueType.java +++ b/src/main/java/net/knarcraft/blacksmith/config/SettingValueType.java @@ -50,4 +50,9 @@ public enum SettingValueType { */ REFORGE_ABLE_ITEMS, + /** + * A list of enchantments + */ + ENCHANTMENT_LIST, + } diff --git a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java index c1545c1..608a256 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java @@ -64,7 +64,7 @@ public class BlacksmithNPCSettings implements TraitSettings { @Override public void changeValue(@NotNull BlacksmithSetting setting, @Nullable Object newValue) { - if (setting.getValueType() == SettingValueType.STRING_LIST || + if (setting.getValueType() == SettingValueType.ENCHANTMENT_LIST || setting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { //Workaround to make sure it's treated as the correct type currentValues.put(setting, newValue == null ? null : ConfigHelper.asStringList(newValue)); diff --git a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java index 4b5d18e..285585a 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java @@ -90,7 +90,7 @@ public enum BlacksmithSetting implements Setting { /** * The setting for the enchantments a blacksmith cannot apply to items */ - ENCHANTMENT_BLOCK_LIST("enchantmentBlockList", SettingValueType.STRING_LIST, List.of("binding_curse", + ENCHANTMENT_BLOCK_LIST("enchantmentBlockList", SettingValueType.ENCHANTMENT_LIST, List.of("binding_curse", "mending", "vanishing_curse"), "The enchantments a " + "blacksmith is denied from applying to an item. Disable anything you find too op or annoying.", true, false), @@ -277,7 +277,7 @@ public enum BlacksmithSetting implements Setting { this.valueType = valueType; this.childPath = key; if (key.contains(".")) { - String[] pathParts = path.split("\\."); + String[] pathParts = key.split("\\."); this.commandName = pathParts[0]; } else { this.commandName = key; diff --git a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSettings.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSettings.java index 8a53cca..c3cb514 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/GlobalBlacksmithSettings.java @@ -73,7 +73,7 @@ public class GlobalBlacksmithSettings implements Settings { * @param newValue

The new value for the setting

*/ public void changeValue(@NotNull BlacksmithSetting blacksmithSetting, @Nullable Object newValue) { - if (blacksmithSetting.getValueType() == SettingValueType.STRING_LIST || + if (blacksmithSetting.getValueType() == SettingValueType.ENCHANTMENT_LIST || blacksmithSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { //Workaround to make sure it's treated as the correct type this.settings.put(blacksmithSetting, newValue == null ? null : ConfigHelper.asStringList(newValue)); diff --git a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java index 8abbef6..1d5b035 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java @@ -181,7 +181,7 @@ public enum ScrapperSetting implements Setting { * Which items are ignored when calculating salvage for a given material */ IGNORED_SALVAGE("ignoredSalvage", SettingValueType.STRING_LIST, - new ArrayList<>(List.of("*_SHOVEL,*_PICKAXE,*_AXE,*_HOE,*_SWORD:STICK")), + new ArrayList<>(List.of("*_SHOVEL;*_PICKAXE;*_AXE;*_HOE;*_SWORD:STICK")), "Items ignored during salvage calculation. This follows the format: " + "\"MATERIAL[,MATERIAL2][,MATERIAL3]:IGNORED\", so the material or materials listed will ignore " + "the material specified after the \":\" when calculating salvage (* matches any character). This " + @@ -223,7 +223,7 @@ public enum ScrapperSetting implements Setting { this.valueType = valueType; this.childPath = key; if (key.contains(".")) { - String[] pathParts = path.split("\\."); + String[] pathParts = key.split("\\."); this.commandName = pathParts[0]; } else { this.commandName = key; diff --git a/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java b/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java index aa1b5e8..066abe9 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/TabCompleteValuesHelper.java @@ -36,25 +36,11 @@ public final class TabCompleteValuesHelper { case PERCENTAGE -> getPercentages(); case REFORGE_ABLE_ITEMS -> getReforgeAbleMaterials(); case MATERIAL -> getAllReforgeAbleMaterialNames(); - case ENCHANTMENT -> getAllEnchantments(); - case STRING_LIST -> getExampleEnchantmentBlockLists(); + case ENCHANTMENT, ENCHANTMENT_LIST -> getAllEnchantments(); + case STRING_LIST -> List.of("*_SHOVEL,*_PICKAXE,*_AXE,*_HOE,*_SWORD:STICK,SMITHING_TABLE:*_PLANKS"); }; } - /** - * Gets example enchantment block lists - * - * @return

Some example enchantment block lists

- */ - private static @NotNull List getExampleEnchantmentBlockLists() { - List exampleBlockLists = new ArrayList<>(); - exampleBlockLists.add(Enchantment.VANISHING_CURSE.getKey().getKey() + "," + - Enchantment.BINDING_CURSE.getKey().getKey() + "," + Enchantment.MENDING.getKey().getKey()); - exampleBlockLists.add(Enchantment.VANISHING_CURSE.getKey().getKey() + "," + - Enchantment.BINDING_CURSE.getKey().getKey()); - return exampleBlockLists; - } - /** * Gets a complete list of all reforge-able material names diff --git a/src/main/java/net/knarcraft/blacksmith/util/TypeValidationHelper.java b/src/main/java/net/knarcraft/blacksmith/util/TypeValidationHelper.java index 239caeb..144c44d 100644 --- a/src/main/java/net/knarcraft/blacksmith/util/TypeValidationHelper.java +++ b/src/main/java/net/knarcraft/blacksmith/util/TypeValidationHelper.java @@ -37,9 +37,10 @@ public final class TypeValidationHelper { case POSITIVE_INTEGER -> isPositiveInteger(value, sender); case PERCENTAGE -> isPercentage(value, sender); case BOOLEAN -> true; - case STRING_LIST, REFORGE_ABLE_ITEMS -> isStringList(value, sender); + case REFORGE_ABLE_ITEMS, STRING_LIST -> isStringList(value, sender); case MATERIAL -> isMaterial(value, sender); case ENCHANTMENT -> isEnchantment(value, sender); + case ENCHANTMENT_LIST -> isEnchantmentList(value, sender); }; } catch (ClassCastException exception) { //This error signifies that an object is not a string, and of the wrong class @@ -64,6 +65,34 @@ public final class TypeValidationHelper { return isMaterial; } + /** + * Checks whether the given value is a list of enchantments + * + * @param value

The value to check

+ * @param sender

The command sender to use for printing error messages

+ * @return

True if the value is an enchantment list

+ */ + private static boolean isEnchantmentList(@Nullable Object value, @Nullable CommandSender sender) { + // Check whether a string list is given + if (!isStringList(value, sender)) { + return false; + } + + // Make sure the input can be converted to a string list + List strings = ConfigHelper.asStringList(value); + if (strings == null) { + return false; + } + + // Make sure each value is an enchantment + for (String string : strings) { + if (!isEnchantment(string, sender)) { + return false; + } + } + return true; + } + /** * Checks whether the given value is an enchantment *