Splits the blacksmith command into two commands, and much more
This commit is contained in:
@ -9,7 +9,7 @@ public enum GlobalSetting {
|
||||
*
|
||||
* <p>This allows specifying a price for each item, by setting base-price.item_name.</p>
|
||||
*/
|
||||
BASE_PRICE("global.base-price.default", 10.0),
|
||||
BASE_PRICE("global.base-price.default", SettingValueType.POSITIVE_DOUBLE, 10.0, "basePrice"),
|
||||
|
||||
/**
|
||||
* The base price for each durability point
|
||||
@ -18,33 +18,39 @@ public enum GlobalSetting {
|
||||
* 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 price-per-durability-point.item_name</p>
|
||||
*/
|
||||
PRICE_PER_DURABILITY_POINT("global.price-per-durability-point.default", 0.005),
|
||||
PRICE_PER_DURABILITY_POINT("global.price-per-durability-point.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("global.enchantment-cost.default", 5),
|
||||
ENCHANTMENT_COST("global.enchantment-cost.default", SettingValueType.POSITIVE_DOUBLE, 5.0, "enchantmentCost"),
|
||||
|
||||
/**
|
||||
* Whether the cost should increase for damage taken, as opposed to increase for durability present
|
||||
*/
|
||||
NATURAL_COST("global.natural-cost", true);
|
||||
NATURAL_COST("global.natural-cost", SettingValueType.BOOLEAN, true, "useNaturalCost");
|
||||
|
||||
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 value <p>The default value of this setting</p>
|
||||
* @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>
|
||||
*/
|
||||
GlobalSetting(String path, Object value) {
|
||||
GlobalSetting(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));
|
||||
}
|
||||
@ -72,8 +78,26 @@ public enum GlobalSetting {
|
||||
*
|
||||
* @return <p>The value of this setting</p>
|
||||
*/
|
||||
Object getDefaultValue() {
|
||||
public Object getDefaultValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value type for this setting
|
||||
*
|
||||
* @return <p>The value type for this setting</p>
|
||||
*/
|
||||
public SettingValueType getValueType() {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.config;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.YamlStorage;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -33,8 +34,8 @@ public class GlobalSettings {
|
||||
*/
|
||||
public GlobalSettings(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.");
|
||||
"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.");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,6 +63,82 @@ public class GlobalSettings {
|
||||
defaultConfig.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param globalSetting <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);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the value of the given setting
|
||||
*
|
||||
* @param npcSetting <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) {
|
||||
defaultNPCSettings.put(npcSetting, newValue);
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enchantment cost for the given enchantment
|
||||
*
|
||||
* @param enchantment <p>The enchantment to set the enchantment cost for</p>
|
||||
* @param newEnchantmentCost <p>The new enchantment cost</p>
|
||||
*/
|
||||
public void setEnchantmentCost(Enchantment enchantment, double newEnchantmentCost) {
|
||||
if (newEnchantmentCost < 0) {
|
||||
throw new IllegalArgumentException("Enchantment cost cannot be negative!");
|
||||
}
|
||||
if (enchantment == null) {
|
||||
globalSettings.put(GlobalSetting.ENCHANTMENT_COST, newEnchantmentCost);
|
||||
} else {
|
||||
enchantmentCosts.put(enchantment, newEnchantmentCost);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the price per durability point for the given material
|
||||
*
|
||||
* @param material <p>The material to set the price per durability point price for</p>
|
||||
* @param newPrice <p>The new price per durability point price</p>
|
||||
*/
|
||||
public void setPricePerDurabilityPoint(Material material, double newPrice) {
|
||||
if (newPrice < 0) {
|
||||
throw new IllegalArgumentException("Price per durability point cannot be negative!");
|
||||
}
|
||||
if (material == null) {
|
||||
globalSettings.put(GlobalSetting.PRICE_PER_DURABILITY_POINT, newPrice);
|
||||
} else {
|
||||
materialPricePerDurabilityPoints.put(material, newPrice);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base price for the given material
|
||||
*
|
||||
* @param material <p>The material to set the base price for</p>
|
||||
* @param newBasePrice <p>The new base price</p>
|
||||
*/
|
||||
public void setBasePrice(Material material, double newBasePrice) {
|
||||
if (newBasePrice < 0) {
|
||||
throw new IllegalArgumentException("Base price cannot be negative!");
|
||||
}
|
||||
if (material == null) {
|
||||
globalSettings.put(GlobalSetting.BASE_PRICE, newBasePrice);
|
||||
} else {
|
||||
materialBasePrices.put(material, newBasePrice);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current value of the default NPC settings
|
||||
*
|
||||
@ -135,12 +212,7 @@ public class GlobalSettings {
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
public boolean asBoolean(GlobalSetting setting) {
|
||||
Object value = getValue(setting);
|
||||
if (value instanceof String) {
|
||||
return Boolean.parseBoolean((String) value);
|
||||
} else {
|
||||
return (Boolean) value;
|
||||
}
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,14 +224,7 @@ public class GlobalSettings {
|
||||
* @return <p>The value of the given setting as a double</p>
|
||||
*/
|
||||
public double asDouble(GlobalSetting setting) {
|
||||
Object value = getValue(setting);
|
||||
if (value instanceof String) {
|
||||
return Double.parseDouble((String) value);
|
||||
} else if (value instanceof Integer) {
|
||||
return (Integer) value;
|
||||
} else {
|
||||
return (Double) value;
|
||||
}
|
||||
return ConfigHelper.asDouble(getValue(setting));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -256,6 +321,16 @@ public class GlobalSettings {
|
||||
return relevant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a normalized material name to the format used in the config file
|
||||
*
|
||||
* @param normalizedName <p>The normalized name to un-normalize</p>
|
||||
* @return <p>The un-normalized name</p>
|
||||
*/
|
||||
private String unNormalizeName(String normalizedName) {
|
||||
return normalizedName.toLowerCase().replace("_", "-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all default NPC settings
|
||||
*
|
||||
@ -273,4 +348,41 @@ public class GlobalSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all current settings to the config file
|
||||
*/
|
||||
private void save() {
|
||||
DataKey root = defaultConfig.getKey("");
|
||||
//Save all default NPC settings
|
||||
for (NPCSetting setting : NPCSetting.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));
|
||||
}
|
||||
|
||||
//Save all base prices
|
||||
DataKey basePriceNode = root.getRelative(GlobalSetting.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());
|
||||
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());
|
||||
for (Enchantment enchantment : enchantmentCosts.keySet()) {
|
||||
enchantmentCostNode.setRaw(unNormalizeName(enchantment.getKey().toString()), enchantmentCosts.get(enchantment));
|
||||
}
|
||||
|
||||
//Perform the actual save to disk
|
||||
defaultConfig.save();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,58 +7,62 @@ import java.util.Arrays;
|
||||
*/
|
||||
public enum NPCSetting {
|
||||
|
||||
DROP_ITEM("defaults.drop-item", true, "dropItem"),
|
||||
DISABLE_COOL_DOWN("defaults.disable-cool-down", false, "disableCoolDown"),
|
||||
DISABLE_DELAY("defaults.disable-delay", false, "disableDelay"),
|
||||
FAIL_CHANCE("defaults.percent-chance-to-fail-reforge", 10, "failReforgeChance"),
|
||||
EXTRA_ENCHANTMENT_CHANCE("defaults.percent-chance-for-extra-enchantment", 5,
|
||||
DROP_ITEM("defaults.drop-item", SettingValueType.BOOLEAN, true, "dropItem"),
|
||||
DISABLE_COOL_DOWN("defaults.disable-cool-down", SettingValueType.BOOLEAN, false, "disableCoolDown"),
|
||||
DISABLE_DELAY("defaults.disable-delay", SettingValueType.BOOLEAN, false, "disableDelay"),
|
||||
FAIL_CHANCE("defaults.percent-chance-to-fail-reforge", SettingValueType.PERCENTAGE, 10, "failReforgeChance"),
|
||||
EXTRA_ENCHANTMENT_CHANCE("defaults.percent-chance-for-extra-enchantment", SettingValueType.PERCENTAGE, 5,
|
||||
"extraEnchantmentChance"),
|
||||
MAX_ENCHANTMENTS("defaults.maximum-enchantments", 3, "maxEnchantments"),
|
||||
MAX_REFORGE_DELAY("defaults.delays-in-seconds.maximum", 30, "maxReforgeDelay"),
|
||||
MIN_REFORGE_DELAY("defaults.delays-in-seconds.minimum", 5, "minReforgeDelay"),
|
||||
REFORGE_COOL_DOWN("defaults.delays-in-seconds.reforge-cool-down", 60, "reforgeCoolDown"),
|
||||
REFORGE_ABLE_ITEMS("defaults.reforge-able-items", new String[]{}, "reforgeAbleItems"),
|
||||
MAX_ENCHANTMENTS("defaults.maximum-enchantments", SettingValueType.POSITIVE_INTEGER, 3, "maxEnchantments"),
|
||||
MAX_REFORGE_DELAY("defaults.delays-in-seconds.maximum", SettingValueType.POSITIVE_INTEGER, 30, "maxReforgeDelay"),
|
||||
MIN_REFORGE_DELAY("defaults.delays-in-seconds.minimum", SettingValueType.POSITIVE_INTEGER, 5, "minReforgeDelay"),
|
||||
REFORGE_COOL_DOWN("defaults.delays-in-seconds.reforge-cool-down", SettingValueType.POSITIVE_INTEGER, 60, "reforgeCoolDown"),
|
||||
REFORGE_ABLE_ITEMS("defaults.reforge-able-items", SettingValueType.STRING_LIST, new String[]{}, "reforgeAbleItems"),
|
||||
|
||||
/*-----------
|
||||
| Messages |
|
||||
-----------*/
|
||||
BUSY_WITH_PLAYER_MESSAGE("defaults.messages.busy-with-player",
|
||||
BUSY_WITH_PLAYER_MESSAGE("defaults.messages.busy-with-player", SettingValueType.STRING,
|
||||
"§cI'm busy at the moment. Come back later!", "busyPlayerMessage"),
|
||||
BUSY_WITH_REFORGE_MESSAGE("defaults.messages.busy-with-reforge", "§cI'm working on it. Be patient!",
|
||||
BUSY_WITH_REFORGE_MESSAGE("defaults.messages.busy-with-reforge", SettingValueType.STRING, "§cI'm working on it. Be patient!",
|
||||
"busyReforgeMessage"),
|
||||
COOL_DOWN_UNEXPIRED_MESSAGE("defaults.messages.cool-down-not-expired",
|
||||
COOL_DOWN_UNEXPIRED_MESSAGE("defaults.messages.cool-down-not-expired", SettingValueType.STRING,
|
||||
"§cYou've already had your chance! Give me a break!", "coolDownUnexpiredMessage"),
|
||||
COST_MESSAGE(
|
||||
"defaults.messages.cost",
|
||||
"defaults.messages.cost", SettingValueType.STRING,
|
||||
"§eIt will cost §a<price> §eto reforge that §a<item>§e! Click again to reforge!", "costMessage"),
|
||||
FAIL_MESSAGE("defaults.messages.fail-reforge", "§cWhoops! Didn't mean to do that! Maybe next time?",
|
||||
FAIL_MESSAGE("defaults.messages.fail-reforge", SettingValueType.STRING, "§cWhoops! Didn't mean to do that! Maybe next time?",
|
||||
"failReforgeMessage"),
|
||||
INSUFFICIENT_FUNDS_MESSAGE("defaults.messages.insufficient-funds",
|
||||
INSUFFICIENT_FUNDS_MESSAGE("defaults.messages.insufficient-funds", SettingValueType.STRING,
|
||||
"§cYou don't have enough money to reforge that item!", "insufficientFundsMessage"),
|
||||
INVALID_ITEM_MESSAGE("defaults.messages.invalid-item", "§cI'm sorry, but I don't know how to reforge that!",
|
||||
"invalidItemMessage"),
|
||||
ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("defaults.messages.item-changed-during-reforge",
|
||||
INVALID_ITEM_MESSAGE("defaults.messages.invalid-item", SettingValueType.STRING,
|
||||
"§cI'm sorry, but I don't know how to reforge that!", "invalidItemMessage"),
|
||||
ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("defaults.messages.item-changed-during-reforge", SettingValueType.STRING,
|
||||
"§cThat's not the item you wanted to reforge before!", "itemChangedMessage"),
|
||||
START_REFORGE_MESSAGE("defaults.messages.start-reforge", "§eOk, let's see what I can do...",
|
||||
"startReforgeMessage"),
|
||||
SUCCESS_MESSAGE("defaults.messages.successful-reforge", "There you go! All better!", "successMessage");
|
||||
START_REFORGE_MESSAGE("defaults.messages.start-reforge", SettingValueType.STRING,
|
||||
"§eOk, let's see what I can do...", "startReforgeMessage"),
|
||||
SUCCESS_MESSAGE("defaults.messages.successful-reforge", SettingValueType.STRING,
|
||||
"There you go! All better!", "successMessage");
|
||||
|
||||
private final String path;
|
||||
private final String childPath;
|
||||
private final Object value;
|
||||
private final String commandName;
|
||||
private final String nodeName;
|
||||
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, Object value, String commandName) {
|
||||
NPCSetting(String path, SettingValueType valueType, Object value, String commandName) {
|
||||
this.path = path;
|
||||
this.value = value;
|
||||
this.valueType = valueType;
|
||||
String[] pathParts = path.split("\\.");
|
||||
this.childPath = String.join(".", Arrays.copyOfRange(pathParts, 1, pathParts.length));
|
||||
this.commandName = commandName;
|
||||
@ -114,4 +118,13 @@ public enum NPCSetting {
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value type for this setting
|
||||
*
|
||||
* @return <p>The value type for this setting</p>
|
||||
*/
|
||||
public SettingValueType getValueType() {
|
||||
return this.valueType;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.config;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.knarcraft.blacksmith.BlacksmithPlugin;
|
||||
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -61,6 +62,9 @@ public class NPCSettings {
|
||||
* @param newValue <p>The new value of the setting</p>
|
||||
*/
|
||||
public void changeSetting(NPCSetting setting, Object newValue) {
|
||||
if (setting == NPCSetting.REFORGE_ABLE_ITEMS) {
|
||||
newValue = replaceReforgeAblePlaceholders(newValue);
|
||||
}
|
||||
currentValues.put(setting, newValue);
|
||||
}
|
||||
|
||||
@ -265,12 +269,7 @@ public class NPCSettings {
|
||||
* @return <p>The value of the given setting as a boolean</p>
|
||||
*/
|
||||
private boolean asBoolean(NPCSetting setting) {
|
||||
Object value = getValue(setting);
|
||||
if (value instanceof String) {
|
||||
return Boolean.parseBoolean((String) value);
|
||||
} else {
|
||||
return (Boolean) value;
|
||||
}
|
||||
return ConfigHelper.asBoolean(getValue(setting));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -282,12 +281,7 @@ public class NPCSettings {
|
||||
* @return <p>The value of the given setting as an integer</p>
|
||||
*/
|
||||
private int asInt(NPCSetting setting) {
|
||||
Object value = getValue(setting);
|
||||
if (value instanceof String) {
|
||||
return Integer.parseInt((String) value);
|
||||
} else {
|
||||
return (Integer) value;
|
||||
}
|
||||
return ConfigHelper.asInt(getValue(setting));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -322,6 +316,31 @@ public class NPCSettings {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces placeholders in the given reforge-able value
|
||||
*
|
||||
* @param value <p>The value specified by a user</p>
|
||||
* @return <p>The value with placeholders replaced</p>
|
||||
*/
|
||||
private Object replaceReforgeAblePlaceholders(Object value) {
|
||||
if (value instanceof String string) {
|
||||
String[] list = string.split(",");
|
||||
List<String> replaced = new ArrayList<>(list.length);
|
||||
for (String item : list) {
|
||||
replaced.add(SmithPreset.replacePlaceholder(item));
|
||||
}
|
||||
return String.join(",", replaced);
|
||||
} else if (value instanceof String[] stringList) {
|
||||
List<String> replaced = new ArrayList<>(stringList.length);
|
||||
for (String item : stringList) {
|
||||
replaced.add(SmithPreset.replacePlaceholder(item));
|
||||
}
|
||||
return replaced.toArray();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected object type encountered!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the reforge-able items according to the current value of the setting
|
||||
*/
|
||||
|
@ -0,0 +1,38 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
|
||||
/**
|
||||
* A representation of all value types used by settings
|
||||
*/
|
||||
public enum SettingValueType {
|
||||
|
||||
/**
|
||||
* A double value which cannot be negative
|
||||
*/
|
||||
POSITIVE_DOUBLE,
|
||||
|
||||
/**
|
||||
* Any string (used for messages), except empty
|
||||
*/
|
||||
STRING,
|
||||
|
||||
/**
|
||||
* An integer value which cannot be negative
|
||||
*/
|
||||
POSITIVE_INTEGER,
|
||||
|
||||
/**
|
||||
* A percentage integer value (0-100 only)
|
||||
*/
|
||||
PERCENTAGE,
|
||||
|
||||
/**
|
||||
* A boolean value
|
||||
*/
|
||||
BOOLEAN,
|
||||
|
||||
/**
|
||||
* A string list (used for reforge-able items)
|
||||
*/
|
||||
STRING_LIST
|
||||
|
||||
}
|
158
src/main/java/net/knarcraft/blacksmith/config/SmithPreset.java
Normal file
158
src/main/java/net/knarcraft/blacksmith/config/SmithPreset.java
Normal file
@ -0,0 +1,158 @@
|
||||
package net.knarcraft.blacksmith.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A representation of the presets for different kinds of smiths
|
||||
*/
|
||||
public enum SmithPreset {
|
||||
|
||||
/**
|
||||
* A blacksmith capable of re-forging all swords
|
||||
*/
|
||||
SWORD_SMITH,
|
||||
|
||||
/**
|
||||
* A blacksmith capable of re-forging all weapons (including shields)
|
||||
*/
|
||||
WEAPON_SMITH,
|
||||
|
||||
/**
|
||||
* A blacksmith capable of re-forging all armor
|
||||
*/
|
||||
ARMOR_SMITH,
|
||||
|
||||
/**
|
||||
* A blacksmith capable of re-forging all tools (hoe, axe, shovel, pickaxe, flint and steel, shears, fishing rod)
|
||||
*/
|
||||
TOOL_SMITH,
|
||||
|
||||
/**
|
||||
* A blacksmith capable of re-forging all ranged weapons (bow, crossbow, trident)
|
||||
*/
|
||||
RANGED_SMITH;
|
||||
|
||||
/**
|
||||
* Replaces the given string if it's a smith type placeholder
|
||||
*
|
||||
* @param possiblePlaceholder <p>The string that might be a placeholder</p>
|
||||
* @return <p>The string, possibly with the placeholder replaced</p>
|
||||
*/
|
||||
public static String replacePlaceholder(String possiblePlaceholder) {
|
||||
for (SmithPreset smithPreset : SmithPreset.values()) {
|
||||
if (possiblePlaceholder.equalsIgnoreCase("preset:" + smithPreset.name())) {
|
||||
return String.join(",", smithPreset.getMaterialNames());
|
||||
}
|
||||
}
|
||||
return possiblePlaceholder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all materials included in this preset
|
||||
*
|
||||
* @return <p>All materials in this preset</p>
|
||||
*/
|
||||
public List<Material> getMaterials() {
|
||||
return switch (this) {
|
||||
case SWORD_SMITH -> getSwords();
|
||||
case WEAPON_SMITH -> getWeapons();
|
||||
case ARMOR_SMITH -> getArmor();
|
||||
case TOOL_SMITH -> getTools();
|
||||
case RANGED_SMITH -> getRanged();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all ranged weapon materials
|
||||
*
|
||||
* @return <p>All ranged weapon materials</p>
|
||||
*/
|
||||
private List<Material> getRanged() {
|
||||
List<Material> ranged = new ArrayList<>();
|
||||
ranged.add(Material.TRIDENT);
|
||||
ranged.add(Material.BOW);
|
||||
ranged.add(Material.CROSSBOW);
|
||||
return ranged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all tool materials
|
||||
*
|
||||
* @return <p>All tool materials</p>
|
||||
*/
|
||||
private List<Material> getTools() {
|
||||
List<Material> tools = new ArrayList<>();
|
||||
tools.addAll(getMaterialsEndingWith("_HOE"));
|
||||
tools.addAll(getMaterialsEndingWith("_SHOVEL"));
|
||||
tools.addAll(getMaterialsEndingWith("_AXE"));
|
||||
tools.addAll(getMaterialsEndingWith("_PICKAXE"));
|
||||
tools.add(Material.FLINT_AND_STEEL);
|
||||
tools.add(Material.FISHING_ROD);
|
||||
tools.add(Material.SHEARS);
|
||||
return tools;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all weapon materials
|
||||
*
|
||||
* @return <p>All weapon materials</p>
|
||||
*/
|
||||
private List<Material> getWeapons() {
|
||||
List<Material> weapons = new ArrayList<>(getSwords());
|
||||
weapons.addAll(getRanged());
|
||||
weapons.add(Material.SHIELD);
|
||||
return weapons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all sword materials
|
||||
*
|
||||
* @return <p>All sword materials</p>
|
||||
*/
|
||||
private List<Material> getSwords() {
|
||||
return getMaterialsEndingWith("_SWORD");
|
||||
}
|
||||
|
||||
private List<Material> getArmor() {
|
||||
List<Material> armor = new ArrayList<>();
|
||||
armor.addAll(getMaterialsEndingWith("HELMET"));
|
||||
armor.addAll(getMaterialsEndingWith("CHESTPLATE"));
|
||||
armor.addAll(getMaterialsEndingWith("LEGGINGS"));
|
||||
armor.addAll(getMaterialsEndingWith("BOOTS"));
|
||||
armor.add(Material.ELYTRA);
|
||||
return armor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all materials ending with the given string
|
||||
*
|
||||
* @param end <p>The string to look for</p>
|
||||
* @return <p>The resulting materials</p>
|
||||
*/
|
||||
private List<Material> getMaterialsEndingWith(String end) {
|
||||
List<Material> swords = new ArrayList<>();
|
||||
for (Material material : Material.values()) {
|
||||
if (!material.name().startsWith("LEGACY") && material.name().endsWith(end)) {
|
||||
swords.add(material);
|
||||
}
|
||||
}
|
||||
return swords;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets material names of all materials re-forge-able by this smith
|
||||
*
|
||||
* @return <p>All material names for this smith</p>
|
||||
*/
|
||||
private List<String> getMaterialNames() {
|
||||
List<String> items = new ArrayList<>();
|
||||
for (Material material : this.getMaterials()) {
|
||||
items.add(material.name().toLowerCase().replace("_", "-"));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user