Fixes a bug caused by "-" being consumed
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2023-01-09 15:13:55 +01:00
parent 7d940ee334
commit a5ae3cb295
3 changed files with 16 additions and 10 deletions

View File

@ -71,8 +71,8 @@ the default one instead.
### Presets and filters: ### Presets and filters:
Presets are a nice way to make specialized blacksmiths by specifying categories of materials, instead of manually **Presets are a nice way to make specialized blacksmiths by specifying categories of materials, instead of manually
listing every material manually. They can only be used for the `reforgeAbleItems` option. listing every material manually. They can only be used for the `reforgeAbleItems` option.**
Note: All of these can be used when specifying reforge-able items, such as Note: All of these can be used when specifying reforge-able items, such as
"preset:weapon-smith:bow,preset:armor_smith:gold,PRESET:TOOL_SMITH,shield" "preset:weapon-smith:bow,preset:armor_smith:gold,PRESET:TOOL_SMITH,shield"

View File

@ -410,14 +410,17 @@ public class NPCSettings {
//Parse every material, and add to reforgeAble items //Parse every material, and add to reforgeAble items
for (String item : newReforgeAbleItems.split(",")) { for (String item : newReforgeAbleItems.split(",")) {
//Ignore ,,
if (InputParsingHelper.isEmpty(item)) { if (InputParsingHelper.isEmpty(item)) {
continue; continue;
} }
boolean blacklist = false; boolean blacklist = false;
if (item.startsWith("-")) { if (item.startsWith("-")) {
blacklist = true; blacklist = true;
item = item.substring(1); item = item.substring(1);
} }
Material material = InputParsingHelper.matchMaterial(item); Material material = InputParsingHelper.matchMaterial(item);
if (material != null && BlacksmithTrait.isRepairable(new ItemStack(material, 1))) { if (material != null && BlacksmithTrait.isRepairable(new ItemStack(material, 1))) {
if (!blacklist) { if (!blacklist) {
@ -432,9 +435,7 @@ public class NPCSettings {
} }
//Remove any blacklisted materials at the end to make sure order of arguments won't matter //Remove any blacklisted materials at the end to make sure order of arguments won't matter
for (Material material : blacklisted) { this.reforgeAbleItems.removeAll(blacklisted);
reforgeAbleItems.remove(material);
}
} }
} }

View File

@ -88,16 +88,21 @@ public enum SmithPreset {
*/ */
public static String replacePreset(String possiblePreset) { public static String replacePreset(String possiblePreset) {
boolean negated = false; boolean negated = false;
if (possiblePreset.startsWith("-")) {
negated = true;
possiblePreset = possiblePreset.substring(1);
}
String upperCasedPreset = possiblePreset.replace('-', '_').toUpperCase(); String upperCasedPreset = possiblePreset.replace('-', '_').toUpperCase();
if (!upperCasedPreset.startsWith("PRESET:")) { if (possiblePreset.startsWith("-")) {
negated = true;
}
if ((negated && !upperCasedPreset.startsWith("_PRESET:")) && !upperCasedPreset.startsWith("PRESET:")) {
return possiblePreset; return possiblePreset;
} }
//Strip the "-" here to prevent stripping for material names
if (negated) {
upperCasedPreset = upperCasedPreset.substring(1);
}
//Parse the input //Parse the input
SmithPresetFilter filter = null; SmithPresetFilter filter = null;
SmithPreset preset; SmithPreset preset;