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 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.
**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.**
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"

View File

@ -410,14 +410,17 @@ public class NPCSettings {
//Parse every material, and add to reforgeAble items
for (String item : newReforgeAbleItems.split(",")) {
//Ignore ,,
if (InputParsingHelper.isEmpty(item)) {
continue;
}
boolean blacklist = false;
if (item.startsWith("-")) {
blacklist = true;
item = item.substring(1);
}
Material material = InputParsingHelper.matchMaterial(item);
if (material != null && BlacksmithTrait.isRepairable(new ItemStack(material, 1))) {
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
for (Material material : blacklisted) {
reforgeAbleItems.remove(material);
}
this.reforgeAbleItems.removeAll(blacklisted);
}
}

View File

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