Implements the scrapper global edit command
Changes setting quite a bit to avoid code duplication
This commit is contained in:
@ -1,45 +0,0 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An interface describing a global setting
|
||||
*/
|
||||
public interface GlobalSetting {
|
||||
|
||||
/**
|
||||
* Gets the full config path for this setting
|
||||
*
|
||||
* @return <p>The full config path for this setting</p>
|
||||
*/
|
||||
@NotNull String getPath();
|
||||
|
||||
/**
|
||||
* Gets the parent item of the defined path
|
||||
*
|
||||
* @return <p>The parent node</p>
|
||||
*/
|
||||
@NotNull String getParent();
|
||||
|
||||
/**
|
||||
* Gets the value of this setting
|
||||
*
|
||||
* @return <p>The value of this setting</p>
|
||||
*/
|
||||
@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();
|
||||
|
||||
/**
|
||||
* Gets the value type for this setting
|
||||
*
|
||||
* @return <p>The value type for this setting</p>
|
||||
*/
|
||||
@NotNull SettingValueType getValueType();
|
||||
|
||||
}
|
@ -3,9 +3,9 @@ package net.knarcraft.blacksmith.config;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An interface describing an NPC setting
|
||||
* An interface describing a setting
|
||||
*/
|
||||
public interface NPCSetting {
|
||||
public interface Setting {
|
||||
|
||||
/**
|
||||
* Gets the full config path for this setting
|
||||
@ -42,4 +42,20 @@ public interface NPCSetting {
|
||||
*/
|
||||
@NotNull SettingValueType getValueType();
|
||||
|
||||
/**
|
||||
* Gets whether this setting can be set per-NPC, or if it's set globally
|
||||
*
|
||||
* @return <p>True if this setting is set per-NPC</p>
|
||||
*/
|
||||
boolean isPerNPC();
|
||||
|
||||
/**
|
||||
* Gets whether this setting is a customizable message
|
||||
*
|
||||
* <p>Messages are a special case, as you generally want to see the raw formatting, not just the result.</p>
|
||||
*
|
||||
* @return <p>True if this setting is a customizable message</p>
|
||||
*/
|
||||
boolean isMessage();
|
||||
|
||||
}
|
26
src/main/java/net/knarcraft/blacksmith/config/Settings.java
Normal file
26
src/main/java/net/knarcraft/blacksmith/config/Settings.java
Normal file
@ -0,0 +1,26 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
|
||||
/**
|
||||
* An interface describing an object for managing settings
|
||||
*
|
||||
* @param <K> <p>The type of setting managed</p>
|
||||
*/
|
||||
public interface Settings<K extends Setting> {
|
||||
|
||||
/**
|
||||
* Changes the value of the given 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);
|
||||
|
||||
/**
|
||||
* Gets the current raw value of the given global setting
|
||||
*
|
||||
* @param setting <p>The setting to get</p>
|
||||
* @return <p>The current raw setting value</p>
|
||||
*/
|
||||
Object getRawValue(K setting);
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.config.blacksmith;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.config.Settings;
|
||||
import net.knarcraft.blacksmith.config.SmithPreset;
|
||||
import net.knarcraft.blacksmith.config.TraitSettings;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
@ -23,11 +24,11 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* A class which keeps track of all Blacksmith settings/config values for one NPC
|
||||
*/
|
||||
public class BlacksmithNPCSettings implements TraitSettings {
|
||||
public class BlacksmithNPCSettings implements TraitSettings, Settings<BlacksmithSetting> {
|
||||
|
||||
private final List<Material> reforgeAbleItems = new ArrayList<>();
|
||||
private final List<Enchantment> enchantmentBlocklist = new ArrayList<>();
|
||||
private final Map<BlacksmithNPCSetting, Object> currentValues = new HashMap<>();
|
||||
private final Map<BlacksmithSetting, Object> currentValues = new HashMap<>();
|
||||
private final GlobalBlacksmithSettings globalBlacksmithSettings;
|
||||
|
||||
/**
|
||||
@ -43,7 +44,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @param key <p>The data key to load variables from</p>
|
||||
*/
|
||||
public void loadVariables(DataKey key) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
for (BlacksmithSetting setting : BlacksmithSetting.values()) {
|
||||
if (key.keyExists(setting.getChildPath())) {
|
||||
currentValues.put(setting, key.getRaw(setting.getChildPath()));
|
||||
}
|
||||
@ -59,18 +60,13 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @param key <p>The data key to save variables to</p>
|
||||
*/
|
||||
public void saveVariables(DataKey key) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
for (BlacksmithSetting setting : BlacksmithSetting.values()) {
|
||||
key.setRaw(setting.getChildPath(), currentValues.get(setting));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes one setting to the given value
|
||||
*
|
||||
* @param setting <p>The setting to change</p>
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
*/
|
||||
public void changeSetting(BlacksmithNPCSetting setting, Object newValue) {
|
||||
@Override
|
||||
public void changeValue(BlacksmithSetting setting, 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
|
||||
@ -78,10 +74,10 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
} else {
|
||||
currentValues.put(setting, newValue);
|
||||
}
|
||||
if (setting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
if (setting == BlacksmithSetting.REFORGE_ABLE_ITEMS) {
|
||||
updateReforgeAbleItems();
|
||||
}
|
||||
if (setting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
if (setting == BlacksmithSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
updateEnchantmentBlocklist();
|
||||
}
|
||||
}
|
||||
@ -92,13 +88,13 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value of the setting</p>
|
||||
*/
|
||||
public Object getRawValue(BlacksmithNPCSetting setting) {
|
||||
public Object getRawValue(BlacksmithSetting setting) {
|
||||
return currentValues.get(setting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBusyWithPlayerMessage() {
|
||||
return asString(BlacksmithNPCSetting.BUSY_WITH_PLAYER_MESSAGE);
|
||||
return asString(BlacksmithSetting.BUSY_WITH_PLAYER_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,7 +103,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The busy reforging message</p>
|
||||
*/
|
||||
public String getBusyWorkingMessage() {
|
||||
return asString(BlacksmithNPCSetting.BUSY_WITH_REFORGE_MESSAGE);
|
||||
return asString(BlacksmithSetting.BUSY_WITH_REFORGE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,7 +112,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The message to use for displaying item cost</p>
|
||||
*/
|
||||
public String getCostMessage() {
|
||||
return asString(BlacksmithNPCSetting.COST_MESSAGE);
|
||||
return asString(BlacksmithSetting.COST_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +121,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The invalid item message</p>
|
||||
*/
|
||||
public String getInvalidItemMessage() {
|
||||
return asString(BlacksmithNPCSetting.INVALID_ITEM_MESSAGE);
|
||||
return asString(BlacksmithSetting.INVALID_ITEM_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,12 +130,12 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The not damaged message</p>
|
||||
*/
|
||||
public String getNotDamagedMessage() {
|
||||
return asString(BlacksmithNPCSetting.NOT_DAMAGED_MESSAGE);
|
||||
return asString(BlacksmithSetting.NOT_DAMAGED_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStartWorkingMessage() {
|
||||
return asString(BlacksmithNPCSetting.START_REFORGE_MESSAGE);
|
||||
return asString(BlacksmithSetting.START_REFORGE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -148,7 +144,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The reforge success message</p>
|
||||
*/
|
||||
public String getSuccessMessage() {
|
||||
return asString(BlacksmithNPCSetting.SUCCESS_MESSAGE);
|
||||
return asString(BlacksmithSetting.SUCCESS_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,7 +153,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The reforge fail message</p>
|
||||
*/
|
||||
public String getFailMessage() {
|
||||
return asString(BlacksmithNPCSetting.FAIL_MESSAGE);
|
||||
return asString(BlacksmithSetting.FAIL_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,12 +162,12 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The insufficient funds message</p>
|
||||
*/
|
||||
public String getInsufficientFundsMessage() {
|
||||
return asString(BlacksmithNPCSetting.INSUFFICIENT_FUNDS_MESSAGE);
|
||||
return asString(BlacksmithSetting.INSUFFICIENT_FUNDS_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCoolDownUnexpiredMessage() {
|
||||
return asString(BlacksmithNPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
|
||||
return asString(BlacksmithSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,7 +176,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The item changed message</p>
|
||||
*/
|
||||
public String getItemChangedMessage() {
|
||||
return asString(BlacksmithNPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
|
||||
return asString(BlacksmithSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +187,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>All items reforge-able by this NPC</p>
|
||||
*/
|
||||
public List<Material> getReforgeAbleItems() {
|
||||
Object currentValue = currentValues.get(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS);
|
||||
Object currentValue = currentValues.get(BlacksmithSetting.REFORGE_ABLE_ITEMS);
|
||||
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
|
||||
return globalBlacksmithSettings.getReforgeAbleItems();
|
||||
} else {
|
||||
@ -205,7 +201,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The list of blocked enchantments</p>
|
||||
*/
|
||||
public List<Enchantment> getEnchantmentBlocklist() {
|
||||
Object currentValue = currentValues.get(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST);
|
||||
Object currentValue = currentValues.get(BlacksmithSetting.ENCHANTMENT_BLOCKLIST);
|
||||
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
|
||||
return globalBlacksmithSettings.getEnchantmentBlocklist();
|
||||
} else {
|
||||
@ -219,7 +215,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The minimum reforge delay</p>
|
||||
*/
|
||||
public int getMinReforgeDelay() {
|
||||
return asInt(BlacksmithNPCSetting.MIN_REFORGE_DELAY);
|
||||
return asInt(BlacksmithSetting.MIN_REFORGE_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -228,7 +224,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The maximum reforge delay</p>
|
||||
*/
|
||||
public int getMaxReforgeDelay() {
|
||||
return asInt(BlacksmithNPCSetting.MAX_REFORGE_DELAY);
|
||||
return asInt(BlacksmithSetting.MAX_REFORGE_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,7 +233,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The reforge cool-down</p>
|
||||
*/
|
||||
public int getReforgeCoolDown() {
|
||||
return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN);
|
||||
return asInt(BlacksmithSetting.REFORGE_COOL_DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,7 +242,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The fail chance</p>
|
||||
*/
|
||||
public int getFailChance() {
|
||||
return asInt(BlacksmithNPCSetting.FAIL_CHANCE);
|
||||
return asInt(BlacksmithSetting.FAIL_CHANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,7 +251,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>Whether enchantments should be removed</p>
|
||||
*/
|
||||
public boolean getFailRemovesEnchantments() {
|
||||
return asBoolean(BlacksmithNPCSetting.FAIL_REMOVE_ENCHANTMENTS);
|
||||
return asBoolean(BlacksmithSetting.FAIL_REMOVE_ENCHANTMENTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,7 +260,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The extra enchantment chance</p>
|
||||
*/
|
||||
public int getExtraEnchantmentChance() {
|
||||
return asInt(BlacksmithNPCSetting.EXTRA_ENCHANTMENT_CHANCE);
|
||||
return asInt(BlacksmithSetting.EXTRA_ENCHANTMENT_CHANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -273,7 +269,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The maximum enchantments</p>
|
||||
*/
|
||||
public int getMaxEnchantments() {
|
||||
return asInt(BlacksmithNPCSetting.MAX_ENCHANTMENTS);
|
||||
return asInt(BlacksmithSetting.MAX_ENCHANTMENTS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,7 +278,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>Whether to drop reforged items on the ground</p>
|
||||
*/
|
||||
public boolean getDropItem() {
|
||||
return asBoolean(BlacksmithNPCSetting.DROP_ITEM);
|
||||
return asBoolean(BlacksmithSetting.DROP_ITEM);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -291,12 +287,12 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>The title of the blacksmith</p>
|
||||
*/
|
||||
public String getBlacksmithTitle() {
|
||||
return asString(BlacksmithNPCSetting.BLACKSMITH_TITLE);
|
||||
return asString(BlacksmithSetting.BLACKSMITH_TITLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDisableCoolDown() {
|
||||
return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN) <= 0;
|
||||
return asInt(BlacksmithSetting.REFORGE_COOL_DOWN) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,7 +301,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @return <p>True if this blacksmith is able to repair anvils</p>
|
||||
*/
|
||||
public boolean getRepairAnvils() {
|
||||
return asBoolean(BlacksmithNPCSetting.REPAIR_ANVILS);
|
||||
return asBoolean(BlacksmithSetting.REPAIR_ANVILS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -316,7 +312,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @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(BlacksmithNPCSetting setting) {
|
||||
private int asInt(BlacksmithSetting setting) {
|
||||
return ConfigHelper.asInt(getValue(setting));
|
||||
}
|
||||
|
||||
@ -326,7 +322,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @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(BlacksmithNPCSetting setting) {
|
||||
private String asString(BlacksmithSetting setting) {
|
||||
return getValue(setting).toString();
|
||||
}
|
||||
|
||||
@ -336,7 +332,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
private boolean asBoolean(BlacksmithNPCSetting setting) {
|
||||
private boolean asBoolean(BlacksmithSetting setting) {
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
@ -346,11 +342,11 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value</p>
|
||||
*/
|
||||
private Object getValue(BlacksmithNPCSetting setting) {
|
||||
private Object getValue(BlacksmithSetting setting) {
|
||||
Object value = currentValues.get(setting);
|
||||
//If not set, use the default value from the config.yml file
|
||||
if (value == null) {
|
||||
Map<BlacksmithNPCSetting, Object> defaultNPCSettings = globalBlacksmithSettings.getDefaultNPCSettings();
|
||||
Map<BlacksmithSetting, Object> defaultNPCSettings = globalBlacksmithSettings.getDefaultNPCSettings();
|
||||
if (defaultNPCSettings.containsKey(setting)) {
|
||||
value = defaultNPCSettings.get(setting);
|
||||
}
|
||||
@ -389,7 +385,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
*/
|
||||
private void updateEnchantmentBlocklist() {
|
||||
this.enchantmentBlocklist.clear();
|
||||
List<String> enchantments = ConfigHelper.asStringList(getValue(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST));
|
||||
List<String> enchantments = ConfigHelper.asStringList(getValue(BlacksmithSetting.ENCHANTMENT_BLOCKLIST));
|
||||
if (enchantments != null) {
|
||||
this.enchantmentBlocklist.addAll(getEnchantmentBlocklist(enchantments));
|
||||
}
|
||||
@ -425,7 +421,7 @@ public class BlacksmithNPCSettings implements TraitSettings {
|
||||
*/
|
||||
private void updateReforgeAbleItems() {
|
||||
this.reforgeAbleItems.clear();
|
||||
List<String> materialStrings = ConfigHelper.asStringList(getValue(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS));
|
||||
List<String> materialStrings = ConfigHelper.asStringList(getValue(BlacksmithSetting.REFORGE_ABLE_ITEMS));
|
||||
if (materialStrings != null) {
|
||||
this.reforgeAbleItems.addAll(getReforgeAbleItems(materialStrings));
|
||||
}
|
||||
|
@ -1,62 +1,69 @@
|
||||
package net.knarcraft.blacksmith.config.blacksmith;
|
||||
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.Setting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* An enum representing all of Blacksmith's settings
|
||||
*/
|
||||
public enum BlacksmithNPCSetting implements NPCSetting {
|
||||
public enum BlacksmithSetting implements Setting {
|
||||
|
||||
/**
|
||||
* The setting for whether the NPC should drop an item to the ground when finished
|
||||
*
|
||||
* <p>If set to false, the item will be directly put in the player's inventory instead</p>
|
||||
*/
|
||||
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"),
|
||||
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem", true, false),
|
||||
|
||||
/**
|
||||
* The setting for the chance of a reforging to fail
|
||||
*/
|
||||
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
|
||||
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance",
|
||||
true, false),
|
||||
|
||||
/**
|
||||
* The setting for whether failing a reforging should downgrade/remove enchantments as well
|
||||
*/
|
||||
FAIL_REMOVE_ENCHANTMENTS("failReforgeRemovesEnchantments", SettingValueType.BOOLEAN, false,
|
||||
"failReforgeRemovesEnchantments"),
|
||||
"failReforgeRemovesEnchantments", true, false),
|
||||
|
||||
/**
|
||||
* The setting for the chance of an additional enchantment being added
|
||||
*/
|
||||
EXTRA_ENCHANTMENT_CHANCE("extraEnchantmentChance", SettingValueType.PERCENTAGE, 5,
|
||||
"extraEnchantmentChance"),
|
||||
"extraEnchantmentChance", true, false),
|
||||
|
||||
/**
|
||||
* The setting for the maximum amount of enchantments that can be added to an item
|
||||
*/
|
||||
MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"),
|
||||
MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3,
|
||||
"maxEnchantments", true, false),
|
||||
|
||||
/**
|
||||
* The maximum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MAX_REFORGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"),
|
||||
MAX_REFORGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30,
|
||||
"maxReforgeDelay", true, false),
|
||||
|
||||
/**
|
||||
* The minimum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MIN_REFORGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"),
|
||||
MIN_REFORGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5,
|
||||
"minReforgeDelay", true, false),
|
||||
|
||||
/**
|
||||
* The setting for number of seconds a player has to wait between each usage of the blacksmith
|
||||
*/
|
||||
REFORGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"),
|
||||
REFORGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60,
|
||||
"reforgeCoolDown", true, false),
|
||||
|
||||
/**
|
||||
* The setting for which items the blacksmith is able to reforge
|
||||
*/
|
||||
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"),
|
||||
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "",
|
||||
"reforgeAbleItems", true, false),
|
||||
|
||||
/**
|
||||
* The setting for the title used to display which kind of blacksmith the NPC is
|
||||
@ -64,18 +71,20 @@ public enum BlacksmithNPCSetting implements NPCSetting {
|
||||
* <p>While this should be entirely configurable, values such as armor-smith, sword-smith and similar, which
|
||||
* describe the blacksmith's specialization, and thus the range of reforge-able items, is expected.</p>
|
||||
*/
|
||||
BLACKSMITH_TITLE("blacksmithTitle", SettingValueType.STRING, "blacksmith", "blacksmithTitle"),
|
||||
BLACKSMITH_TITLE("blacksmithTitle", SettingValueType.STRING, "blacksmith",
|
||||
"blacksmithTitle", true, false),
|
||||
|
||||
/**
|
||||
* The setting for the enchantments a blacksmith cannot apply to items
|
||||
*/
|
||||
ENCHANTMENT_BLOCKLIST("enchantmentBlocklist", SettingValueType.STRING_LIST, new String[]{"binding_curse",
|
||||
"mending", "vanishing_curse"}, "enchantmentBlocklist"),
|
||||
"mending", "vanishing_curse"}, "enchantmentBlocklist", true, false),
|
||||
|
||||
/**
|
||||
* Whether to allow this blacksmith to repair anvils
|
||||
*/
|
||||
REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils"),
|
||||
REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils",
|
||||
true, false),
|
||||
|
||||
/*-----------
|
||||
| Messages |
|
||||
@ -85,74 +94,137 @@ public enum BlacksmithNPCSetting implements NPCSetting {
|
||||
* The message displayed when the blacksmith is busy with another player
|
||||
*/
|
||||
BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING,
|
||||
"&cI'm busy at the moment. Come back later!", "busyPlayerMessage"),
|
||||
"&cI'm busy at the moment. Come back later!", "busyPlayerMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith is already reforging something for the player
|
||||
*/
|
||||
BUSY_WITH_REFORGE_MESSAGE("messages.busyReforgeMessage", SettingValueType.STRING,
|
||||
"&cI'm working on it. Be patient! I'll finish {time}!", "busyReforgeMessage"),
|
||||
"&cI'm working on it. Be patient! I'll finish {time}!", "busyReforgeMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if the player has to wait for the cool-down to expire
|
||||
*/
|
||||
COOL_DOWN_UNEXPIRED_MESSAGE("messages.coolDownUnexpiredMessage", SettingValueType.STRING,
|
||||
"&cYou've already had your chance! Give me a break! I'll be ready {time}!",
|
||||
"coolDownUnexpiredMessage"),
|
||||
"coolDownUnexpiredMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed when displaying the cost of reforging the held item to the player
|
||||
*/
|
||||
COST_MESSAGE("messages.costMessage", SettingValueType.STRING,
|
||||
"&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!", "costMessage"),
|
||||
"&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!",
|
||||
"costMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if the blacksmith fails reforging an item
|
||||
*/
|
||||
FAIL_MESSAGE("messages.failReforgeMessage", SettingValueType.STRING,
|
||||
"&cWhoops! Didn't mean to do that! Maybe next time?", "failReforgeMessage"),
|
||||
"&cWhoops! Didn't mean to do that! Maybe next time?", "failReforgeMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if a player is unable to pay the blacksmith
|
||||
*/
|
||||
INSUFFICIENT_FUNDS_MESSAGE("messages.insufficientFundsMessage", SettingValueType.STRING,
|
||||
"&cYou don't have enough money to reforge that item!", "insufficientFundsMessage"),
|
||||
"&cYou don't have enough money to reforge that item!", "insufficientFundsMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if the blacksmith encounters an item they cannot reforge
|
||||
*/
|
||||
INVALID_ITEM_MESSAGE("messages.invalidItemMessage", SettingValueType.STRING,
|
||||
"&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!", "invalidItemMessage"),
|
||||
"&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!",
|
||||
"invalidItemMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if a player presents a different item after seeing the price to reforge an item
|
||||
*/
|
||||
ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("messages.itemChangedMessage", SettingValueType.STRING,
|
||||
"&cThat's not the item you wanted to reforge before!", "itemChangedMessage"),
|
||||
"&cThat's not the item you wanted to reforge before!", "itemChangedMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith starts reforging an item
|
||||
*/
|
||||
START_REFORGE_MESSAGE("messages.startReforgeMessage", SettingValueType.STRING,
|
||||
"&eOk, let's see what I can do...", "startReforgeMessage"),
|
||||
"&eOk, let's see what I can do...", "startReforgeMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed when the blacksmith successfully finishes reforging an item
|
||||
*/
|
||||
SUCCESS_MESSAGE("messages.successMessage", SettingValueType.STRING,
|
||||
"There you go! All better!", "successMessage"),
|
||||
"There you go! All better!", "successMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed when trying to reforge an item with full durability
|
||||
*/
|
||||
NOT_DAMAGED_MESSAGE("messages.notDamagedMessage", SettingValueType.STRING,
|
||||
"&cThat item is not in need of repair", "notDamagedMessage");
|
||||
"&cThat item is not in need of repair", "notDamagedMessage", true, true),
|
||||
|
||||
/*------------------
|
||||
| Global settings |
|
||||
------------------*/
|
||||
|
||||
/**
|
||||
* The base price for repairing, regardless of durability
|
||||
*
|
||||
* <p>This allows specifying a price for each item, by setting basePrice.item_name.</p>
|
||||
*/
|
||||
BASE_PRICE("basePrice.default", SettingValueType.POSITIVE_DOUBLE, 10.0, "basePrice",
|
||||
false, false),
|
||||
|
||||
/**
|
||||
* The base price for each durability point
|
||||
*
|
||||
* <p>If natural cost, this is the cost each missing durability point will add to the cost. If not natural cost,
|
||||
* this is the cost each present durability point will add to the cost. This allows specifying a price per
|
||||
* durability point value for each item, by setting pricePerDurabilityPoint.item_name</p>
|
||||
*/
|
||||
PRICE_PER_DURABILITY_POINT("pricePerDurabilityPoint.default", SettingValueType.POSITIVE_DOUBLE,
|
||||
0.005, "pricePerDurabilityPoint", false, false),
|
||||
|
||||
/**
|
||||
* The price increase for each level of each present enchantment
|
||||
*
|
||||
* <p>This can be specified for each possible enchantment by setting enchantment-cost.enchantment_name</p>
|
||||
*/
|
||||
ENCHANTMENT_COST("enchantmentCost.default", SettingValueType.POSITIVE_DOUBLE, 5.0,
|
||||
"enchantmentCost", false, false),
|
||||
|
||||
/**
|
||||
* Whether the cost should increase for damage taken, as opposed to increase for durability present
|
||||
*/
|
||||
NATURAL_COST("useNaturalCost", SettingValueType.BOOLEAN, true, "useNaturalCost",
|
||||
false, false),
|
||||
|
||||
/**
|
||||
* Whether to show exact time when displaying the wait time for a reforging or the cool-down
|
||||
*/
|
||||
SHOW_EXACT_TIME("showExactTime", SettingValueType.BOOLEAN, false, "showExactTime",
|
||||
false, false),
|
||||
|
||||
/**
|
||||
* The cost for repairing a chipped anvil
|
||||
*/
|
||||
ANVIL_CHIPPED_COST("chippedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 10.0,
|
||||
"chippedAnvilReforgingCost", false, false),
|
||||
|
||||
/**
|
||||
* The cost for repairing a damaged anvil
|
||||
*/
|
||||
ANVIL_DAMAGED_COST("damagedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 20.0,
|
||||
"damagedAnvilReforgingCost", false, false);
|
||||
|
||||
private final String path;
|
||||
private final String childPath;
|
||||
private final Object value;
|
||||
private final String commandName;
|
||||
private final SettingValueType valueType;
|
||||
private final boolean isPerNPC;
|
||||
private final boolean isMessage;
|
||||
|
||||
/**
|
||||
* Instantiates a new setting
|
||||
@ -161,13 +233,22 @@ public enum BlacksmithNPCSetting implements NPCSetting {
|
||||
* @param valueType <p>The type of value used by this setting</p>
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
* @param isPerNPC <p>Whether this setting is per-NPC or global</p>
|
||||
* @param isMessage <p>Whether this option is for an NPC message</p>
|
||||
*/
|
||||
BlacksmithNPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = "blacksmith.defaults." + path;
|
||||
BlacksmithSetting(String path, SettingValueType valueType, Object value, String commandName, boolean isPerNPC,
|
||||
boolean isMessage) {
|
||||
if (isPerNPC) {
|
||||
this.path = "blacksmith.defaults." + path;
|
||||
} else {
|
||||
this.path = "blacksmith.global." + path;
|
||||
}
|
||||
this.value = value;
|
||||
this.valueType = valueType;
|
||||
this.childPath = path;
|
||||
this.commandName = commandName;
|
||||
this.isPerNPC = isPerNPC;
|
||||
this.isMessage = isMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -195,4 +276,29 @@ public enum BlacksmithNPCSetting implements NPCSetting {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPerNPC() {
|
||||
return this.isPerNPC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMessage() {
|
||||
return this.isMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blacksmith setting specified by the input string
|
||||
*
|
||||
* @param input <p>The input to check</p>
|
||||
* @return <p>The matching blacksmith setting, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable BlacksmithSetting getSetting(@NotNull String input) {
|
||||
for (BlacksmithSetting blacksmithSetting : BlacksmithSetting.values()) {
|
||||
if (input.equalsIgnoreCase(blacksmithSetting.commandName)) {
|
||||
return blacksmithSetting;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
package net.knarcraft.blacksmith.config.blacksmith;
|
||||
|
||||
import net.knarcraft.blacksmith.config.GlobalSetting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Settings which are the same for every blacksmith
|
||||
*/
|
||||
public enum GlobalBlacksmithSetting implements GlobalSetting {
|
||||
|
||||
/**
|
||||
* The base price for repairing, regardless of durability
|
||||
*
|
||||
* <p>This allows specifying a price for each item, by setting basePrice.item_name.</p>
|
||||
*/
|
||||
BASE_PRICE("basePrice.default", SettingValueType.POSITIVE_DOUBLE, 10.0, "basePrice"),
|
||||
|
||||
/**
|
||||
* The base price for each durability point
|
||||
*
|
||||
* <p>If natural cost, this is the cost each missing durability point will add to the cost. If not natural cost,
|
||||
* this is the cost each present durability point will add to the cost. This allows specifying a price per
|
||||
* durability point value for each item, by setting pricePerDurabilityPoint.item_name</p>
|
||||
*/
|
||||
PRICE_PER_DURABILITY_POINT("pricePerDurabilityPoint.default", SettingValueType.POSITIVE_DOUBLE,
|
||||
0.005, "pricePerDurabilityPoint"),
|
||||
|
||||
/**
|
||||
* The price increase for each level of each present enchantment
|
||||
*
|
||||
* <p>This can be specified for each possible enchantment by setting enchantment-cost.enchantment_name</p>
|
||||
*/
|
||||
ENCHANTMENT_COST("enchantmentCost.default", SettingValueType.POSITIVE_DOUBLE, 5.0,
|
||||
"enchantmentCost"),
|
||||
|
||||
/**
|
||||
* Whether the cost should increase for damage taken, as opposed to increase for durability present
|
||||
*/
|
||||
NATURAL_COST("useNaturalCost", SettingValueType.BOOLEAN, true, "useNaturalCost"),
|
||||
|
||||
/**
|
||||
* Whether to show exact time when displaying the wait time for a reforging or the cool-down
|
||||
*/
|
||||
SHOW_EXACT_TIME("showExactTime", SettingValueType.BOOLEAN, false, "showExactTime"),
|
||||
|
||||
/**
|
||||
* The cost for repairing a chipped anvil
|
||||
*/
|
||||
ANVIL_CHIPPED_COST("chippedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 10.0,
|
||||
"chippedAnvilReforgingCost"),
|
||||
|
||||
/**
|
||||
* The cost for repairing a damaged anvil
|
||||
*/
|
||||
ANVIL_DAMAGED_COST("damagedAnvilReforgingCost", SettingValueType.POSITIVE_DOUBLE, 20.0,
|
||||
"damagedAnvilReforgingCost");
|
||||
|
||||
private final String path;
|
||||
private final String parent;
|
||||
private final String commandName;
|
||||
private final Object value;
|
||||
private final SettingValueType valueType;
|
||||
|
||||
/**
|
||||
* Instantiates a new setting
|
||||
*
|
||||
* @param path <p>The full config path for this setting</p>
|
||||
* @param valueType <p>The type of value used by this setting</p>
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
*/
|
||||
GlobalBlacksmithSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = "blacksmith.global." + path;
|
||||
this.value = value;
|
||||
this.commandName = commandName;
|
||||
this.valueType = valueType;
|
||||
String[] pathParts = path.split("\\.");
|
||||
this.parent = String.join(".", Arrays.copyOfRange(pathParts, 0, pathParts.length - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Object getDefaultValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getCommandName() {
|
||||
return commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SettingValueType getValueType() {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.config.Settings;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import net.knarcraft.blacksmith.util.InputParsingHelper;
|
||||
import net.knarcraft.blacksmith.util.ItemHelper;
|
||||
@ -20,15 +21,14 @@ import java.util.logging.Level;
|
||||
/**
|
||||
* A class which keeps track of all default NPC settings and all global settings
|
||||
*/
|
||||
public class GlobalBlacksmithSettings {
|
||||
public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> {
|
||||
|
||||
private final Map<Material, Double> materialBasePrices = new HashMap<>();
|
||||
private final Map<Material, Double> materialPricePerDurabilityPoints = new HashMap<>();
|
||||
private final Map<Enchantment, Double> enchantmentCosts = new HashMap<>();
|
||||
private final Map<BlacksmithNPCSetting, Object> defaultNPCSettings = 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 Map<GlobalBlacksmithSetting, Object> globalSettings = new HashMap<>();
|
||||
|
||||
private final YamlStorage defaultConfig;
|
||||
|
||||
@ -47,78 +47,53 @@ public class GlobalBlacksmithSettings {
|
||||
* Loads all configuration values from the config file
|
||||
*/
|
||||
public void load() {
|
||||
//Load the config from disk
|
||||
// Load the config from disk
|
||||
defaultConfig.load();
|
||||
DataKey root = defaultConfig.getKey("");
|
||||
|
||||
//Just in case, clear existing values
|
||||
defaultNPCSettings.clear();
|
||||
globalSettings.clear();
|
||||
// Just in case, clear existing values
|
||||
settings.clear();
|
||||
materialBasePrices.clear();
|
||||
materialPricePerDurabilityPoints.clear();
|
||||
enchantmentCosts.clear();
|
||||
|
||||
//Load/Save NPC default settings
|
||||
loadDefaultNPCSettings(root);
|
||||
|
||||
//Load/Save global settings
|
||||
// Load/Save settings
|
||||
loadGlobalSettings(root);
|
||||
|
||||
//Save any modified values to disk
|
||||
// Save any modified values to disk
|
||||
defaultConfig.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param globalBlacksmithSetting <p>The global setting to change</p>
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
* @param blacksmithSetting <p>The default NPC setting to change</p>
|
||||
* @param newValue <p>The new value for the setting</p>
|
||||
*/
|
||||
public void changeValue(GlobalBlacksmithSetting globalBlacksmithSetting, Object newValue) {
|
||||
globalSettings.put(globalBlacksmithSetting, newValue);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param blacksmithNpcSetting <p>The default NPC setting to change</p>
|
||||
* @param newValue <p>The new value for the setting</p>
|
||||
*/
|
||||
public void changeValue(BlacksmithNPCSetting blacksmithNpcSetting, Object newValue) {
|
||||
if (blacksmithNpcSetting.getValueType() == SettingValueType.STRING_LIST ||
|
||||
blacksmithNpcSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
|
||||
public void changeValue(BlacksmithSetting blacksmithSetting, 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
|
||||
defaultNPCSettings.put(blacksmithNpcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||
settings.put(blacksmithSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||
} else {
|
||||
defaultNPCSettings.put(blacksmithNpcSetting, newValue);
|
||||
settings.put(blacksmithSetting, newValue);
|
||||
}
|
||||
save();
|
||||
if (blacksmithNpcSetting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
if (blacksmithSetting == BlacksmithSetting.REFORGE_ABLE_ITEMS) {
|
||||
loadReforgeAbleItems();
|
||||
} else if (blacksmithNpcSetting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
} else if (blacksmithSetting == BlacksmithSetting.ENCHANTMENT_BLOCKLIST) {
|
||||
loadEnchantmentBlocklist();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current raw value of the given global setting
|
||||
*
|
||||
* @param globalBlacksmithSetting <p>The setting to get</p>
|
||||
* @return <p>The current raw setting value</p>
|
||||
*/
|
||||
public Object getRawValue(GlobalBlacksmithSetting globalBlacksmithSetting) {
|
||||
return globalSettings.get(globalBlacksmithSetting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current raw value of the given default NPC setting
|
||||
*
|
||||
* @param blacksmithNpcSetting <p>The setting to get</p>
|
||||
* @param blacksmithSetting <p>The setting to get</p>
|
||||
* @return <p>The current raw setting value</p>
|
||||
*/
|
||||
public Object getRawValue(BlacksmithNPCSetting blacksmithNpcSetting) {
|
||||
return defaultNPCSettings.get(blacksmithNpcSetting);
|
||||
public Object getRawValue(BlacksmithSetting blacksmithSetting) {
|
||||
return settings.get(blacksmithSetting);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,7 +107,7 @@ public class GlobalBlacksmithSettings {
|
||||
if (newEnchantmentCost < 0) {
|
||||
throw new IllegalArgumentException("Enchantment cost cannot be negative!");
|
||||
}
|
||||
globalSettings.put(GlobalBlacksmithSetting.ENCHANTMENT_COST, newEnchantmentCost);
|
||||
settings.put(BlacksmithSetting.ENCHANTMENT_COST, newEnchantmentCost);
|
||||
} else {
|
||||
if (newEnchantmentCost < 0) {
|
||||
enchantmentCosts.put(enchantment, null);
|
||||
@ -154,7 +129,7 @@ public class GlobalBlacksmithSettings {
|
||||
if (newPrice < 0) {
|
||||
throw new IllegalArgumentException("Price per durability point cannot be negative!");
|
||||
}
|
||||
globalSettings.put(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT, newPrice);
|
||||
settings.put(BlacksmithSetting.PRICE_PER_DURABILITY_POINT, newPrice);
|
||||
} else {
|
||||
//Use a negative price to unset the per-item value
|
||||
if (newPrice < 0) {
|
||||
@ -177,7 +152,7 @@ public class GlobalBlacksmithSettings {
|
||||
if (newBasePrice < 0) {
|
||||
throw new IllegalArgumentException("Base price cannot be negative!");
|
||||
}
|
||||
globalSettings.put(GlobalBlacksmithSetting.BASE_PRICE, newBasePrice);
|
||||
settings.put(BlacksmithSetting.BASE_PRICE, newBasePrice);
|
||||
} else {
|
||||
//Use a negative price to unset the per-item value
|
||||
if (newBasePrice < 0) {
|
||||
@ -194,8 +169,8 @@ public class GlobalBlacksmithSettings {
|
||||
*
|
||||
* @return <p>The current value of the default NPC settings</p>
|
||||
*/
|
||||
public Map<BlacksmithNPCSetting, Object> getDefaultNPCSettings() {
|
||||
return new HashMap<>(this.defaultNPCSettings);
|
||||
public Map<BlacksmithSetting, Object> getDefaultNPCSettings() {
|
||||
return new HashMap<>(this.settings);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,7 +182,7 @@ public class GlobalBlacksmithSettings {
|
||||
* @return <p>Whether to use natural cost</p>
|
||||
*/
|
||||
public boolean getUseNaturalCost() {
|
||||
return asBoolean(GlobalBlacksmithSetting.NATURAL_COST);
|
||||
return asBoolean(BlacksmithSetting.NATURAL_COST);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,7 +191,7 @@ public class GlobalBlacksmithSettings {
|
||||
* @return <p>Whether to show exact time</p>
|
||||
*/
|
||||
public boolean getShowExactTime() {
|
||||
return asBoolean(GlobalBlacksmithSetting.SHOW_EXACT_TIME);
|
||||
return asBoolean(BlacksmithSetting.SHOW_EXACT_TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,7 +204,7 @@ public class GlobalBlacksmithSettings {
|
||||
if (materialBasePrices.containsKey(material) && materialBasePrices.get(material) != null) {
|
||||
return materialBasePrices.get(material);
|
||||
} else {
|
||||
return asDouble(GlobalBlacksmithSetting.BASE_PRICE);
|
||||
return asDouble(BlacksmithSetting.BASE_PRICE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +219,7 @@ public class GlobalBlacksmithSettings {
|
||||
materialPricePerDurabilityPoints.get(material) != null) {
|
||||
return materialPricePerDurabilityPoints.get(material);
|
||||
} else {
|
||||
return asDouble(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT);
|
||||
return asDouble(BlacksmithSetting.PRICE_PER_DURABILITY_POINT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,7 +233,7 @@ public class GlobalBlacksmithSettings {
|
||||
if (enchantmentCosts.containsKey(enchantment) && enchantmentCosts.get(enchantment) != null) {
|
||||
return enchantmentCosts.get(enchantment);
|
||||
} else {
|
||||
return asDouble(GlobalBlacksmithSetting.ENCHANTMENT_COST);
|
||||
return asDouble(BlacksmithSetting.ENCHANTMENT_COST);
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,9 +263,9 @@ public class GlobalBlacksmithSettings {
|
||||
*/
|
||||
public double getAnvilCost(Material material) {
|
||||
if (material == Material.CHIPPED_ANVIL) {
|
||||
return asDouble(GlobalBlacksmithSetting.ANVIL_CHIPPED_COST);
|
||||
return asDouble(BlacksmithSetting.ANVIL_CHIPPED_COST);
|
||||
} else if (material == Material.DAMAGED_ANVIL) {
|
||||
return asDouble(GlobalBlacksmithSetting.ANVIL_DAMAGED_COST);
|
||||
return asDouble(BlacksmithSetting.ANVIL_DAMAGED_COST);
|
||||
} else {
|
||||
throw new IllegalArgumentException("An unexpected item was encountered!");
|
||||
}
|
||||
@ -304,7 +279,7 @@ public class GlobalBlacksmithSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
public boolean asBoolean(GlobalBlacksmithSetting setting) {
|
||||
public boolean asBoolean(BlacksmithSetting setting) {
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
@ -316,7 +291,7 @@ public class GlobalBlacksmithSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a double</p>
|
||||
*/
|
||||
public double asDouble(GlobalBlacksmithSetting setting) {
|
||||
public double asDouble(BlacksmithSetting setting) {
|
||||
return ConfigHelper.asDouble(getValue(setting));
|
||||
}
|
||||
|
||||
@ -326,8 +301,8 @@ public class GlobalBlacksmithSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value</p>
|
||||
*/
|
||||
private Object getValue(GlobalBlacksmithSetting setting) {
|
||||
Object value = globalSettings.get(setting);
|
||||
private Object getValue(BlacksmithSetting setting) {
|
||||
Object value = settings.get(setting);
|
||||
//If not set in config.yml, use the default value from the enum
|
||||
if (value == null) {
|
||||
value = setting.getDefaultValue();
|
||||
@ -341,15 +316,17 @@ public class GlobalBlacksmithSettings {
|
||||
* @param root <p>The root node of all global settings</p>
|
||||
*/
|
||||
private void loadGlobalSettings(DataKey root) {
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
if (!root.keyExists(globalBlacksmithSetting.getPath())) {
|
||||
for (BlacksmithSetting blacksmithSetting : BlacksmithSetting.values()) {
|
||||
if (!root.keyExists(blacksmithSetting.getPath())) {
|
||||
//If the setting does not exist in the config file, add it
|
||||
root.setRaw(globalBlacksmithSetting.getPath(), globalBlacksmithSetting.getDefaultValue());
|
||||
root.setRaw(blacksmithSetting.getPath(), blacksmithSetting.getDefaultValue());
|
||||
} else {
|
||||
//Set the setting to the value found in the path
|
||||
globalSettings.put(globalBlacksmithSetting, root.getRaw(globalBlacksmithSetting.getPath()));
|
||||
settings.put(blacksmithSetting, root.getRaw(blacksmithSetting.getPath()));
|
||||
}
|
||||
}
|
||||
loadReforgeAbleItems();
|
||||
loadEnchantmentBlocklist();
|
||||
|
||||
//Load all base prices
|
||||
loadBasePrices(root);
|
||||
@ -358,7 +335,7 @@ public class GlobalBlacksmithSettings {
|
||||
loadPricesPerDurabilityPoint(root);
|
||||
|
||||
//Load all enchantment prices
|
||||
DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent());
|
||||
DataKey enchantmentCostNode = root.getRelative(BlacksmithSetting.ENCHANTMENT_COST.getPath());
|
||||
Map<String, String> relevantKeys = getRelevantKeys(enchantmentCostNode);
|
||||
for (String key : relevantKeys.keySet()) {
|
||||
String enchantmentName = relevantKeys.get(key);
|
||||
@ -373,7 +350,7 @@ public class GlobalBlacksmithSettings {
|
||||
* @param root <p>The configuration root node to search from</p>
|
||||
*/
|
||||
private void loadPricesPerDurabilityPoint(DataKey root) {
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent());
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(BlacksmithSetting.PRICE_PER_DURABILITY_POINT.getPath());
|
||||
Map<String, String> relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
|
||||
|
||||
for (String key : relevantKeys.keySet()) {
|
||||
@ -395,7 +372,7 @@ public class GlobalBlacksmithSettings {
|
||||
* @param root <p>The configuration root node to search from</p>
|
||||
*/
|
||||
private void loadBasePrices(DataKey root) {
|
||||
DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent());
|
||||
DataKey basePriceNode = root.getRelative(BlacksmithSetting.BASE_PRICE.getPath());
|
||||
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
|
||||
|
||||
for (String key : relevantKeys.keySet()) {
|
||||
@ -474,32 +451,13 @@ public class GlobalBlacksmithSettings {
|
||||
return normalizedName.toLowerCase().replace("_", "-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all default NPC settings
|
||||
*
|
||||
* @param root <p>The root node of all default NPC settings</p>
|
||||
*/
|
||||
private void loadDefaultNPCSettings(DataKey root) {
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
if (!root.keyExists(setting.getPath())) {
|
||||
//If the setting does not exist in the config file, add it
|
||||
root.setRaw(setting.getPath(), setting.getDefaultValue());
|
||||
} else {
|
||||
//Set the setting to the value found in the path
|
||||
defaultNPCSettings.put(setting, root.getRaw(setting.getPath()));
|
||||
}
|
||||
}
|
||||
loadReforgeAbleItems();
|
||||
loadEnchantmentBlocklist();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads reforgeAble items from the current value
|
||||
*/
|
||||
private void loadReforgeAbleItems() {
|
||||
defaultReforgeAbleMaterials.clear();
|
||||
List<String> materialNames = ConfigHelper.asStringList(defaultNPCSettings.get(
|
||||
BlacksmithNPCSetting.REFORGE_ABLE_ITEMS));
|
||||
List<String> materialNames = ConfigHelper.asStringList(settings.get(
|
||||
BlacksmithSetting.REFORGE_ABLE_ITEMS));
|
||||
if (materialNames != null) {
|
||||
defaultReforgeAbleMaterials.addAll(BlacksmithNPCSettings.getReforgeAbleItems(materialNames));
|
||||
}
|
||||
@ -510,8 +468,8 @@ public class GlobalBlacksmithSettings {
|
||||
*/
|
||||
private void loadEnchantmentBlocklist() {
|
||||
defaultEnchantmentBlocklist.clear();
|
||||
List<String> enchantmentNames = ConfigHelper.asStringList(defaultNPCSettings.get(
|
||||
BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST));
|
||||
List<String> enchantmentNames = ConfigHelper.asStringList(settings.get(
|
||||
BlacksmithSetting.ENCHANTMENT_BLOCKLIST));
|
||||
if (enchantmentNames != null) {
|
||||
defaultEnchantmentBlocklist.addAll(BlacksmithNPCSettings.getEnchantmentBlocklist(enchantmentNames));
|
||||
}
|
||||
@ -522,30 +480,25 @@ public class GlobalBlacksmithSettings {
|
||||
*/
|
||||
private void save() {
|
||||
DataKey root = defaultConfig.getKey("");
|
||||
//Save all default NPC settings
|
||||
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
|
||||
root.setRaw(setting.getPath(), defaultNPCSettings.get(setting));
|
||||
}
|
||||
|
||||
//Save all normal global settings
|
||||
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
|
||||
root.setRaw(globalBlacksmithSetting.getPath(), globalSettings.get(globalBlacksmithSetting));
|
||||
//Save all default settings
|
||||
for (BlacksmithSetting setting : BlacksmithSetting.values()) {
|
||||
root.setRaw(setting.getPath(), settings.get(setting));
|
||||
}
|
||||
|
||||
//Save all base prices
|
||||
DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent());
|
||||
DataKey basePriceNode = root.getRelative(BlacksmithSetting.BASE_PRICE.getPath());
|
||||
for (Material material : materialBasePrices.keySet()) {
|
||||
basePriceNode.setRaw(unNormalizeName(material.name()), materialBasePrices.get(material));
|
||||
}
|
||||
|
||||
//Save all per-durability-point prices
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent());
|
||||
DataKey basePerDurabilityPriceNode = root.getRelative(BlacksmithSetting.PRICE_PER_DURABILITY_POINT.getPath());
|
||||
for (Material material : materialPricePerDurabilityPoints.keySet()) {
|
||||
basePerDurabilityPriceNode.setRaw(unNormalizeName(material.name()), materialPricePerDurabilityPoints.get(material));
|
||||
}
|
||||
|
||||
//Load all enchantment prices
|
||||
DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent());
|
||||
DataKey enchantmentCostNode = root.getRelative(BlacksmithSetting.ENCHANTMENT_COST.getPath());
|
||||
for (Enchantment enchantment : enchantmentCosts.keySet()) {
|
||||
enchantmentCostNode.setRaw(unNormalizeName(enchantment.getKey().getKey()), enchantmentCosts.get(enchantment));
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
package net.knarcraft.blacksmith.config.scrapper;
|
||||
|
||||
import net.knarcraft.blacksmith.config.GlobalSetting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Settings which are the same for every scrapper
|
||||
*/
|
||||
public enum GlobalScrapperSetting implements GlobalSetting {
|
||||
|
||||
/**
|
||||
* Whether to display exact time in minutes and seconds when displaying a remaining cool-down
|
||||
*/
|
||||
SHOW_EXACT_TIME("scrapper.global.showExactTime", SettingValueType.BOOLEAN, "false",
|
||||
"showExactTime"),
|
||||
|
||||
/**
|
||||
* Whether to give experience back when salvaging an enchanted item
|
||||
*/
|
||||
GIVE_EXPERIENCE("scrapper.global.giveExperience", SettingValueType.BOOLEAN, "true",
|
||||
"giveExperience"),
|
||||
;
|
||||
|
||||
private final String path;
|
||||
private final String parent;
|
||||
private final String commandName;
|
||||
private final Object value;
|
||||
private final SettingValueType valueType;
|
||||
|
||||
/**
|
||||
* Instantiates a new setting
|
||||
*
|
||||
* @param path <p>The full config path for this setting</p>
|
||||
* @param valueType <p>The type of value used by this setting</p>
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
*/
|
||||
GlobalScrapperSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.commandName = commandName;
|
||||
this.valueType = valueType;
|
||||
String[] pathParts = path.split("\\.");
|
||||
this.parent = String.join(".", Arrays.copyOfRange(pathParts, 0, pathParts.length - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Object getDefaultValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getCommandName() {
|
||||
return commandName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SettingValueType getValueType() {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
}
|
@ -4,16 +4,16 @@ import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.config.Settings;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GlobalScrapperSettings {
|
||||
public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
|
||||
|
||||
private final Map<ScrapperNPCSetting, Object> defaultNPCSettings = new HashMap<>();
|
||||
private final Map<GlobalScrapperSetting, Object> globalSettings = new HashMap<>();
|
||||
private final Map<ScrapperSetting, Object> settings = new HashMap<>();
|
||||
|
||||
private final YamlStorage defaultConfig;
|
||||
|
||||
@ -37,14 +37,10 @@ public class GlobalScrapperSettings {
|
||||
DataKey root = defaultConfig.getKey("");
|
||||
|
||||
//Just in case, clear existing values
|
||||
defaultNPCSettings.clear();
|
||||
globalSettings.clear();
|
||||
|
||||
//Load/Save NPC default settings
|
||||
loadDefaultNPCSettings(root);
|
||||
settings.clear();
|
||||
|
||||
//Load/Save global settings
|
||||
loadGlobalSettings(root);
|
||||
loadSettings(root);
|
||||
|
||||
//Save any modified values to disk
|
||||
defaultConfig.save();
|
||||
@ -53,27 +49,16 @@ public class GlobalScrapperSettings {
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param globalScrapperSetting <p>The global setting to change</p>
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
* @param scrapperSetting <p>The default NPC setting to change</p>
|
||||
* @param newValue <p>The new value for the setting</p>
|
||||
*/
|
||||
public void changeValue(GlobalScrapperSetting globalScrapperSetting, Object newValue) {
|
||||
globalSettings.put(globalScrapperSetting, newValue);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param scrapperNPCSetting <p>The default NPC setting to change</p>
|
||||
* @param newValue <p>The new value for the setting</p>
|
||||
*/
|
||||
public void changeValue(ScrapperNPCSetting scrapperNPCSetting, Object newValue) {
|
||||
if (scrapperNPCSetting.getValueType() == SettingValueType.STRING_LIST ||
|
||||
scrapperNPCSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
|
||||
public void changeValue(ScrapperSetting scrapperSetting, Object newValue) {
|
||||
if (scrapperSetting.getValueType() == SettingValueType.STRING_LIST ||
|
||||
scrapperSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
|
||||
//Workaround to make sure it's treated as the correct type
|
||||
defaultNPCSettings.put(scrapperNPCSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||
settings.put(scrapperSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
|
||||
} else {
|
||||
defaultNPCSettings.put(scrapperNPCSetting, newValue);
|
||||
settings.put(scrapperSetting, newValue);
|
||||
}
|
||||
save();
|
||||
}
|
||||
@ -81,21 +66,11 @@ public class GlobalScrapperSettings {
|
||||
/**
|
||||
* Gets the current raw value of the given global setting
|
||||
*
|
||||
* @param globalBlacksmithSetting <p>The setting to get</p>
|
||||
* @param scrapperSetting <p>The setting to get</p>
|
||||
* @return <p>The current raw setting value</p>
|
||||
*/
|
||||
public Object getRawValue(GlobalScrapperSetting globalBlacksmithSetting) {
|
||||
return globalSettings.get(globalBlacksmithSetting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current raw value of the given default NPC setting
|
||||
*
|
||||
* @param scrapperNPCSetting <p>The setting to get</p>
|
||||
* @return <p>The current raw setting value</p>
|
||||
*/
|
||||
public Object getRawValue(ScrapperNPCSetting scrapperNPCSetting) {
|
||||
return defaultNPCSettings.get(scrapperNPCSetting);
|
||||
public Object getRawValue(ScrapperSetting scrapperSetting) {
|
||||
return settings.get(scrapperSetting);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,8 +78,8 @@ public class GlobalScrapperSettings {
|
||||
*
|
||||
* @return <p>The current value of the default NPC settings</p>
|
||||
*/
|
||||
public Map<ScrapperNPCSetting, Object> getDefaultNPCSettings() {
|
||||
return new HashMap<>(this.defaultNPCSettings);
|
||||
public Map<ScrapperSetting, Object> getDefaultNPCSettings() {
|
||||
return new HashMap<>(this.settings);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,7 +88,7 @@ public class GlobalScrapperSettings {
|
||||
* @return <p>Whether to show exact time</p>
|
||||
*/
|
||||
public boolean getShowExactTime() {
|
||||
return asBoolean(GlobalScrapperSetting.SHOW_EXACT_TIME);
|
||||
return asBoolean(ScrapperSetting.SHOW_EXACT_TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,7 +99,7 @@ public class GlobalScrapperSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
public boolean asBoolean(GlobalScrapperSetting setting) {
|
||||
public boolean asBoolean(ScrapperSetting setting) {
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
@ -136,7 +111,7 @@ public class GlobalScrapperSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a double</p>
|
||||
*/
|
||||
public double asDouble(GlobalScrapperSetting setting) {
|
||||
public double asDouble(ScrapperSetting setting) {
|
||||
return ConfigHelper.asDouble(getValue(setting));
|
||||
}
|
||||
|
||||
@ -146,8 +121,8 @@ public class GlobalScrapperSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value</p>
|
||||
*/
|
||||
private Object getValue(GlobalScrapperSetting setting) {
|
||||
Object value = globalSettings.get(setting);
|
||||
private Object getValue(ScrapperSetting setting) {
|
||||
Object value = settings.get(setting);
|
||||
//If not set in config.yml, use the default value from the enum
|
||||
if (value == null) {
|
||||
value = setting.getDefaultValue();
|
||||
@ -160,31 +135,14 @@ public class GlobalScrapperSettings {
|
||||
*
|
||||
* @param root <p>The root node of all global settings</p>
|
||||
*/
|
||||
private void loadGlobalSettings(DataKey root) {
|
||||
for (GlobalScrapperSetting globalScrapperSetting : GlobalScrapperSetting.values()) {
|
||||
if (!root.keyExists(globalScrapperSetting.getPath())) {
|
||||
private void loadSettings(DataKey root) {
|
||||
for (ScrapperSetting setting : ScrapperSetting.values()) {
|
||||
if (!root.keyExists(setting.getChildPath())) {
|
||||
//If the setting does not exist in the config file, add it
|
||||
root.setRaw(globalScrapperSetting.getPath(), globalScrapperSetting.getDefaultValue());
|
||||
root.setRaw(setting.getChildPath(), setting.getDefaultValue());
|
||||
} else {
|
||||
//Set the setting to the value found in the path
|
||||
globalSettings.put(globalScrapperSetting, root.getRaw(globalScrapperSetting.getPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all default NPC settings
|
||||
*
|
||||
* @param root <p>The root node of all default NPC settings</p>
|
||||
*/
|
||||
private void loadDefaultNPCSettings(DataKey root) {
|
||||
for (ScrapperNPCSetting setting : ScrapperNPCSetting.values()) {
|
||||
if (!root.keyExists(setting.getPath())) {
|
||||
//If the setting does not exist in the config file, add it
|
||||
root.setRaw(setting.getPath(), setting.getDefaultValue());
|
||||
} else {
|
||||
//Set the setting to the value found in the path
|
||||
defaultNPCSettings.put(setting, root.getRaw(setting.getPath()));
|
||||
settings.put(setting, root.getRaw(setting.getChildPath()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -194,14 +152,9 @@ public class GlobalScrapperSettings {
|
||||
*/
|
||||
private void save() {
|
||||
DataKey root = defaultConfig.getKey("");
|
||||
//Save all default NPC settings
|
||||
for (ScrapperNPCSetting setting : ScrapperNPCSetting.values()) {
|
||||
root.setRaw(setting.getPath(), defaultNPCSettings.get(setting));
|
||||
}
|
||||
|
||||
//Save all normal global settings
|
||||
for (GlobalScrapperSetting globalBlacksmithSetting : GlobalScrapperSetting.values()) {
|
||||
root.setRaw(globalBlacksmithSetting.getPath(), globalSettings.get(globalBlacksmithSetting));
|
||||
//Save all default settings
|
||||
for (ScrapperSetting setting : ScrapperSetting.values()) {
|
||||
root.setRaw(setting.getPath(), settings.get(setting));
|
||||
}
|
||||
|
||||
//Perform the actual save to disk
|
||||
|
@ -2,17 +2,15 @@ package net.knarcraft.blacksmith.config.scrapper;
|
||||
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import net.knarcraft.blacksmith.config.SmithPreset;
|
||||
import net.knarcraft.blacksmith.config.Settings;
|
||||
import net.knarcraft.blacksmith.config.TraitSettings;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ScrapperNPCSettings implements TraitSettings {
|
||||
private final Map<ScrapperNPCSetting, Object> currentValues = new HashMap<>();
|
||||
public class ScrapperNPCSettings implements TraitSettings, Settings<ScrapperSetting> {
|
||||
private final Map<ScrapperSetting, Object> currentValues = new HashMap<>();
|
||||
private final GlobalScrapperSettings globalScrapperSettings;
|
||||
|
||||
/**
|
||||
@ -30,7 +28,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @param key <p>The data key to load variables from</p>
|
||||
*/
|
||||
public void loadVariables(DataKey key) {
|
||||
for (ScrapperNPCSetting setting : ScrapperNPCSetting.values()) {
|
||||
for (ScrapperSetting setting : ScrapperSetting.values()) {
|
||||
if (key.keyExists(setting.getChildPath())) {
|
||||
currentValues.put(setting, key.getRaw(setting.getChildPath()));
|
||||
}
|
||||
@ -43,7 +41,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @param key <p>The data key to save variables to</p>
|
||||
*/
|
||||
public void saveVariables(DataKey key) {
|
||||
for (ScrapperNPCSetting setting : ScrapperNPCSetting.values()) {
|
||||
for (ScrapperSetting setting : ScrapperSetting.values()) {
|
||||
key.setRaw(setting.getChildPath(), currentValues.get(setting));
|
||||
}
|
||||
}
|
||||
@ -54,7 +52,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @param setting <p>The setting to change</p>
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
*/
|
||||
public void changeSetting(ScrapperNPCSetting setting, Object newValue) {
|
||||
public void changeValue(ScrapperSetting setting, 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
|
||||
@ -70,23 +68,23 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value of the setting</p>
|
||||
*/
|
||||
public Object getRawValue(ScrapperNPCSetting setting) {
|
||||
public Object getRawValue(ScrapperSetting setting) {
|
||||
return currentValues.get(setting);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBusyWithPlayerMessage() {
|
||||
return asString(ScrapperNPCSetting.BUSY_WITH_PLAYER_MESSAGE);
|
||||
return asString(ScrapperSetting.BUSY_WITH_PLAYER_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBusyWorkingMessage() {
|
||||
return asString(ScrapperNPCSetting.BUSY_WITH_SALVAGE_MESSAGE);
|
||||
return asString(ScrapperSetting.BUSY_WITH_SALVAGE_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStartWorkingMessage() {
|
||||
return asString(ScrapperNPCSetting.START_SALVAGE_MESSAGE);
|
||||
return asString(ScrapperSetting.START_SALVAGE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,19 +93,19 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @return <p>The reforge success message</p>
|
||||
*/
|
||||
public String getSuccessMessage() {
|
||||
return asString(ScrapperNPCSetting.SUCCESS_SALVAGE_MESSAGE);
|
||||
return asString(ScrapperSetting.SUCCESS_SALVAGE_MESSAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCoolDownUnexpiredMessage() {
|
||||
return asString(ScrapperNPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
|
||||
return asString(ScrapperSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* The message displayed if a player presents a different item after seeing the price to salvage an item
|
||||
*/
|
||||
public String getItemChangedMessage() {
|
||||
return asString(ScrapperNPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
|
||||
return asString(ScrapperSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,7 +114,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @return <p>The minimum salvage delay</p>
|
||||
*/
|
||||
public int getMinSalvageDelay() {
|
||||
return asInt(ScrapperNPCSetting.MIN_SALVAGE_DELAY);
|
||||
return asInt(ScrapperSetting.MIN_SALVAGE_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +123,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @return <p>The maximum salvage delay</p>
|
||||
*/
|
||||
public int getMaxSalvageDelay() {
|
||||
return asInt(ScrapperNPCSetting.MAX_SALVAGE_DELAY);
|
||||
return asInt(ScrapperSetting.MAX_SALVAGE_DELAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +132,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @return <p>The salvage cool-down</p>
|
||||
*/
|
||||
public int getSalvageCoolDown() {
|
||||
return asInt(ScrapperNPCSetting.SALVAGE_COOL_DOWN);
|
||||
return asInt(ScrapperSetting.SALVAGE_COOL_DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,12 +141,12 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @return <p>Whether to drop reforged items on the ground</p>
|
||||
*/
|
||||
public boolean getDropItem() {
|
||||
return asBoolean(ScrapperNPCSetting.DROP_ITEM);
|
||||
return asBoolean(ScrapperSetting.DROP_ITEM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDisableCoolDown() {
|
||||
return asInt(ScrapperNPCSetting.SALVAGE_COOL_DOWN) <= 0;
|
||||
return asInt(ScrapperSetting.SALVAGE_COOL_DOWN) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,7 +155,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @return <p>Whether to disable the reforge delay</p>
|
||||
*/
|
||||
public boolean getDisableDelay() {
|
||||
return asInt(ScrapperNPCSetting.MAX_SALVAGE_DELAY) <= 0;
|
||||
return asInt(ScrapperSetting.MAX_SALVAGE_DELAY) <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,7 +166,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @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(ScrapperNPCSetting setting) {
|
||||
private int asInt(ScrapperSetting setting) {
|
||||
return ConfigHelper.asInt(getValue(setting));
|
||||
}
|
||||
|
||||
@ -178,7 +176,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @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(ScrapperNPCSetting setting) {
|
||||
private String asString(ScrapperSetting setting) {
|
||||
return getValue(setting).toString();
|
||||
}
|
||||
|
||||
@ -188,7 +186,7 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
private boolean asBoolean(ScrapperNPCSetting setting) {
|
||||
private boolean asBoolean(ScrapperSetting setting) {
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
@ -198,11 +196,11 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
* @param setting <p>The setting to get the value of</p>
|
||||
* @return <p>The current value</p>
|
||||
*/
|
||||
private Object getValue(ScrapperNPCSetting setting) {
|
||||
private Object getValue(ScrapperSetting setting) {
|
||||
Object value = currentValues.get(setting);
|
||||
//If not set, use the default value from the config.yml file
|
||||
if (value == null) {
|
||||
Map<ScrapperNPCSetting, Object> defaultNPCSettings = globalScrapperSettings.getDefaultNPCSettings();
|
||||
Map<ScrapperSetting, Object> defaultNPCSettings = globalScrapperSettings.getDefaultNPCSettings();
|
||||
if (defaultNPCSettings.containsKey(setting)) {
|
||||
value = defaultNPCSettings.get(setting);
|
||||
}
|
||||
@ -214,26 +212,4 @@ public class ScrapperNPCSettings implements TraitSettings {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces placeholders in the given reforge-able value
|
||||
*
|
||||
* @param stringList <p>The value specified by a user</p>
|
||||
* @return <p>The value with placeholders replaced</p>
|
||||
*/
|
||||
private static List<String> replaceReforgeAblePresets(List<String> stringList) {
|
||||
List<String> newStrings = new ArrayList<>();
|
||||
for (String item : stringList) {
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
String replaced = SmithPreset.replacePreset(item);
|
||||
if (!replaced.equals(item)) {
|
||||
newStrings.addAll(List.of(replaced.split(",")));
|
||||
} else {
|
||||
newStrings.add(item);
|
||||
}
|
||||
}
|
||||
return newStrings;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,42 +1,49 @@
|
||||
package net.knarcraft.blacksmith.config.scrapper;
|
||||
|
||||
import net.knarcraft.blacksmith.config.NPCSetting;
|
||||
import net.knarcraft.blacksmith.config.Setting;
|
||||
import net.knarcraft.blacksmith.config.SettingValueType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum ScrapperNPCSetting implements NPCSetting {
|
||||
public enum ScrapperSetting implements Setting {
|
||||
|
||||
/**
|
||||
* The setting for whether the NPC should drop an item to the ground when finished
|
||||
*
|
||||
* <p>If set to false, the item will be directly put in the player's inventory instead</p>
|
||||
*/
|
||||
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem"),
|
||||
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "dropItem",
|
||||
true, false),
|
||||
|
||||
/**
|
||||
* The chance of a scrapper returning no salvage, regardless of item condition
|
||||
*/
|
||||
FAIL_SALVAGE_CHANCE("failSalvageChance", SettingValueType.POSITIVE_DOUBLE, 0, "failSalvageChance"),
|
||||
FAIL_SALVAGE_CHANCE("failSalvageChance", SettingValueType.POSITIVE_DOUBLE, 0,
|
||||
"failSalvageChance", true, false),
|
||||
|
||||
/**
|
||||
* The setting for which items a scrapper is able to salvage
|
||||
*/
|
||||
SALVAGE_ABLE_ITEMS("salvageAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "salvageAbleItems"),
|
||||
SALVAGE_ABLE_ITEMS("salvageAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "",
|
||||
"salvageAbleItems", true, false),
|
||||
|
||||
/**
|
||||
* The maximum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MAX_SALVAGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"),
|
||||
MAX_SALVAGE_DELAY("delaysInSeconds.maximum", SettingValueType.POSITIVE_INTEGER, 30,
|
||||
"maxReforgeDelay", true, false),
|
||||
|
||||
/**
|
||||
* The minimum amount of seconds a player may need to wait for the reforging to finish
|
||||
*/
|
||||
MIN_SALVAGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"),
|
||||
MIN_SALVAGE_DELAY("delaysInSeconds.minimum", SettingValueType.POSITIVE_INTEGER, 5,
|
||||
"minReforgeDelay", true, false),
|
||||
|
||||
/**
|
||||
* The setting for number of seconds a player has to wait between each usage of the blacksmith
|
||||
*/
|
||||
SALVAGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"),
|
||||
SALVAGE_COOL_DOWN("delaysInSeconds.reforgeCoolDown", SettingValueType.POSITIVE_INTEGER, 60,
|
||||
"reforgeCoolDown", true, false),
|
||||
|
||||
/*-----------
|
||||
| Messages |
|
||||
@ -46,51 +53,70 @@ public enum ScrapperNPCSetting implements NPCSetting {
|
||||
* The message displayed when the scrapper is busy with another player
|
||||
*/
|
||||
BUSY_WITH_PLAYER_MESSAGE("messages.busyPlayerMessage", SettingValueType.STRING,
|
||||
"&cI'm busy at the moment. Come back later!", "busyPlayerMessage"),
|
||||
"&cI'm busy at the moment. Come back later!", "busyPlayerMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed when the scrapper is busy salvaging the player's item
|
||||
*/
|
||||
BUSY_WITH_SALVAGE_MESSAGE("messages.busySalvageMessage", SettingValueType.STRING,
|
||||
"&cI'm working on it. Be patient! I'll finish {time}!", "busySalvageMessage"),
|
||||
"&cI'm working on it. Be patient! I'll finish {time}!", "busySalvageMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if the player needs to wait for the cool-down to expire
|
||||
*/
|
||||
COOL_DOWN_UNEXPIRED_MESSAGE("messages.coolDownUnexpiredMessage", SettingValueType.STRING,
|
||||
"&cYou've already had your chance! Give me a break! I'll be ready {time}!",
|
||||
"coolDownUnexpiredMessage"),
|
||||
"coolDownUnexpiredMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if presented with an item that cannot be salvaged by the NPC
|
||||
*/
|
||||
CANNOT_SALVAGE_MESSAGE("messages.cannotSalvageMessage", SettingValueType.STRING,
|
||||
"&cI'm unable to salvage that item", "cannotSalvageMessage"),
|
||||
"&cI'm unable to salvage that item", "cannotSalvageMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if salvaging an item would return in no items
|
||||
*/
|
||||
TOO_DAMAGED_FOR_SALVAGE_MESSAGE("messages.tooDamagedForSalvageMessage", SettingValueType.STRING,
|
||||
"&cThat item is too damaged to be salvaged into anything useful",
|
||||
"tooDamagedForSalvageMessage"),
|
||||
"tooDamagedForSalvageMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if a salvage is successful
|
||||
*/
|
||||
SUCCESS_SALVAGE_MESSAGE("messages.successSalvagedMessage", SettingValueType.STRING, "&cThere you go!",
|
||||
"successSalvagedMessage"),
|
||||
"successSalvagedMessage", true, true),
|
||||
|
||||
/**
|
||||
* The message displayed if a player presents a different item after seeing the price to reforge an item
|
||||
*/
|
||||
ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("messages.itemChangedMessage", SettingValueType.STRING,
|
||||
"&cThat's not the item you wanted to reforge before!", "itemChangedMessage"),
|
||||
"&cThat's not the item you wanted to reforge before!", "itemChangedMessage",
|
||||
true, true),
|
||||
|
||||
/**
|
||||
* The message displayed when the scrapper starts salvaging an item
|
||||
*/
|
||||
START_SALVAGE_MESSAGE("messages.startSalvageMessage", SettingValueType.STRING,
|
||||
"&eOk, let's see what I can do...", "startSalvageMessage"),
|
||||
"&eOk, let's see what I can do...", "startSalvageMessage", true, true),
|
||||
|
||||
/*------------------
|
||||
| Global settings |
|
||||
------------------*/
|
||||
|
||||
/**
|
||||
* Whether to display exact time in minutes and seconds when displaying a remaining cool-down
|
||||
*/
|
||||
SHOW_EXACT_TIME("scrapper.global.showExactTime", SettingValueType.BOOLEAN, "false",
|
||||
"showExactTime", false, false),
|
||||
|
||||
/**
|
||||
* Whether to give experience back when salvaging an enchanted item
|
||||
*/
|
||||
GIVE_EXPERIENCE("scrapper.global.giveExperience", SettingValueType.BOOLEAN, "true",
|
||||
"giveExperience", false, false),
|
||||
;
|
||||
|
||||
private final String path;
|
||||
@ -98,6 +124,8 @@ public enum ScrapperNPCSetting implements NPCSetting {
|
||||
private final Object value;
|
||||
private final String commandName;
|
||||
private final SettingValueType valueType;
|
||||
private final boolean isPerNPC;
|
||||
private final boolean isMessage;
|
||||
|
||||
/**
|
||||
* Instantiates a new setting
|
||||
@ -106,13 +134,22 @@ public enum ScrapperNPCSetting implements NPCSetting {
|
||||
* @param valueType <p>The type of value used by this setting</p>
|
||||
* @param value <p>The default value of this setting</p>
|
||||
* @param commandName <p>The name of the command used to change this setting</p>
|
||||
* @param isPerNPC <p>Whether this setting is per-NPC or global</p>
|
||||
* @param isMessage <p>Whether this option is for an NPC message</p>
|
||||
*/
|
||||
ScrapperNPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = "scrapper.defaults." + path;
|
||||
ScrapperSetting(String path, SettingValueType valueType, Object value, String commandName, boolean isPerNPC,
|
||||
boolean isMessage) {
|
||||
if (isPerNPC) {
|
||||
this.path = "scrapper.defaults." + path;
|
||||
} else {
|
||||
this.path = "scrapper.global." + path;
|
||||
}
|
||||
this.value = value;
|
||||
this.valueType = valueType;
|
||||
this.childPath = path;
|
||||
this.commandName = commandName;
|
||||
this.isPerNPC = isPerNPC;
|
||||
this.isMessage = isMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,4 +177,29 @@ public enum ScrapperNPCSetting implements NPCSetting {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPerNPC() {
|
||||
return this.isPerNPC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMessage() {
|
||||
return this.isMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scrapper setting specified by the input string
|
||||
*
|
||||
* @param input <p>The input to check</p>
|
||||
* @return <p>The matching scrapper setting, or null if not found</p>
|
||||
*/
|
||||
public static @Nullable ScrapperSetting getSetting(@NotNull String input) {
|
||||
for (ScrapperSetting scrapperSetting : ScrapperSetting.values()) {
|
||||
if (input.equalsIgnoreCase(scrapperSetting.commandName)) {
|
||||
return scrapperSetting;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user