Finishes the scrapper implementation
Some checks failed
EpicKnarvik97/Blacksmith/pipeline/head There was a failure building this commit

This commit is contained in:
2024-05-04 01:01:56 +02:00
parent 455db78988
commit 4012e532da
30 changed files with 501 additions and 216 deletions

View File

@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull;
/**
* An interface describing a setting
*/
@SuppressWarnings("unused")
public interface Setting {
/**
@ -12,42 +13,48 @@ public interface Setting {
*
* @return <p>The full config path for this setting</p>
*/
@NotNull String getPath();
@NotNull
String getPath();
/**
* Gets the config path without the root node
*
* @return <p>The config path without the root node</p>
*/
@NotNull String getChildPath();
@NotNull
String getChildPath();
/**
* Gets the value of this setting
*
* @return <p>The value of this setting</p>
*/
@NotNull Object getDefaultValue();
@NotNull
Object getDefaultValue();
/**
* The name of the command used to change this setting
*
* @return <p>The name of this setting's command</p>
*/
@NotNull String getCommandName();
@NotNull
String getCommandName();
/**
* Gets the value type for this setting
*
* @return <p>The value type for this setting</p>
*/
@NotNull SettingValueType getValueType();
@NotNull
SettingValueType getValueType();
/**
* Gets the description explaining the usage of this setting
*
* @return <p>This setting's description</p>
*/
@NotNull String getDescription();
@NotNull
String getDescription();
/**
* Gets whether this setting can be set per-NPC, or if it's set globally

View File

@ -1,5 +1,8 @@
package net.knarcraft.blacksmith.config;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* An interface describing an object for managing settings
*
@ -13,7 +16,7 @@ public interface Settings<K extends Setting> {
* @param setting <p>The setting to change</p>
* @param newValue <p>The new value of the setting</p>
*/
void changeValue(K setting, Object newValue);
void changeValue(@NotNull K setting, @Nullable Object newValue);
/**
* Gets the current raw value of the given global setting
@ -21,6 +24,6 @@ public interface Settings<K extends Setting> {
* @param setting <p>The setting to get</p>
* @return <p>The current raw setting value</p>
*/
Object getRawValue(K setting);
@NotNull Object getRawValue(@NotNull K setting);
}

View File

@ -4,6 +4,7 @@ import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@ -46,7 +47,7 @@ public enum SmithPreset {
*
* @param filters <p>The filters applicable to this preset</p>
*/
SmithPreset(SmithPresetFilter[] filters) {
SmithPreset(@NotNull SmithPresetFilter[] filters) {
this.filters = filters;
}
@ -56,7 +57,7 @@ public enum SmithPreset {
* @param filter <p>The filter to check</p>
* @return <p>True if the filter is supported</p>
*/
public boolean supportsFilter(SmithPresetFilter filter) {
public boolean supportsFilter(@NotNull SmithPresetFilter filter) {
return List.of(filters).contains(filter);
}
@ -65,6 +66,7 @@ public enum SmithPreset {
*
* @return <p>The filters supported by this preset</p>
*/
@NotNull
public List<SmithPresetFilter> getSupportedFilters() {
return List.of(filters);
}
@ -74,6 +76,7 @@ public enum SmithPreset {
*
* @return <p>All available smith presets</p>
*/
@NotNull
public static List<String> getPresetNames() {
List<String> presetNames = new ArrayList<>();
for (SmithPreset preset : SmithPreset.values()) {
@ -88,7 +91,8 @@ public enum SmithPreset {
* @param possiblePreset <p>The string that might be a preset</p>
* @return <p>The string, possibly with the preset replaced</p>
*/
public static String replacePreset(String possiblePreset) {
@NotNull
public static String replacePreset(@NotNull String possiblePreset) {
boolean negated = false;
String upperCasedPreset = possiblePreset.replace('-', '_').toUpperCase();
@ -143,6 +147,7 @@ public enum SmithPreset {
* @param filter <p>The filter to use for filtering</p>
* @return <p>The materials included in this preset, filtered using the given filter</p>
*/
@NotNull
public List<Material> getFilteredMaterials(SmithPresetFilter filter) {
List<Material> materials = new ArrayList<>(this.getMaterials());
materials.removeIf((item) -> !filter.isIncluded(item));
@ -154,6 +159,7 @@ public enum SmithPreset {
*
* @return <p>All materials in this preset</p>
*/
@NotNull
public List<Material> getMaterials() {
return switch (this) {
case BLACKSMITH -> ItemHelper.getAllReforgeAbleMaterials();
@ -168,6 +174,7 @@ public enum SmithPreset {
*
* @return <p>All ranged weapon materials</p>
*/
@NotNull
private List<Material> getRanged() {
List<Material> ranged = new ArrayList<>();
ranged.add(Material.TRIDENT);
@ -181,6 +188,7 @@ public enum SmithPreset {
*
* @return <p>All tool materials</p>
*/
@NotNull
private List<Material> getTools() {
List<Material> tools = new ArrayList<>();
tools.addAll(Tag.ITEMS_HOES.getValues());
@ -198,6 +206,7 @@ public enum SmithPreset {
*
* @return <p>All weapon materials</p>
*/
@NotNull
private List<Material> getWeapons() {
List<Material> weapons = new ArrayList<>(getSwords());
weapons.addAll(getRanged());
@ -210,10 +219,17 @@ public enum SmithPreset {
*
* @return <p>All sword materials</p>
*/
@NotNull
private Set<Material> getSwords() {
return Tag.ITEMS_SWORDS.getValues();
}
/**
* Gets all types of armor
*
* @return <p>All armor types</p>
*/
@NotNull
private List<Material> getArmor() {
List<Material> armor = new ArrayList<>();
armor.addAll(getMaterialsEndingWith("HELMET"));
@ -230,7 +246,8 @@ public enum SmithPreset {
* @param end <p>The string to look for</p>
* @return <p>The resulting materials</p>
*/
private List<Material> getMaterialsEndingWith(String end) {
@NotNull
private List<Material> getMaterialsEndingWith(@NotNull String end) {
List<Material> matchedMaterials = new ArrayList<>();
for (Material material : ItemHelper.getAllReforgeAbleMaterials()) {
if (!material.name().startsWith("LEGACY") && material.name().endsWith(end)) {
@ -245,6 +262,7 @@ public enum SmithPreset {
*
* @return <p>All material names for this smith</p>
*/
@NotNull
private List<String> getMaterialNames() {
return getNames(this.getMaterials());
}
@ -255,7 +273,8 @@ public enum SmithPreset {
* @param filter <p>The filter used for filtering materials</p>
* @return <p>All material names for this smith</p>
*/
private List<String> getMaterialNames(SmithPresetFilter filter) {
@NotNull
private List<String> getMaterialNames(@NotNull SmithPresetFilter filter) {
return getNames(this.getFilteredMaterials(filter));
}
@ -265,7 +284,8 @@ public enum SmithPreset {
* @param materials <p>The materials to get the names of</p>
* @return <p>The names of the materials</p>
*/
private List<String> getNames(List<Material> materials) {
@NotNull
private List<String> getNames(@NotNull List<Material> materials) {
List<String> items = new ArrayList<>();
for (Material material : materials) {
items.add(material.name().toLowerCase().replace("_", "-"));
@ -279,7 +299,8 @@ public enum SmithPreset {
* @param materials <p>The material names to negate</p>
* @return <p>The negated material names</p>
*/
private static List<String> negateMaterials(List<String> materials) {
@NotNull
private static List<String> negateMaterials(@NotNull List<String> materials) {
List<String> negatedMaterials = new ArrayList<>(materials.size());
materials.forEach((material) -> {
if (material != null && !material.isBlank()) {

View File

@ -9,6 +9,8 @@ import net.knarcraft.blacksmith.util.InputParsingHelper;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
@ -22,7 +24,7 @@ import java.util.logging.Level;
public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
private final List<Material> reforgeAbleItems = new ArrayList<>();
private final List<Enchantment> enchantmentBlocklist = new ArrayList<>();
private final List<Enchantment> enchantmentBlockList = new ArrayList<>();
private final Map<BlacksmithSetting, Object> currentValues = new HashMap<>();
private final GlobalBlacksmithSettings globalBlacksmithSettings;
@ -46,7 +48,7 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
}
//Updates the list of reforge-able items/materials
updateReforgeAbleItems();
updateEnchantmentBlocklist();
updateEnchantmentBlockList();
}
/**
@ -61,7 +63,7 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
}
@Override
public void changeValue(BlacksmithSetting setting, Object newValue) {
public void changeValue(@NotNull BlacksmithSetting setting, @Nullable Object newValue) {
if (setting.getValueType() == SettingValueType.STRING_LIST ||
setting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
//Workaround to make sure it's treated as the correct type
@ -72,8 +74,8 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
if (setting == BlacksmithSetting.REFORGE_ABLE_ITEMS) {
updateReforgeAbleItems();
}
if (setting == BlacksmithSetting.ENCHANTMENT_BLOCKLIST) {
updateEnchantmentBlocklist();
if (setting == BlacksmithSetting.ENCHANTMENT_BLOCK_LIST) {
updateEnchantmentBlockList();
}
}
@ -83,7 +85,7 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
* @param setting <p>The setting to get the value of</p>
* @return <p>The current value of the setting</p>
*/
public Object getRawValue(BlacksmithSetting setting) {
public @NotNull Object getRawValue(@NotNull BlacksmithSetting setting) {
return currentValues.get(setting);
}
@ -195,12 +197,12 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
*
* @return <p>The list of blocked enchantments</p>
*/
public List<Enchantment> getEnchantmentBlocklist() {
Object currentValue = currentValues.get(BlacksmithSetting.ENCHANTMENT_BLOCKLIST);
public List<Enchantment> getEnchantmentBlockList() {
Object currentValue = currentValues.get(BlacksmithSetting.ENCHANTMENT_BLOCK_LIST);
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
return globalBlacksmithSettings.getEnchantmentBlocklist();
return globalBlacksmithSettings.getEnchantmentBlockList();
} else {
return new ArrayList<>(this.enchantmentBlocklist);
return new ArrayList<>(this.enchantmentBlockList);
}
}
@ -356,11 +358,11 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
/**
* Updates the list of blocked enchantments
*/
private void updateEnchantmentBlocklist() {
this.enchantmentBlocklist.clear();
List<String> enchantments = ConfigHelper.asStringList(getValue(BlacksmithSetting.ENCHANTMENT_BLOCKLIST));
private void updateEnchantmentBlockList() {
this.enchantmentBlockList.clear();
List<String> enchantments = ConfigHelper.asStringList(getValue(BlacksmithSetting.ENCHANTMENT_BLOCK_LIST));
if (enchantments != null) {
this.enchantmentBlocklist.addAll(getEnchantmentBlocklist(enchantments));
this.enchantmentBlockList.addAll(getEnchantmentBlockList(enchantments));
}
}
@ -370,8 +372,8 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
* @param enchantments <p>The enchantment names to block</p>
* @return <p>The enchantments to be blocked</p>
*/
public static List<Enchantment> getEnchantmentBlocklist(List<String> enchantments) {
List<Enchantment> enchantmentBlocklist = new ArrayList<>();
public static List<Enchantment> getEnchantmentBlockList(List<String> enchantments) {
List<Enchantment> enchantmentBlockList = new ArrayList<>();
for (String item : enchantments) {
if (InputParsingHelper.isEmpty(item)) {
@ -380,13 +382,13 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> {
Enchantment enchantment = InputParsingHelper.matchEnchantment(item);
if (enchantment != null) {
enchantmentBlocklist.add(enchantment);
enchantmentBlockList.add(enchantment);
} else {
BlacksmithPlugin.getInstance().getLogger().log(Level.WARNING, "Unable to verify " + item +
" as a valid enchantment");
}
}
return enchantmentBlocklist;
return enchantmentBlockList;
}
/**

View File

@ -90,7 +90,7 @@ public enum BlacksmithSetting implements Setting {
/**
* The setting for the enchantments a blacksmith cannot apply to items
*/
ENCHANTMENT_BLOCKLIST("enchantmentBlocklist", SettingValueType.STRING_LIST, List.of("binding_curse",
ENCHANTMENT_BLOCK_LIST("enchantmentBlockList", SettingValueType.STRING_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),

View File

@ -11,6 +11,7 @@ import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.ArrayList;
@ -29,7 +30,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
private final Map<Enchantment, Double> enchantmentCosts = new HashMap<>();
private final Map<BlacksmithSetting, Object> settings = new HashMap<>();
private final List<Material> defaultReforgeAbleMaterials = new ArrayList<>();
private final List<Enchantment> defaultEnchantmentBlocklist = new ArrayList<>();
private final List<Enchantment> defaultEnchantmentBlockList = new ArrayList<>();
private final YamlStorage defaultConfig;
@ -71,7 +72,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
* @param blacksmithSetting <p>The default NPC setting to change</p>
* @param newValue <p>The new value for the setting</p>
*/
public void changeValue(BlacksmithSetting blacksmithSetting, Object newValue) {
public void changeValue(@NotNull BlacksmithSetting blacksmithSetting, @Nullable Object newValue) {
if (blacksmithSetting.getValueType() == SettingValueType.STRING_LIST ||
blacksmithSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
//Workaround to make sure it's treated as the correct type
@ -82,8 +83,8 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
save();
if (blacksmithSetting == BlacksmithSetting.REFORGE_ABLE_ITEMS) {
loadReforgeAbleItems();
} else if (blacksmithSetting == BlacksmithSetting.ENCHANTMENT_BLOCKLIST) {
loadEnchantmentBlocklist();
} else if (blacksmithSetting == BlacksmithSetting.ENCHANTMENT_BLOCK_LIST) {
loadEnchantmentBlockList();
}
}
@ -93,7 +94,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
* @param blacksmithSetting <p>The setting to get</p>
* @return <p>The current raw setting value</p>
*/
public Object getRawValue(BlacksmithSetting blacksmithSetting) {
public @NotNull Object getRawValue(@NotNull BlacksmithSetting blacksmithSetting) {
return this.settings.get(blacksmithSetting);
}
@ -248,12 +249,12 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
}
/**
* Gets the value of enchantmentBlocklist
* Gets the value of enchantmentBlockList
*
* @return <p>The value of enchantmentBlocklist</p>
* @return <p>The value of enchantmentBlockList</p>
*/
public @NotNull List<Enchantment> getEnchantmentBlocklist() {
return this.defaultEnchantmentBlocklist;
public @NotNull List<Enchantment> getEnchantmentBlockList() {
return this.defaultEnchantmentBlockList;
}
/**
@ -327,7 +328,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
}
}
loadReforgeAbleItems();
loadEnchantmentBlocklist();
loadEnchantmentBlockList();
//Load all base prices
loadBasePrices(root);
@ -465,14 +466,14 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
}
/**
* Loads the enchantment blocklist from the current value
* Loads the enchantment block list from the current value
*/
private void loadEnchantmentBlocklist() {
this.defaultEnchantmentBlocklist.clear();
private void loadEnchantmentBlockList() {
this.defaultEnchantmentBlockList.clear();
List<String> enchantmentNames = ConfigHelper.asStringList(settings.get(
BlacksmithSetting.ENCHANTMENT_BLOCKLIST));
BlacksmithSetting.ENCHANTMENT_BLOCK_LIST));
if (enchantmentNames != null) {
this.defaultEnchantmentBlocklist.addAll(BlacksmithNPCSettings.getEnchantmentBlocklist(enchantmentNames));
this.defaultEnchantmentBlockList.addAll(BlacksmithNPCSettings.getEnchantmentBlockList(enchantmentNames));
}
}

View File

@ -86,7 +86,7 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
* @param scrapperSetting <p>The setting to get</p>
* @return <p>The current raw setting value</p>
*/
public Object getRawValue(ScrapperSetting scrapperSetting) {
public @NotNull Object getRawValue(@NotNull ScrapperSetting scrapperSetting) {
return this.settings.get(scrapperSetting);
}
@ -104,7 +104,7 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
*
* @return <p>Whether to show exact time</p>
*/
public boolean getShowExactTime() {
public boolean showExactTime() {
return asBoolean(ScrapperSetting.SHOW_EXACT_TIME);
}
@ -173,10 +173,20 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
*
* @return <p>The value of salvageAbleItems</p>
*/
@NotNull
public List<Material> getSalvageAbleItems() {
return this.defaultSalvageableMaterials;
}
/**
* Gets the cost of using a scrapper
*
* @return <p>The cost of using a scrapper</p>
*/
public double getCost() {
return ConfigHelper.asDouble(getValue(ScrapperSetting.USE_COST));
}
/**
* Gets ignored salvage for the given material
*
@ -186,7 +196,8 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
* @param material <p>The material to get ignored salvage for</p>
* @return <p>The ignored salvage</p>
*/
public @Nullable Set<Material> getIgnoredSalvage(@NotNull Material material) {
@Nullable
public Set<Material> getIgnoredSalvage(@NotNull Material material) {
return this.ignoredSalvage.get(material);
}
@ -221,15 +232,15 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
// Parse all material names
String[] data = ignoredSalvageInfo.split(":");
String[] materialStrings = data[0].split(",");
String[] materialStrings = data[0].split(";");
List<Material> materials = new ArrayList<>();
for (String materialString : materialStrings) {
materials.addAll(ItemHelper.getWildcardMatch(materialString));
materials.addAll(ItemHelper.getWildcardMatch(materialString, true));
}
String[] ignoredSalvageStrings = data[1].split(",");
String[] ignoredSalvageStrings = data[1].split(";");
List<Material> ignored = new ArrayList<>();
for (String ignoredSalvageString : ignoredSalvageStrings) {
ignored.addAll(ItemHelper.getWildcardMatch(ignoredSalvageString));
ignored.addAll(ItemHelper.getWildcardMatch(ignoredSalvageString, true));
}
// Add the ignored salvage to all the matched materials

View File

@ -6,6 +6,8 @@ import net.knarcraft.blacksmith.config.TraitSettings;
import net.knarcraft.blacksmith.util.ConfigHelper;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
@ -57,7 +59,7 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
* @param setting <p>The setting to change</p>
* @param newValue <p>The new value of the setting</p>
*/
public void changeValue(ScrapperSetting setting, Object newValue) {
public void changeValue(@NotNull ScrapperSetting setting, @Nullable Object newValue) {
if (setting.getValueType() == SettingValueType.STRING_LIST ||
setting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
//Workaround to make sure it's treated as the correct type
@ -87,21 +89,24 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
* @param setting <p>The setting to get the value of</p>
* @return <p>The current value of the setting</p>
*/
public Object getRawValue(ScrapperSetting setting) {
public @NotNull Object getRawValue(@NotNull ScrapperSetting setting) {
return currentValues.get(setting);
}
@Override
@NotNull
public String getBusyWithPlayerMessage() {
return asString(ScrapperSetting.BUSY_WITH_PLAYER_MESSAGE);
}
@Override
@NotNull
public String getBusyWorkingMessage() {
return asString(ScrapperSetting.BUSY_WITH_SALVAGE_MESSAGE);
}
@Override
@NotNull
public String getStartWorkingMessage() {
return asString(ScrapperSetting.START_SALVAGE_MESSAGE);
}
@ -111,6 +116,7 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
*
* @return <p>The salvage success message</p>
*/
@NotNull
public String getSuccessMessage() {
return asString(ScrapperSetting.SUCCESS_SALVAGE_MESSAGE);
}
@ -120,11 +126,22 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
*
* @return <p>The salvage fail message</p>
*/
@NotNull
public String getFailMessage() {
return asString(ScrapperSetting.FAIL_SALVAGE_MESSAGE);
}
/**
* Gets the message to use for displaying salvage cost
*
* @return <p>The message to use for displaying salvage cost</p>
*/
public String getCostMessage() {
return asString(ScrapperSetting.COST_MESSAGE);
}
@Override
@NotNull
public String getCoolDownUnexpiredMessage() {
return asString(ScrapperSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
}
@ -132,6 +149,7 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
/**
* The message displayed if a player presents a different item after seeing the price to salvage an item
*/
@NotNull
public String getItemChangedMessage() {
return asString(ScrapperSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
}
@ -177,15 +195,6 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
return asInt(ScrapperSetting.SALVAGE_COOL_DOWN) <= 0;
}
/**
* Gets whether to disable the delay between starting reforging and the reforging finishing
*
* @return <p>Whether to disable the reforge delay</p>
*/
public boolean getDisableDelay() {
return asInt(ScrapperSetting.MAX_SALVAGE_DELAY) <= 0;
}
/**
* Gets the chance of a salvaging to fail
*
@ -203,7 +212,7 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
* @param setting <p>The setting to get the value of</p>
* @return <p>The value of the given setting as an integer</p>
*/
private int asInt(ScrapperSetting setting) {
private int asInt(@NotNull ScrapperSetting setting) {
return ConfigHelper.asInt(getValue(setting));
}
@ -213,7 +222,8 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
* @param setting <p>The setting to get the value of</p>
* @return <p>The value of the given setting as a string</p>
*/
private String asString(ScrapperSetting setting) {
@NotNull
private String asString(@NotNull ScrapperSetting setting) {
return getValue(setting).toString();
}
@ -223,7 +233,8 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
* @param setting <p>The setting to get the value of</p>
* @return <p>The current value</p>
*/
private Object getValue(ScrapperSetting setting) {
@NotNull
private Object getValue(@NotNull ScrapperSetting setting) {
Object value = currentValues.get(setting);
//If not set, use the default value from the config.yml file
if (value == null) {
@ -244,6 +255,7 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
*
* @return <p>All salvageable items</p>
*/
@NotNull
public List<Material> getSalvageAbleItems() {
Object currentValue = currentValues.get(ScrapperSetting.SALVAGE_ABLE_ITEMS);
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
@ -257,7 +269,7 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
* Whether extended salvaging is enabled
*
* <p>When not extended, only repairable items can be salvaged. When extended, any item produced using a crafting
* recipe or a smithing transformation can be salvaged. This does not include smelting or similar.</p>
* recipe can be salvaged. This does not include smelting or similar.</p>
*
* @return <p>True if extended salvaging is enabled</p>
*/
@ -273,6 +285,7 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
*
* @return <p>The title of this scrapper NPC</p>
*/
@NotNull
public String getScrapperTitle() {
return asString(ScrapperSetting.SCRAPPER_TITLE);
}
@ -282,8 +295,19 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
*
* @return <p>The message to display</p>
*/
@NotNull
public String getInvalidItemMessage() {
return asString(ScrapperSetting.INVALID_ITEM_MESSAGE);
}
/**
* Gets the message to display if the player is unable to afford an item salvage
*
* @return <p>The message to display</p>
*/
@NotNull
public String getInsufficientFundsMessage() {
return asString(ScrapperSetting.INSUFFICIENT_FUNDS_MESSAGE);
}
}

View File

@ -140,10 +140,30 @@ public enum ScrapperSetting implements Setting {
START_SALVAGE_MESSAGE("startSalvageMessage", SettingValueType.STRING, "&eOk, let's see what I can do...",
"The message to display once the blacksmith starts re-forging", true, true),
/**
* The message displayed if a player is unable to pay the blacksmith
*/
INSUFFICIENT_FUNDS_MESSAGE("insufficientFundsMessage", SettingValueType.STRING,
"&cYou don't have enough money to salvage an item!",
"The message to display when a player cannot pay for the salvaging", true, true),
/**
* The message displayed when displaying the cost of reforging the held item to the player
*/
COST_MESSAGE("costMessage", SettingValueType.STRING,
"&eIt will cost &a{cost}&e to salvage that item! Click again to salvage!",
"The message to display when informing a player about the salvaging cost", true, true),
/*------------------
| Global settings |
------------------*/
/**
* The setting for the use cost of using the scrapper
*/
USE_COST("basePrice", SettingValueType.POSITIVE_DOUBLE, 0, "The cost of using a scrapper",
false, false),
/**
* Whether to display exact time in minutes and seconds when displaying a remaining cool-down
*/