Fixes some bugs
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
Fixes some config commands not being registered Bumps KnarLib version to include bug-fix Fixes and improves tab-completion for enchantment block-list
This commit is contained in:
parent
7e5525bd00
commit
f9463f58d1
2
pom.xml
2
pom.xml
@ -83,7 +83,7 @@
|
||||
<dependency>
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>knarlib</artifactId>
|
||||
<version>1.2.6</version>
|
||||
<version>1.2.7</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -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<String> getCompletions(@NotNull BlacksmithSetting blacksmithSetting,
|
||||
@NotNull String commandValue) {
|
||||
if (blacksmithSetting == BlacksmithSetting.ENCHANTMENT_BLOCK_LIST) {
|
||||
return TabCompletionHelper.getStringList(getTabCompletions(SettingValueType.ENCHANTMENT),
|
||||
commandValue, TabCompletionHelper::filterMatchingContains);
|
||||
}
|
||||
|
||||
List<String> returnValues = filterMatchingContains(
|
||||
getTabCompletions(blacksmithSetting.getValueType()), commandValue);
|
||||
if (blacksmithSetting == BlacksmithSetting.BASE_PRICE ||
|
||||
|
@ -50,4 +50,9 @@ public enum SettingValueType {
|
||||
*/
|
||||
REFORGE_ABLE_ITEMS,
|
||||
|
||||
/**
|
||||
* A list of enchantments
|
||||
*/
|
||||
ENCHANTMENT_LIST,
|
||||
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
|
||||
|
||||
@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));
|
||||
|
@ -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;
|
||||
|
@ -73,7 +73,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
|
||||
* @param newValue <p>The new value for the setting</p>
|
||||
*/
|
||||
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));
|
||||
|
@ -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;
|
||||
|
@ -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 <p>Some example enchantment block lists</p>
|
||||
*/
|
||||
private static @NotNull List<String> getExampleEnchantmentBlockLists() {
|
||||
List<String> 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
|
||||
|
@ -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 <p>The value to check</p>
|
||||
* @param sender <p>The command sender to use for printing error messages</p>
|
||||
* @return <p>True if the value is an enchantment list</p>
|
||||
*/
|
||||
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<String> 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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user