Changes ignored salvage into trash salvage according to #22

This commit is contained in:
2024-05-05 18:02:12 +02:00
parent c71d664a79
commit 21d55563b7
6 changed files with 77 additions and 67 deletions

View File

@ -25,7 +25,7 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
private final Map<ScrapperSetting, Object> settings = new HashMap<>();
private final List<Material> defaultSalvageableMaterials = new ArrayList<>();
private final Map<Material, Set<Material>> ignoredSalvage = new HashMap<>();
private final Map<Material, Set<Material>> trashSalvage = new HashMap<>();
private final BlacksmithPlugin instance;
@ -144,7 +144,7 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
}
}
loadSalvageAbleItems();
loadIgnoredSalvage();
loadTrashSalvage();
}
/**
@ -182,17 +182,17 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
}
/**
* Gets ignored salvage for the given material
* Gets trash salvage for the given material
*
* <p>The ignored salvage should be ignored when calculating item salvage, in order to increase the probability of
* <p>The trash salvage should be deferred when calculating item salvage, in order to increase the probability of
* getting the more expensive materials back.</p>
*
* @param material <p>The material to get ignored salvage for</p>
* @return <p>The ignored salvage</p>
* @param material <p>The material to get trash salvage for</p>
* @return <p>The trash salvage</p>
*/
@Nullable
public Set<Material> getIgnoredSalvage(@NotNull Material material) {
return this.ignoredSalvage.get(material);
public Set<Material> getTrashSalvage(@NotNull Material material) {
return this.trashSalvage.get(material);
}
/**
@ -207,40 +207,40 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
}
/**
* Loads all ignored salvage from the configuration file
* Loads all trash salvage from the configuration file
*/
private void loadIgnoredSalvage() {
this.ignoredSalvage.clear();
List<String> allIgnoredSalvage = ConfigHelper.asStringList(this.settings.get(ScrapperSetting.IGNORED_SALVAGE));
if (allIgnoredSalvage == null) {
private void loadTrashSalvage() {
this.trashSalvage.clear();
List<String> allTrashSalvage = ConfigHelper.asStringList(this.settings.get(ScrapperSetting.IGNORED_SALVAGE));
if (allTrashSalvage == null) {
return;
}
for (String ignoredSalvageInfo : allIgnoredSalvage) {
for (String trashSalvageInfo : allTrashSalvage) {
// Ignore invalid lines
if (!ignoredSalvageInfo.contains(":")) {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, String.format("The ignored salvage " +
"configuration line %s is invalid", ignoredSalvageInfo));
if (!trashSalvageInfo.contains(":")) {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, String.format("The trash salvage " +
"configuration line %s is invalid", trashSalvageInfo));
continue;
}
// Parse all material names
String[] data = ignoredSalvageInfo.split(":");
String[] data = trashSalvageInfo.split(":");
String[] materialStrings = data[0].split(";");
List<Material> materials = new ArrayList<>();
for (String materialString : materialStrings) {
materials.addAll(ItemHelper.getWildcardMatch(materialString, true));
}
String[] ignoredSalvageStrings = data[1].split(";");
String[] trashSalvageStrings = data[1].split(";");
List<Material> ignored = new ArrayList<>();
for (String ignoredSalvageString : ignoredSalvageStrings) {
ignored.addAll(ItemHelper.getWildcardMatch(ignoredSalvageString, true));
for (String trashSalvageString : trashSalvageStrings) {
ignored.addAll(ItemHelper.getWildcardMatch(trashSalvageString, true));
}
// Add the ignored salvage to all the matched materials
// Add the trash salvage to all the matched materials
for (Material material : materials) {
ignoredSalvage.computeIfAbsent(material, k -> new HashSet<>());
ignoredSalvage.get(material).addAll(ignored);
trashSalvage.computeIfAbsent(material, k -> new HashSet<>());
trashSalvage.get(material).addAll(ignored);
}
}
}

View File

@ -194,13 +194,13 @@ 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")),
"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 " +
"causes the player to lose some items during salvaging, but can prevent cases where a diamond " +
"pickaxe is salvaged and only sticks are returned.", false, false),
IGNORED_SALVAGE("trashSalvage", SettingValueType.STRING_LIST,
new ArrayList<>(List.of("*_SHOVEL;*_PICKAXE;*_AXE;*_HOE;*_SWORD;SHIELD;*_BOW:STICK")),
"Items treated as trash during salvage calculation. This follows the format: " +
"\"MATERIAL[;MATERIAL2][;MATERIAL3]:TRASH_MATERIAL[;TRASH_MATERIAL2]\", so the material or " +
"materials listed will treat the material specified after the \":\" as trash when calculating " +
"salvage unless all non-trash items can be given as well(* matches any character).",
false, false),
;
private final String path;