Starts on the Scrapper implementation

This commit is contained in:
2023-11-12 19:02:11 +01:00
parent 72ea5600fe
commit 3e3a35d02a
17 changed files with 697 additions and 518 deletions

View File

@ -1,214 +1,43 @@
package net.knarcraft.blacksmith.config;
/**
* An enum representing all of Blacksmith's settings
* An interface describing an NPC setting
*/
public enum NPCSetting {
/**
* 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"),
/**
* The setting for the chance of a reforging to fail
*/
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
/**
* The setting for whether failing a reforging should downgrade/remove enchantments as well
*/
FAIL_REMOVE_ENCHANTMENTS("failReforgeRemovesEnchantments", SettingValueType.BOOLEAN, false,
"failReforgeRemovesEnchantments"),
/**
* The setting for the chance of an additional enchantment being added
*/
EXTRA_ENCHANTMENT_CHANCE("extraEnchantmentChance", SettingValueType.PERCENTAGE, 5,
"extraEnchantmentChance"),
/**
* The setting for the maximum amount of enchantments that can be added to an item
*/
MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* The setting for which items the blacksmith is able to reforge
*/
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"),
/**
* The setting for the title used to display which kind of blacksmith the NPC is
*
* <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"),
/**
* 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"),
/**
* Whether to allow this blacksmith to repair anvils
*/
REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils"),
/*-----------
| Messages |
-----------*/
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* The message displayed when the blacksmith successfully finishes reforging an item
*/
SUCCESS_MESSAGE("messages.successMessage", SettingValueType.STRING,
"There you go! All better!", "successMessage"),
/**
* 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");
private final String path;
private final String childPath;
private final Object value;
private final String commandName;
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>
*/
NPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
this.path = "defaults." + path;
this.value = value;
this.valueType = valueType;
this.childPath = path;
this.commandName = commandName;
}
public interface NPCSetting {
/**
* Gets the full config path for this setting
*
* @return <p>The full config path for this setting</p>
*/
public String getPath() {
return path;
}
String getPath();
/**
* Gets the config path without the root node
*
* @return <p>The config path without the root node</p>
*/
public String getChildPath() {
return childPath;
}
String getChildPath();
/**
* Gets the value of this setting
*
* @return <p>The value of this setting</p>
*/
public Object getDefaultValue() {
return value;
}
Object getDefaultValue();
/**
* The name of the command used to change this setting
*
* @return <p>The name of this setting's command</p>
*/
public String getCommandName() {
return commandName;
}
String getCommandName();
/**
* Gets the value type for this setting
*
* @return <p>The value type for this setting</p>
*/
public SettingValueType getValueType() {
return this.valueType;
}
SettingValueType getValueType();
}

View File

@ -0,0 +1,197 @@
package net.knarcraft.blacksmith.config.blacksmith;
import net.knarcraft.blacksmith.config.NPCSetting;
import net.knarcraft.blacksmith.config.SettingValueType;
/**
* An enum representing all of Blacksmith's settings
*/
public enum BlacksmithNPCSetting implements NPCSetting {
/**
* 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"),
/**
* The setting for the chance of a reforging to fail
*/
FAIL_CHANCE("failReforgeChance", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
/**
* The setting for whether failing a reforging should downgrade/remove enchantments as well
*/
FAIL_REMOVE_ENCHANTMENTS("failReforgeRemovesEnchantments", SettingValueType.BOOLEAN, false,
"failReforgeRemovesEnchantments"),
/**
* The setting for the chance of an additional enchantment being added
*/
EXTRA_ENCHANTMENT_CHANCE("extraEnchantmentChance", SettingValueType.PERCENTAGE, 5,
"extraEnchantmentChance"),
/**
* The setting for the maximum amount of enchantments that can be added to an item
*/
MAX_ENCHANTMENTS("maxEnchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* The setting for which items the blacksmith is able to reforge
*/
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "reforgeAbleItems"),
/**
* The setting for the title used to display which kind of blacksmith the NPC is
*
* <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"),
/**
* 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"),
/**
* Whether to allow this blacksmith to repair anvils
*/
REPAIR_ANVILS("reforgeAnvils", SettingValueType.BOOLEAN, false, "reforgeAnvils"),
/*-----------
| Messages |
-----------*/
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* 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"),
/**
* The message displayed when the blacksmith successfully finishes reforging an item
*/
SUCCESS_MESSAGE("messages.successMessage", SettingValueType.STRING,
"There you go! All better!", "successMessage"),
/**
* 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");
private final String path;
private final String childPath;
private final Object value;
private final String commandName;
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>
*/
BlacksmithNPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
this.path = "defaults." + path;
this.value = value;
this.valueType = valueType;
this.childPath = path;
this.commandName = commandName;
}
@Override
public String getPath() {
return path;
}
@Override
public String getChildPath() {
return childPath;
}
@Override
public Object getDefaultValue() {
return value;
}
@Override
public String getCommandName() {
return commandName;
}
@Override
public SettingValueType getValueType() {
return this.valueType;
}
}

View File

@ -1,7 +1,9 @@
package net.knarcraft.blacksmith.config;
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.SmithPreset;
import net.knarcraft.blacksmith.util.ConfigHelper;
import net.knarcraft.blacksmith.util.InputParsingHelper;
import net.knarcraft.blacksmith.util.ItemHelper;
@ -20,18 +22,18 @@ import java.util.logging.Level;
/**
* A class which keeps track of all Blacksmith settings/config values for one NPC
*/
public class NPCSettings {
public class BlacksmithNPCSettings {
private final List<Material> reforgeAbleItems = new ArrayList<>();
private final List<Enchantment> enchantmentBlocklist = new ArrayList<>();
private final Map<NPCSetting, Object> currentValues = new HashMap<>();
private final GlobalSettings globalSettings;
private final Map<BlacksmithNPCSetting, Object> currentValues = new HashMap<>();
private final GlobalBlacksmithSettings globalBlacksmithSettings;
/**
* Instantiates a new "Settings" object
*/
public NPCSettings(GlobalSettings globalSettings) {
this.globalSettings = globalSettings;
public BlacksmithNPCSettings(GlobalBlacksmithSettings globalBlacksmithSettings) {
this.globalBlacksmithSettings = globalBlacksmithSettings;
}
/**
@ -40,7 +42,7 @@ public class NPCSettings {
* @param key <p>The data key to load variables from</p>
*/
public void loadVariables(DataKey key) {
for (NPCSetting setting : NPCSetting.values()) {
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
if (key.keyExists(setting.getChildPath())) {
currentValues.put(setting, key.getRaw(setting.getChildPath()));
}
@ -56,7 +58,7 @@ public class NPCSettings {
* @param key <p>The data key to save variables to</p>
*/
public void saveVariables(DataKey key) {
for (NPCSetting setting : NPCSetting.values()) {
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
key.setRaw(setting.getChildPath(), currentValues.get(setting));
}
}
@ -67,7 +69,7 @@ public class NPCSettings {
* @param setting <p>The setting to change</p>
* @param newValue <p>The new value of the setting</p>
*/
public void changeSetting(NPCSetting setting, Object newValue) {
public void changeSetting(BlacksmithNPCSetting 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
@ -75,10 +77,10 @@ public class NPCSettings {
} else {
currentValues.put(setting, newValue);
}
if (setting == NPCSetting.REFORGE_ABLE_ITEMS) {
if (setting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) {
updateReforgeAbleItems();
}
if (setting == NPCSetting.ENCHANTMENT_BLOCKLIST) {
if (setting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) {
updateEnchantmentBlocklist();
}
}
@ -89,7 +91,7 @@ public class NPCSettings {
* @param setting <p>The setting to get the value of</p>
* @return <p>The current value of the setting</p>
*/
public Object getRawValue(NPCSetting setting) {
public Object getRawValue(BlacksmithNPCSetting setting) {
return currentValues.get(setting);
}
@ -99,7 +101,7 @@ public class NPCSettings {
* @return <p>The busy with player message</p>
*/
public String getBusyWithPlayerMessage() {
return asString(NPCSetting.BUSY_WITH_PLAYER_MESSAGE);
return asString(BlacksmithNPCSetting.BUSY_WITH_PLAYER_MESSAGE);
}
/**
@ -108,7 +110,7 @@ public class NPCSettings {
* @return <p>The busy reforging message</p>
*/
public String getBusyReforgingMessage() {
return asString(NPCSetting.BUSY_WITH_REFORGE_MESSAGE);
return asString(BlacksmithNPCSetting.BUSY_WITH_REFORGE_MESSAGE);
}
/**
@ -117,7 +119,7 @@ public class NPCSettings {
* @return <p>The message to use for displaying item cost</p>
*/
public String getCostMessage() {
return asString(NPCSetting.COST_MESSAGE);
return asString(BlacksmithNPCSetting.COST_MESSAGE);
}
/**
@ -126,7 +128,7 @@ public class NPCSettings {
* @return <p>The invalid item message</p>
*/
public String getInvalidItemMessage() {
return asString(NPCSetting.INVALID_ITEM_MESSAGE);
return asString(BlacksmithNPCSetting.INVALID_ITEM_MESSAGE);
}
/**
@ -135,7 +137,7 @@ public class NPCSettings {
* @return <p>The not damaged message</p>
*/
public String getNotDamagedMessage() {
return asString(NPCSetting.NOT_DAMAGED_MESSAGE);
return asString(BlacksmithNPCSetting.NOT_DAMAGED_MESSAGE);
}
/**
@ -144,7 +146,7 @@ public class NPCSettings {
* @return <p>The start reforge message</p>
*/
public String getStartReforgeMessage() {
return asString(NPCSetting.START_REFORGE_MESSAGE);
return asString(BlacksmithNPCSetting.START_REFORGE_MESSAGE);
}
/**
@ -153,7 +155,7 @@ public class NPCSettings {
* @return <p>The reforge success message</p>
*/
public String getSuccessMessage() {
return asString(NPCSetting.SUCCESS_MESSAGE);
return asString(BlacksmithNPCSetting.SUCCESS_MESSAGE);
}
/**
@ -162,7 +164,7 @@ public class NPCSettings {
* @return <p>The reforge fail message</p>
*/
public String getFailMessage() {
return asString(NPCSetting.FAIL_MESSAGE);
return asString(BlacksmithNPCSetting.FAIL_MESSAGE);
}
/**
@ -171,7 +173,7 @@ public class NPCSettings {
* @return <p>The insufficient funds message</p>
*/
public String getInsufficientFundsMessage() {
return asString(NPCSetting.INSUFFICIENT_FUNDS_MESSAGE);
return asString(BlacksmithNPCSetting.INSUFFICIENT_FUNDS_MESSAGE);
}
/**
@ -180,7 +182,7 @@ public class NPCSettings {
* @return <p>The cool down unexpired message</p>
*/
public String getCoolDownUnexpiredMessage() {
return asString(NPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
return asString(BlacksmithNPCSetting.COOL_DOWN_UNEXPIRED_MESSAGE);
}
/**
@ -189,7 +191,7 @@ public class NPCSettings {
* @return <p>The item changed message</p>
*/
public String getItemChangedMessage() {
return asString(NPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
return asString(BlacksmithNPCSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE);
}
/**
@ -200,9 +202,9 @@ public class NPCSettings {
* @return <p>All items reforge-able by this NPC</p>
*/
public List<Material> getReforgeAbleItems() {
Object currentValue = currentValues.get(NPCSetting.REFORGE_ABLE_ITEMS);
Object currentValue = currentValues.get(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS);
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
return globalSettings.getReforgeAbleItems();
return globalBlacksmithSettings.getReforgeAbleItems();
} else {
return new ArrayList<>(this.reforgeAbleItems);
}
@ -214,9 +216,9 @@ public class NPCSettings {
* @return <p>The list of blocked enchantments</p>
*/
public List<Enchantment> getEnchantmentBlocklist() {
Object currentValue = currentValues.get(NPCSetting.ENCHANTMENT_BLOCKLIST);
Object currentValue = currentValues.get(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST);
if (currentValue == null || String.valueOf(currentValue).isEmpty()) {
return globalSettings.getEnchantmentBlocklist();
return globalBlacksmithSettings.getEnchantmentBlocklist();
} else {
return new ArrayList<>(this.enchantmentBlocklist);
}
@ -228,7 +230,7 @@ public class NPCSettings {
* @return <p>The minimum reforge delay</p>
*/
public int getMinReforgeDelay() {
return asInt(NPCSetting.MIN_REFORGE_DELAY);
return asInt(BlacksmithNPCSetting.MIN_REFORGE_DELAY);
}
/**
@ -237,7 +239,7 @@ public class NPCSettings {
* @return <p>The maximum reforge delay</p>
*/
public int getMaxReforgeDelay() {
return asInt(NPCSetting.MAX_REFORGE_DELAY);
return asInt(BlacksmithNPCSetting.MAX_REFORGE_DELAY);
}
/**
@ -246,7 +248,7 @@ public class NPCSettings {
* @return <p>The reforge cool-down</p>
*/
public int getReforgeCoolDown() {
return asInt(NPCSetting.REFORGE_COOL_DOWN);
return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN);
}
/**
@ -255,7 +257,7 @@ public class NPCSettings {
* @return <p>The fail chance</p>
*/
public int getFailChance() {
return asInt(NPCSetting.FAIL_CHANCE);
return asInt(BlacksmithNPCSetting.FAIL_CHANCE);
}
/**
@ -264,7 +266,7 @@ public class NPCSettings {
* @return <p>Whether enchantments should be removed</p>
*/
public boolean getFailRemovesEnchantments() {
return asBoolean(NPCSetting.FAIL_REMOVE_ENCHANTMENTS);
return asBoolean(BlacksmithNPCSetting.FAIL_REMOVE_ENCHANTMENTS);
}
/**
@ -273,7 +275,7 @@ public class NPCSettings {
* @return <p>The extra enchantment chance</p>
*/
public int getExtraEnchantmentChance() {
return asInt(NPCSetting.EXTRA_ENCHANTMENT_CHANCE);
return asInt(BlacksmithNPCSetting.EXTRA_ENCHANTMENT_CHANCE);
}
/**
@ -282,7 +284,7 @@ public class NPCSettings {
* @return <p>The maximum enchantments</p>
*/
public int getMaxEnchantments() {
return asInt(NPCSetting.MAX_ENCHANTMENTS);
return asInt(BlacksmithNPCSetting.MAX_ENCHANTMENTS);
}
/**
@ -291,7 +293,7 @@ public class NPCSettings {
* @return <p>Whether to drop reforged items on the ground</p>
*/
public boolean getDropItem() {
return asBoolean(NPCSetting.DROP_ITEM);
return asBoolean(BlacksmithNPCSetting.DROP_ITEM);
}
/**
@ -300,7 +302,7 @@ public class NPCSettings {
* @return <p>The title of the blacksmith</p>
*/
public String getBlacksmithTitle() {
return asString(NPCSetting.BLACKSMITH_TITLE);
return asString(BlacksmithNPCSetting.BLACKSMITH_TITLE);
}
/**
@ -309,7 +311,7 @@ public class NPCSettings {
* @return <p>Whether to disable the reforge-cool-down</p>
*/
public boolean getDisableCoolDown() {
return asInt(NPCSetting.REFORGE_COOL_DOWN) <= 0;
return asInt(BlacksmithNPCSetting.REFORGE_COOL_DOWN) <= 0;
}
/**
@ -318,7 +320,7 @@ public class NPCSettings {
* @return <p>Whether to disable the reforge delay</p>
*/
public boolean getDisableDelay() {
return asInt(NPCSetting.MAX_REFORGE_DELAY) <= 0;
return asInt(BlacksmithNPCSetting.MAX_REFORGE_DELAY) <= 0;
}
/**
@ -327,7 +329,7 @@ public class NPCSettings {
* @return <p>True if this blacksmith is able to repair anvils</p>
*/
public boolean getRepairAnvils() {
return asBoolean(NPCSetting.REPAIR_ANVILS);
return asBoolean(BlacksmithNPCSetting.REPAIR_ANVILS);
}
/**
@ -338,7 +340,7 @@ public class NPCSettings {
* @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(NPCSetting setting) {
private int asInt(BlacksmithNPCSetting setting) {
return ConfigHelper.asInt(getValue(setting));
}
@ -348,7 +350,7 @@ public class NPCSettings {
* @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(NPCSetting setting) {
private String asString(BlacksmithNPCSetting setting) {
return getValue(setting).toString();
}
@ -358,7 +360,7 @@ public class NPCSettings {
* @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(NPCSetting setting) {
private boolean asBoolean(BlacksmithNPCSetting setting) {
return ConfigHelper.asBoolean(getValue(setting));
}
@ -368,11 +370,11 @@ public class NPCSettings {
* @param setting <p>The setting to get the value of</p>
* @return <p>The current value</p>
*/
private Object getValue(NPCSetting setting) {
private Object getValue(BlacksmithNPCSetting setting) {
Object value = currentValues.get(setting);
//If not set, use the default value from the config.yml file
if (value == null) {
Map<NPCSetting, Object> defaultNPCSettings = globalSettings.getDefaultNPCSettings();
Map<BlacksmithNPCSetting, Object> defaultNPCSettings = globalBlacksmithSettings.getDefaultNPCSettings();
if (defaultNPCSettings.containsKey(setting)) {
value = defaultNPCSettings.get(setting);
}
@ -412,7 +414,7 @@ public class NPCSettings {
private void updateEnchantmentBlocklist() {
this.enchantmentBlocklist.clear();
this.enchantmentBlocklist.addAll(getEnchantmentBlocklist(ConfigHelper.asStringList(getValue(
NPCSetting.ENCHANTMENT_BLOCKLIST))));
BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST))));
}
/**
@ -446,7 +448,7 @@ public class NPCSettings {
private void updateReforgeAbleItems() {
this.reforgeAbleItems.clear();
this.reforgeAbleItems.addAll(getReforgeAbleItems(ConfigHelper.asStringList(getValue(
NPCSetting.REFORGE_ABLE_ITEMS))));
BlacksmithNPCSetting.REFORGE_ABLE_ITEMS))));
}
/**

View File

@ -1,8 +1,10 @@
package net.knarcraft.blacksmith.config;
package net.knarcraft.blacksmith.config.blacksmith;
import net.knarcraft.blacksmith.config.SettingValueType;
import java.util.Arrays;
public enum GlobalSetting {
public enum GlobalBlacksmithSetting {
/**
* The base price for repairing, regardless of durability
@ -65,7 +67,7 @@ public enum GlobalSetting {
* @param value <p>The default value of this setting</p>
* @param commandName <p>The name of the command used to change this setting</p>
*/
GlobalSetting(String path, SettingValueType valueType, Object value, String commandName) {
GlobalBlacksmithSetting(String path, SettingValueType valueType, Object value, String commandName) {
this.path = path;
this.value = value;
this.commandName = commandName;

View File

@ -1,8 +1,9 @@
package net.knarcraft.blacksmith.config;
package net.knarcraft.blacksmith.config.blacksmith;
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.util.ConfigHelper;
import net.knarcraft.blacksmith.util.InputParsingHelper;
import net.knarcraft.blacksmith.util.ItemHelper;
@ -19,15 +20,15 @@ import java.util.logging.Level;
/**
* A class which keeps track of all default NPC settings and all global settings
*/
public class GlobalSettings {
public class GlobalBlacksmithSettings {
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<NPCSetting, Object> defaultNPCSettings = new HashMap<>();
private final Map<BlacksmithNPCSetting, Object> defaultNPCSettings = new HashMap<>();
private final List<Material> defaultReforgeAbleMaterials = new ArrayList<>();
private final List<Enchantment> defaultEnchantmentBlocklist = new ArrayList<>();
private final Map<GlobalSetting, Object> globalSettings = new HashMap<>();
private final Map<GlobalBlacksmithSetting, Object> globalSettings = new HashMap<>();
private final YamlStorage defaultConfig;
@ -36,7 +37,7 @@ public class GlobalSettings {
*
* @param plugin <p>A reference to the blacksmith plugin</p>
*/
public GlobalSettings(BlacksmithPlugin plugin) {
public GlobalBlacksmithSettings(BlacksmithPlugin plugin) {
defaultConfig = new YamlStorage(new File(plugin.getDataFolder() + File.separator + "config.yml"),
"Blacksmith Configuration\nWarning: The values under defaults are the values set for a " +
"blacksmith upon creation. To change any values for existing NPCs, edit the citizens NPC file.");
@ -70,32 +71,32 @@ public class GlobalSettings {
/**
* Changes the value of the given setting
*
* @param globalSetting <p>The global setting to change</p>
* @param globalBlacksmithSetting <p>The global setting to change</p>
* @param newValue <p>The new value of the setting</p>
*/
public void changeValue(GlobalSetting globalSetting, Object newValue) {
globalSettings.put(globalSetting, newValue);
public void changeValue(GlobalBlacksmithSetting globalBlacksmithSetting, Object newValue) {
globalSettings.put(globalBlacksmithSetting, newValue);
save();
}
/**
* Changes the value of the given setting
*
* @param npcSetting <p>The default NPC setting to change</p>
* @param blacksmithNpcSetting <p>The default NPC setting to change</p>
* @param newValue <p>The new value for the setting</p>
*/
public void changeValue(NPCSetting npcSetting, Object newValue) {
if (npcSetting.getValueType() == SettingValueType.STRING_LIST ||
npcSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
public void changeValue(BlacksmithNPCSetting blacksmithNpcSetting, Object newValue) {
if (blacksmithNpcSetting.getValueType() == SettingValueType.STRING_LIST ||
blacksmithNpcSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) {
//Workaround to make sure it's treated as the correct type
defaultNPCSettings.put(npcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
defaultNPCSettings.put(blacksmithNpcSetting, newValue == null ? null : ConfigHelper.asStringList(newValue));
} else {
defaultNPCSettings.put(npcSetting, newValue);
defaultNPCSettings.put(blacksmithNpcSetting, newValue);
}
save();
if (npcSetting == NPCSetting.REFORGE_ABLE_ITEMS) {
if (blacksmithNpcSetting == BlacksmithNPCSetting.REFORGE_ABLE_ITEMS) {
loadReforgeAbleItems();
} else if (npcSetting == NPCSetting.ENCHANTMENT_BLOCKLIST) {
} else if (blacksmithNpcSetting == BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST) {
loadEnchantmentBlocklist();
}
}
@ -103,21 +104,21 @@ public class GlobalSettings {
/**
* Gets the current raw value of the given global setting
*
* @param globalSetting <p>The setting to get</p>
* @param globalBlacksmithSetting <p>The setting to get</p>
* @return <p>The current raw setting value</p>
*/
public Object getRawValue(GlobalSetting globalSetting) {
return globalSettings.get(globalSetting);
public Object getRawValue(GlobalBlacksmithSetting globalBlacksmithSetting) {
return globalSettings.get(globalBlacksmithSetting);
}
/**
* Gets the current raw value of the given default NPC setting
*
* @param npcSetting <p>The setting to get</p>
* @param blacksmithNpcSetting <p>The setting to get</p>
* @return <p>The current raw setting value</p>
*/
public Object getRawValue(NPCSetting npcSetting) {
return defaultNPCSettings.get(npcSetting);
public Object getRawValue(BlacksmithNPCSetting blacksmithNpcSetting) {
return defaultNPCSettings.get(blacksmithNpcSetting);
}
/**
@ -131,7 +132,7 @@ public class GlobalSettings {
if (newEnchantmentCost < 0) {
throw new IllegalArgumentException("Enchantment cost cannot be negative!");
}
globalSettings.put(GlobalSetting.ENCHANTMENT_COST, newEnchantmentCost);
globalSettings.put(GlobalBlacksmithSetting.ENCHANTMENT_COST, newEnchantmentCost);
} else {
if (newEnchantmentCost < 0) {
enchantmentCosts.put(enchantment, null);
@ -153,7 +154,7 @@ public class GlobalSettings {
if (newPrice < 0) {
throw new IllegalArgumentException("Price per durability point cannot be negative!");
}
globalSettings.put(GlobalSetting.PRICE_PER_DURABILITY_POINT, newPrice);
globalSettings.put(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT, newPrice);
} else {
//Use a negative price to unset the per-item value
if (newPrice < 0) {
@ -176,7 +177,7 @@ public class GlobalSettings {
if (newBasePrice < 0) {
throw new IllegalArgumentException("Base price cannot be negative!");
}
globalSettings.put(GlobalSetting.BASE_PRICE, newBasePrice);
globalSettings.put(GlobalBlacksmithSetting.BASE_PRICE, newBasePrice);
} else {
//Use a negative price to unset the per-item value
if (newBasePrice < 0) {
@ -193,7 +194,7 @@ public class GlobalSettings {
*
* @return <p>The current value of the default NPC settings</p>
*/
public Map<NPCSetting, Object> getDefaultNPCSettings() {
public Map<BlacksmithNPCSetting, Object> getDefaultNPCSettings() {
return new HashMap<>(this.defaultNPCSettings);
}
@ -206,7 +207,7 @@ public class GlobalSettings {
* @return <p>Whether to use natural cost</p>
*/
public boolean getUseNaturalCost() {
return asBoolean(GlobalSetting.NATURAL_COST);
return asBoolean(GlobalBlacksmithSetting.NATURAL_COST);
}
/**
@ -215,7 +216,7 @@ public class GlobalSettings {
* @return <p>Whether to show exact time</p>
*/
public boolean getShowExactTime() {
return asBoolean(GlobalSetting.SHOW_EXACT_TIME);
return asBoolean(GlobalBlacksmithSetting.SHOW_EXACT_TIME);
}
/**
@ -228,7 +229,7 @@ public class GlobalSettings {
if (materialBasePrices.containsKey(material) && materialBasePrices.get(material) != null) {
return materialBasePrices.get(material);
} else {
return asDouble(GlobalSetting.BASE_PRICE);
return asDouble(GlobalBlacksmithSetting.BASE_PRICE);
}
}
@ -243,7 +244,7 @@ public class GlobalSettings {
materialPricePerDurabilityPoints.get(material) != null) {
return materialPricePerDurabilityPoints.get(material);
} else {
return asDouble(GlobalSetting.PRICE_PER_DURABILITY_POINT);
return asDouble(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT);
}
}
@ -257,7 +258,7 @@ public class GlobalSettings {
if (enchantmentCosts.containsKey(enchantment) && enchantmentCosts.get(enchantment) != null) {
return enchantmentCosts.get(enchantment);
} else {
return asDouble(GlobalSetting.ENCHANTMENT_COST);
return asDouble(GlobalBlacksmithSetting.ENCHANTMENT_COST);
}
}
@ -287,9 +288,9 @@ public class GlobalSettings {
*/
public double getAnvilCost(Material material) {
if (material == Material.CHIPPED_ANVIL) {
return asDouble(GlobalSetting.ANVIL_CHIPPED_COST);
return asDouble(GlobalBlacksmithSetting.ANVIL_CHIPPED_COST);
} else if (material == Material.DAMAGED_ANVIL) {
return asDouble(GlobalSetting.ANVIL_DAMAGED_COST);
return asDouble(GlobalBlacksmithSetting.ANVIL_DAMAGED_COST);
} else {
throw new IllegalArgumentException("An unexpected item was encountered!");
}
@ -303,7 +304,7 @@ public class GlobalSettings {
* @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(GlobalSetting setting) {
public boolean asBoolean(GlobalBlacksmithSetting setting) {
return ConfigHelper.asBoolean(getValue(setting));
}
@ -315,7 +316,7 @@ public class GlobalSettings {
* @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(GlobalSetting setting) {
public double asDouble(GlobalBlacksmithSetting setting) {
return ConfigHelper.asDouble(getValue(setting));
}
@ -325,7 +326,7 @@ public class GlobalSettings {
* @param setting <p>The setting to get the value of</p>
* @return <p>The current value</p>
*/
private Object getValue(GlobalSetting setting) {
private Object getValue(GlobalBlacksmithSetting setting) {
Object value = globalSettings.get(setting);
//If not set in config.yml, use the default value from the enum
if (value == null) {
@ -340,13 +341,13 @@ public class GlobalSettings {
* @param root <p>The root node of all global settings</p>
*/
private void loadGlobalSettings(DataKey root) {
for (GlobalSetting globalSetting : GlobalSetting.values()) {
if (!root.keyExists(globalSetting.getPath())) {
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
if (!root.keyExists(globalBlacksmithSetting.getPath())) {
//If the setting does not exist in the config file, add it
root.setRaw(globalSetting.getPath(), globalSetting.getDefaultValue());
root.setRaw(globalBlacksmithSetting.getPath(), globalBlacksmithSetting.getDefaultValue());
} else {
//Set the setting to the value found in the path
globalSettings.put(globalSetting, root.getRaw(globalSetting.getPath()));
globalSettings.put(globalBlacksmithSetting, root.getRaw(globalBlacksmithSetting.getPath()));
}
}
@ -357,7 +358,7 @@ public class GlobalSettings {
loadPricesPerDurabilityPoint(root);
//Load all enchantment prices
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent());
Map<String, String> relevantKeys = getRelevantKeys(enchantmentCostNode);
for (String key : relevantKeys.keySet()) {
String enchantmentName = relevantKeys.get(key);
@ -372,7 +373,7 @@ public class GlobalSettings {
* @param root <p>The configuration root node to search from</p>
*/
private void loadPricesPerDurabilityPoint(DataKey root) {
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent());
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent());
Map<String, String> relevantKeys = getRelevantKeys(basePerDurabilityPriceNode);
for (String key : relevantKeys.keySet()) {
@ -394,7 +395,7 @@ public class GlobalSettings {
* @param root <p>The configuration root node to search from</p>
*/
private void loadBasePrices(DataKey root) {
DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent());
DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent());
Map<String, String> relevantKeys = getRelevantKeys(basePriceNode);
for (String key : relevantKeys.keySet()) {
@ -479,7 +480,7 @@ public class GlobalSettings {
* @param root <p>The root node of all default NPC settings</p>
*/
private void loadDefaultNPCSettings(DataKey root) {
for (NPCSetting setting : NPCSetting.values()) {
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());
@ -497,8 +498,8 @@ public class GlobalSettings {
*/
private void loadReforgeAbleItems() {
defaultReforgeAbleMaterials.clear();
defaultReforgeAbleMaterials.addAll(NPCSettings.getReforgeAbleItems(ConfigHelper.asStringList(
defaultNPCSettings.get(NPCSetting.REFORGE_ABLE_ITEMS))));
defaultReforgeAbleMaterials.addAll(BlacksmithNPCSettings.getReforgeAbleItems(ConfigHelper.asStringList(
defaultNPCSettings.get(BlacksmithNPCSetting.REFORGE_ABLE_ITEMS))));
}
/**
@ -506,8 +507,8 @@ public class GlobalSettings {
*/
private void loadEnchantmentBlocklist() {
defaultEnchantmentBlocklist.clear();
defaultEnchantmentBlocklist.addAll(NPCSettings.getEnchantmentBlocklist(ConfigHelper.asStringList(
defaultNPCSettings.get(NPCSetting.ENCHANTMENT_BLOCKLIST))));
defaultEnchantmentBlocklist.addAll(BlacksmithNPCSettings.getEnchantmentBlocklist(ConfigHelper.asStringList(
defaultNPCSettings.get(BlacksmithNPCSetting.ENCHANTMENT_BLOCKLIST))));
}
/**
@ -516,29 +517,29 @@ public class GlobalSettings {
private void save() {
DataKey root = defaultConfig.getKey("");
//Save all default NPC settings
for (NPCSetting setting : NPCSetting.values()) {
for (BlacksmithNPCSetting setting : BlacksmithNPCSetting.values()) {
root.setRaw(setting.getPath(), defaultNPCSettings.get(setting));
}
//Save all normal global settings
for (GlobalSetting globalSetting : GlobalSetting.values()) {
root.setRaw(globalSetting.getPath(), globalSettings.get(globalSetting));
for (GlobalBlacksmithSetting globalBlacksmithSetting : GlobalBlacksmithSetting.values()) {
root.setRaw(globalBlacksmithSetting.getPath(), globalSettings.get(globalBlacksmithSetting));
}
//Save all base prices
DataKey basePriceNode = root.getRelative(GlobalSetting.BASE_PRICE.getParent());
DataKey basePriceNode = root.getRelative(GlobalBlacksmithSetting.BASE_PRICE.getParent());
for (Material material : materialBasePrices.keySet()) {
basePriceNode.setRaw(unNormalizeName(material.name()), materialBasePrices.get(material));
}
//Save all per-durability-point prices
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalSetting.PRICE_PER_DURABILITY_POINT.getParent());
DataKey basePerDurabilityPriceNode = root.getRelative(GlobalBlacksmithSetting.PRICE_PER_DURABILITY_POINT.getParent());
for (Material material : materialPricePerDurabilityPoints.keySet()) {
basePerDurabilityPriceNode.setRaw(unNormalizeName(material.name()), materialPricePerDurabilityPoints.get(material));
}
//Load all enchantment prices
DataKey enchantmentCostNode = root.getRelative(GlobalSetting.ENCHANTMENT_COST.getParent());
DataKey enchantmentCostNode = root.getRelative(GlobalBlacksmithSetting.ENCHANTMENT_COST.getParent());
for (Enchantment enchantment : enchantmentCosts.keySet()) {
enchantmentCostNode.setRaw(unNormalizeName(enchantment.getKey().getKey()), enchantmentCosts.get(enchantment));
}

View File

@ -0,0 +1,83 @@
package net.knarcraft.blacksmith.config.scrapper;
import net.knarcraft.blacksmith.config.NPCSetting;
import net.knarcraft.blacksmith.config.SettingValueType;
public enum ScrapperNPCSetting implements NPCSetting {
/**
* 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"),
/**
* The chance of a scrapper returning no salvage, regardless of item condition
*/
FAIL_SALVAGE_CHANCE("failSalvageChance", SettingValueType.POSITIVE_DOUBLE, 0, "failSalvageChance"),
/**
* The setting for which items a scrapper is able to salvage
*/
SALVAGE_ABLE_ITEMS("salvageAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "", "salvageAbleItems"),
/*-----------
| Messages |
-----------*/
/**
* 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"),
;
private final String path;
private final String childPath;
private final Object value;
private final String commandName;
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>
*/
ScrapperNPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
this.path = "defaults." + path;
this.value = value;
this.valueType = valueType;
this.childPath = path;
this.commandName = commandName;
}
@Override
public String getPath() {
return path;
}
@Override
public String getChildPath() {
return childPath;
}
@Override
public Object getDefaultValue() {
return value;
}
@Override
public String getCommandName() {
return commandName;
}
@Override
public SettingValueType getValueType() {
return this.valueType;
}
}

View File

@ -0,0 +1,4 @@
package net.knarcraft.blacksmith.config.scrapper;
public class ScrapperNPCSettings {
}