Fixes handling of preset replacement

This commit is contained in:
Kristian Knarvik 2023-01-11 01:32:48 +01:00
parent 488d4c7589
commit 8423eabc57

View File

@ -367,26 +367,20 @@ public class NPCSettings {
/** /**
* Replaces placeholders in the given reforge-able value * Replaces placeholders in the given reforge-able value
* *
* @param value <p>The value specified by a user</p> * @param stringList <p>The value specified by a user</p>
* @return <p>The value with placeholders replaced</p> * @return <p>The value with placeholders replaced</p>
*/ */
private static Object replaceReforgeAblePresets(Object value) { private static List<String> replaceReforgeAblePresets(List<String> stringList) {
if (value instanceof String string) { List<String> newStrings = new ArrayList<>(stringList);
String[] list = string.split(","); for (String item : stringList) {
List<String> replaced = new ArrayList<>(list.length); String replaced = SmithPreset.replacePreset(item);
for (String item : list) { if (!replaced.equals(item)) {
replaced.add(SmithPreset.replacePreset(item)); newStrings.addAll(List.of(replaced.split(",")));
} else {
newStrings.add(item);
} }
return String.join(",", replaced);
} else if (value instanceof String[] stringList) {
List<String> replaced = new ArrayList<>(stringList.length);
for (String item : stringList) {
replaced.add(SmithPreset.replacePreset(item));
}
return replaced.toArray();
} else {
throw new IllegalArgumentException("Unexpected object type encountered!");
} }
return newStrings;
} }
/** /**
@ -444,8 +438,10 @@ public class NPCSettings {
return null; return null;
} }
Set<Material> blacklisted = new HashSet<>(); //Convert any presets with a list of materials
itemList = replaceReforgeAblePresets(itemList);
Set<Material> blacklisted = new HashSet<>();
//Parse every material, and add to reforgeAble items //Parse every material, and add to reforgeAble items
for (String item : itemList) { for (String item : itemList) {
//Ignore ,, //Ignore ,,
@ -453,9 +449,6 @@ public class NPCSettings {
continue; continue;
} }
//Convert any presets with a list of materials
item = (String) replaceReforgeAblePresets(item);
boolean blacklist = false; boolean blacklist = false;
if (item.startsWith("-")) { if (item.startsWith("-")) {
blacklist = true; blacklist = true;