Implements the scrapper global edit command
Changes setting quite a bit to avoid code duplication
This commit is contained in:
@ -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