272 lines
11 KiB
Java
Raw Normal View History

2023-11-12 19:02:11 +01:00
package net.knarcraft.blacksmith.config.scrapper;
import net.knarcraft.blacksmith.config.Setting;
2023-11-12 19:02:11 +01:00
import net.knarcraft.blacksmith.config.SettingValueType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
2023-11-12 19:02:11 +01:00
import java.util.ArrayList;
import java.util.List;
/**
* An enum representing all scrapper-related settings
*/
public enum ScrapperSetting implements Setting {
2023-11-12 19:02:11 +01:00
/**
* 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>
*/
2023-11-20 13:20:11 +01:00
DROP_ITEM("dropItem", SettingValueType.BOOLEAN, true, "Whether the " +
"item will drop materials resulting from scrapping on the ground, instead of putting them into the user's" +
" inventory", true, false),
2023-11-12 19:02:11 +01:00
/**
* The chance of a scrapper returning no salvage, regardless of item condition
*/
FAIL_SALVAGE_CHANCE("failSalvageChance", SettingValueType.POSITIVE_DOUBLE, 0,
2023-11-20 13:20:11 +01:00
"The chance to fail a salvage, thus destroying the item (0-100)",
true, false),
2023-11-12 19:02:11 +01:00
/**
* The setting for which items a scrapper is able to salvage
*/
SALVAGE_ABLE_ITEMS("salvageAbleItems", SettingValueType.REFORGE_ABLE_ITEMS, "",
2023-11-20 13:20:11 +01:00
"The items a blacksmith is able to salvage. Setting this only " +
"allows NPCs to repair the listed items. This should be set for each individual NPC, and should not be " +
"set here, unless you want to restrict NPCs which have not been set up yet", true, false),
/**
* The maximum amount of seconds a player may need to wait for the reforging to finish
*/
2023-11-20 13:20:11 +01:00
MAX_SALVAGE_DELAY("maxSalvageWaitTimeSeconds", SettingValueType.POSITIVE_INTEGER, 30,
"The maximum time for a salvaging to finish",
true, false),
/**
* The minimum amount of seconds a player may need to wait for the reforging to finish
*/
2023-11-20 13:20:11 +01:00
MIN_SALVAGE_DELAY("minSalvageWaitTimeSeconds", SettingValueType.POSITIVE_INTEGER, 5,
"The minimum time for a salvaging to finish",
true, false),
/**
* The setting for number of seconds a player has to wait between each usage of the blacksmith
*/
2023-11-20 13:20:11 +01:00
SALVAGE_COOL_DOWN("salvageCoolDownSeconds", SettingValueType.POSITIVE_INTEGER, 60,
"The cool-down period between each salvage",
true, false),
2023-11-20 13:20:11 +01:00
/**
* The setting for the title used to display which kind of scrapper the NPC is
*
* <p>While this should be entirely configurable, values such as armor-scrapper, sword-scrapper and similar, which
* describe the scrapper's specialization, and thus the range of salvageable items, is expected.</p>
*/
SCRAPPER_TITLE("scrapperTitle", SettingValueType.STRING, "scrapper",
"The title describing the scrapper's usage/speciality", true, false),
/**
* The setting for whether the NPC should allow salvaging of any craft-able item instead of just repairable items
*/
EXTENDED_SALVAGE_ENABLED("extendedSalvageEnabled", SettingValueType.BOOLEAN, false,
"Whether to enable salvaging of non-repairable items, such as planks", true, false),
2023-11-12 19:02:11 +01:00
/*-----------
| Messages |
-----------*/
/**
* The message displayed when the scrapper is busy with another player
*/
2023-11-20 13:20:11 +01:00
BUSY_WITH_PLAYER_MESSAGE("busyPlayerMessage", SettingValueType.STRING, "&cI'm busy at the moment. Come " +
"back later!", "The message to display when another player is using the scrapper",
true, true),
/**
* The message displayed when the scrapper is busy salvaging the player's item
*/
2023-11-20 13:20:11 +01:00
BUSY_WITH_SALVAGE_MESSAGE("busySalvageMessage", SettingValueType.STRING, "&cI'm working on it. Be " +
"patient! I'll finish {time}!", "The message to display when the blacksmith is working on the " +
"salvaging", true, true),
/**
* The message displayed if the player needs to wait for the cool-down to expire
*/
2023-11-20 13:20:11 +01:00
COOL_DOWN_UNEXPIRED_MESSAGE("coolDownUnexpiredMessage", SettingValueType.STRING,
"&cYou've already had your chance! Give me a break! I'll be ready {time}!",
2023-11-20 13:20:11 +01:00
"The message to display when the blacksmith is still " +
"on a cool-down from the previous re-forging", true, true),
/**
* The message displayed if the scrapper encounters an item they cannot salvage
*/
INVALID_ITEM_MESSAGE("invalidItemMessage", SettingValueType.STRING,
"&cI'm sorry, but I'm a/an {title}, I don't know how to salvage that!",
"The message to display if the player tries to salvage" +
" an item the scrapper cannot salvage", true, true),
/**
* The message displayed if salvaging an item would return in no items
*/
2023-11-20 13:20:11 +01:00
TOO_DAMAGED_FOR_SALVAGE_MESSAGE("tooDamagedForSalvageMessage", SettingValueType.STRING,
"&cThat item is too damaged to be salvaged into anything useful", "The message to display " +
"if salvaging the player's item would result in no salvage", true, true),
/**
* The message displayed if a salvage is successful
*/
2023-11-20 13:20:11 +01:00
SUCCESS_SALVAGE_MESSAGE("successSalvagedMessage", SettingValueType.STRING, "&cThere you go!",
"The message to display when an item is successfully salvaged", true, true),
/**
* The message displayed if a salvage is unsuccessful
*/
FAIL_SALVAGE_MESSAGE("failSalvageMessage", SettingValueType.STRING, "&cWhoops! The item broke! Maybe " +
"next time?", "The message to display when a scrapper fails to salvage an item because of the " +
"fail chance.", true, true),
/**
* The message displayed if a player presents a different item after seeing the price to reforge an item
*/
2023-11-20 13:20:11 +01:00
ITEM_UNEXPECTEDLY_CHANGED_MESSAGE("itemChangedMessage", SettingValueType.STRING, "&cThat's not the item" +
" you wanted to reforge before!", "The message to display when presenting a different item than" +
" the one just evaluated", true, true),
/**
* The message displayed when the scrapper starts salvaging an item
*/
2023-11-20 13:20:11 +01:00
START_SALVAGE_MESSAGE("startSalvageMessage", SettingValueType.STRING, "&eOk, let's see what I can do...",
"The message to display once the blacksmith starts re-forging", true, true),
/*------------------
| Global settings |
------------------*/
/**
* Whether to display exact time in minutes and seconds when displaying a remaining cool-down
*/
2023-11-20 13:20:11 +01:00
SHOW_EXACT_TIME("showExactTime", SettingValueType.BOOLEAN, "false", "Exact time displays the " +
"exact number of seconds and minutes remaining as part of the scrapping cool-down and scrapping delay " +
"messages, instead of just vaguely hinting at the remaining time.", false, false),
/**
* Whether to give experience back when salvaging an enchanted item
*/
2023-11-20 13:20:11 +01:00
GIVE_EXPERIENCE("giveExperience", SettingValueType.BOOLEAN, "true", "Whether enchanted " +
"salvaged items should return some amount of exp upon salvage", false, false),
/**
* Which items are ignored when calculating salvage for a given material
*/
IGNORED_SALVAGE("ignoredSalvage", SettingValueType.STRING_LIST,
new ArrayList<>(List.of("*_SHOVEL,*_PICKAXE,*_AXE,*_HOE,*_SWORD:STICK")),
"Items ignored during salvage calculation. This follows the format: " +
"\"MATERIAL[,MATERIAL2][,MATERIAL3]:IGNORED\", so the material or materials listed will ignore " +
"the material specified after the \":\" when calculating salvage (* matches any character). This " +
"causes the player to lose some items during salvaging, but can prevent cases where a diamond " +
"pickaxe is salvaged and only sticks are returned.", false, false),
2023-11-12 19:02:11 +01:00
;
private final String path;
private final String childPath;
private final Object value;
private final String commandName;
private final SettingValueType valueType;
private final String description;
private final boolean isPerNPC;
private final boolean isMessage;
2023-11-12 19:02:11 +01:00
/**
* Instantiates a new setting
*
2023-11-20 13:20:11 +01:00
* @param key <p>The configuration key for this setting</p>
2023-11-12 19:02:11 +01:00
* @param valueType <p>The type of value used by this setting</p>
* @param value <p>The default value of this setting</p>
* @param description <p>The description describing 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>
2023-11-12 19:02:11 +01:00
*/
2023-11-20 13:20:11 +01:00
ScrapperSetting(String key, SettingValueType valueType, Object value,
@NotNull String description, boolean isPerNPC, boolean isMessage) {
if (isPerNPC) {
2023-11-20 13:20:11 +01:00
if (isMessage) {
this.path = "scrapper.defaults.messages." + key;
} else {
this.path = "scrapper.defaults." + key;
}
} else {
2023-11-20 13:20:11 +01:00
this.path = "scrapper.global." + key;
}
2023-11-12 19:02:11 +01:00
this.value = value;
this.valueType = valueType;
2023-11-20 13:20:11 +01:00
this.childPath = key;
if (key.contains(".")) {
String[] pathParts = path.split("\\.");
this.commandName = pathParts[0];
} else {
this.commandName = key;
}
this.description = description;
this.isPerNPC = isPerNPC;
this.isMessage = isMessage;
2023-11-12 19:02:11 +01:00
}
@Override
public @NotNull String getPath() {
2023-11-20 13:20:11 +01:00
return this.path;
2023-11-12 19:02:11 +01:00
}
@Override
public @NotNull String getChildPath() {
2023-11-20 13:20:11 +01:00
return this.childPath;
2023-11-12 19:02:11 +01:00
}
@Override
public @NotNull Object getDefaultValue() {
2023-11-20 13:20:11 +01:00
return this.value;
2023-11-12 19:02:11 +01:00
}
@Override
public @NotNull String getCommandName() {
2023-11-20 13:20:11 +01:00
return this.commandName;
2023-11-12 19:02:11 +01:00
}
@Override
public @NotNull SettingValueType getValueType() {
2023-11-12 19:02:11 +01:00
return this.valueType;
}
@Override
public @NotNull String getDescription() {
return this.description;
}
@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()) {
2023-11-20 13:20:11 +01:00
if (input.equalsIgnoreCase(scrapperSetting.getCommandName())) {
return scrapperSetting;
}
}
return null;
}
2023-11-12 19:02:11 +01:00
}