Implements netherite salvaging #24
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good

This commit is contained in:
2024-05-06 21:26:21 +02:00
parent e6047f3866
commit 1d7e8a0732
15 changed files with 430 additions and 209 deletions

View File

@ -34,7 +34,7 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
*
* @param instance <p>A reference to the blacksmith plugin</p>
*/
public GlobalScrapperSettings(BlacksmithPlugin instance) {
public GlobalScrapperSettings(@NotNull BlacksmithPlugin instance) {
this.instance = instance;
}
@ -78,7 +78,8 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
* @param scrapperSetting <p>The setting to get</p>
* @return <p>The current raw setting value</p>
*/
public @NotNull Object getRawValue(@NotNull ScrapperSetting scrapperSetting) {
@NotNull
public Object getRawValue(@NotNull ScrapperSetting scrapperSetting) {
return this.settings.get(scrapperSetting);
}
@ -87,6 +88,7 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
*
* @return <p>The current value of the default NPC settings</p>
*/
@NotNull
public Map<ScrapperSetting, Object> getDefaultNPCSettings() {
return new HashMap<>(this.settings);
}
@ -108,10 +110,22 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
* @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(ScrapperSetting setting) {
public boolean asBoolean(@NotNull ScrapperSetting setting) {
return ConfigHelper.asBoolean(getValue(setting));
}
/**
* Gets the given value as a double
*
* <p>This will throw an exception if used for a non-double setting</p>
*
* @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(@NotNull ScrapperSetting setting) {
return ConfigHelper.asDouble(getValue(setting));
}
/**
* Gets the value of a setting, using the default if not set
*
@ -173,12 +187,30 @@ public class GlobalScrapperSettings implements Settings<ScrapperSetting> {
}
/**
* Gets the cost of using a scrapper
* Gets the cost of using a scrapper to salvage an item
*
* @return <p>The cost of using a scrapper</p>
* @return <p>The cost of using a scrapper to salvage an item</p>
*/
public double getCost() {
return ConfigHelper.asDouble(getValue(ScrapperSetting.USE_COST));
public double getSalvageCost() {
return asDouble(ScrapperSetting.SALVAGE_COST);
}
/**
* Gets the cost of using a scrapper to remove armor trim
*
* @return <p>The cost of using a scrapper to remove armor trim</p>
*/
public double getArmorTrimSalvageCost() {
return asDouble(ScrapperSetting.ARMOR_TRIM_SALVAGE_COST);
}
/**
* Gets the cost of using a scrapper to remove netherite from an item
*
* @return <p>The cost of using a scrapper to remove netherite from an item</p>
*/
public double getNetheriteSalvageCost() {
return asDouble(ScrapperSetting.NETHERITE_SALVAGE_COST);
}
/**

View File

@ -151,6 +151,16 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
return asString(ScrapperSetting.COST_MESSAGE_ARMOR_TRIM);
}
/**
* Gets the message to use for displaying netherite salvage cost
*
* @return <p>The message to use for displaying netherite salvage cost</p>
*/
@NotNull
public String getNetheriteCostMessage() {
return asString(ScrapperSetting.COST_MESSAGE_NETHERITE);
}
@Override
@NotNull
public String getCoolDownUnexpiredMessage() {
@ -316,6 +326,15 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
return asBoolean(ScrapperSetting.SALVAGE_ARMOR_TRIMS);
}
/**
* Whether salvage of netherite items is enabled
*
* @return <p>True if this scrapper can salvage netherite items</p>
*/
public boolean salvageNetherite() {
return asBoolean(ScrapperSetting.SALVAGE_NETHERITE);
}
/**
* Gets the title of this scrapper NPC
*
@ -415,4 +434,14 @@ public class ScrapperNPCSettings implements TraitSettings<ScrapperSetting> {
return asString(ScrapperSetting.ARMOR_TRIM_SALVAGE_NOT_FOUND_MESSAGE);
}
/**
* Gets the message to display when explaining that this scrapper is unable to salvage netherite items
*
* @return <p>The message to display when explaining that this scrapper is unable to salvage netherite items</p>
*/
@NotNull
public String getCannotSalvageNetheriteMessage() {
return asString(ScrapperSetting.CANNOT_SALVAGE_NETHERITE_MESSAGE);
}
}

View File

@ -19,7 +19,7 @@ public enum ScrapperSetting implements Setting {
* <p>If set to false, the item will be directly put in the player's inventory instead</p>
*/
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" +
"item will drop materials resulting from salvaging on the ground, instead of putting them into the user's" +
" inventory", true, false),
/**
@ -85,6 +85,12 @@ public enum ScrapperSetting implements Setting {
*/
SALVAGE_ARMOR_TRIMS("salvageArmorTrims", SettingValueType.BOOLEAN, true,
"Whether to enable salvaging of armor trims.", true, false),
/**
* The setting for whether the NPC should allow salvaging netherite items to diamond items
*/
SALVAGE_NETHERITE("salvageNetherite", SettingValueType.BOOLEAN, true,
"Whether to enable salvaging of netherite items", true, false),
/*-----------
| Messages |
@ -164,16 +170,23 @@ public enum ScrapperSetting implements Setting {
* The message displayed when displaying the cost of salvaging the held item to the player
*/
COST_MESSAGE("costMessage", SettingValueType.STRING,
"&eIt will cost &a{cost}&e to salvage that item! {yield} Click again to salvage!",
"&eIt will cost &a{cost}&e to salvage that &a{item}&e! {yield} &eClick again to salvage!",
"The message to display when informing a player about the salvaging cost", true, true),
/**
* The message displayed when displaying the cost of salvaging the armor trim of the held item to the player
*/
COST_MESSAGE_ARMOR_TRIM("costMessageArmorTrim", SettingValueType.STRING,
"&eIt will cost &a{cost}&e to salvage that armor trim!",
"&eIt will cost &a{cost}&e to salvage that &a{item}&e's armor trim!",
"The message to display when explaining the shown item's armor trim's salvage cost", true, true),
/**
* The message displayed when displaying the cost of salvaging the netherite of the held item to the player
*/
COST_MESSAGE_NETHERITE("costMessageNetherite", SettingValueType.STRING,
"&eIt will cost &a{cost}&e to salvage that &a{item}&e into diamond!",
"The message to display when explaining the shown item's netherite salvage cost", true, true),
/**
* The message displayed when explaining that all items will be returned as salvage
*/
@ -209,21 +222,40 @@ public enum ScrapperSetting implements Setting {
"&cI'm sorry, but I don't know how to salvage that armor trim!",
"The message to display if the correct materials to return for the armor trim are unknown", true, true),
/**
* The message displayed when explaining that netherite salvage is disabled
*/
CANNOT_SALVAGE_NETHERITE_MESSAGE("cannotSalvageNetheriteMessage", SettingValueType.STRING,
"&cI'm sorry, but I'm unable to salvage netherite items!",
"The message to display when asked to salvage netherite items, and that option is disabled", true, true),
/*------------------
| Global settings |
------------------*/
/**
* The setting for the use cost of using the scrapper
* The setting for the salvage cost
*/
USE_COST("basePrice", SettingValueType.POSITIVE_DOUBLE, 0, "The cost of using a scrapper",
false, false),
SALVAGE_COST("salvagePrice", SettingValueType.POSITIVE_DOUBLE, 0,
"The cost of using a scrapper to salvage an item", false, false),
/**
* The setting for the armor trim salvage cost
*/
ARMOR_TRIM_SALVAGE_COST("armorTrimSalvagePrice", SettingValueType.POSITIVE_DOUBLE, 5,
"The cost of using the scrapper to remove armor trim", false, false),
/**
* The setting for the netherite salvage cost
*/
NETHERITE_SALVAGE_COST("netheriteSalvagePrice", SettingValueType.POSITIVE_DOUBLE, 15,
"The cost of using the scrapper to remove netherite from an item", false, false),
/**
* Whether to display exact time in minutes and seconds when displaying a remaining cool-down
*/
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 " +
"exact number of seconds and minutes remaining as part of the salvaging cool-down and salvaging delay " +
"messages, instead of just vaguely hinting at the remaining time.", false, false),
/**
@ -263,7 +295,7 @@ public enum ScrapperSetting implements Setting {
* @param isPerNPC <p>Whether this setting is per-NPC or global</p>
* @param isMessage <p>Whether this option is for an NPC message</p>
*/
ScrapperSetting(String key, SettingValueType valueType, Object value,
ScrapperSetting(@NotNull String key, @NotNull SettingValueType valueType, @NotNull Object value,
@NotNull String description, boolean isPerNPC, boolean isMessage) {
if (isPerNPC) {
if (isMessage) {
@ -289,32 +321,38 @@ public enum ScrapperSetting implements Setting {
}
@Override
public @NotNull String getPath() {
@NotNull
public String getPath() {
return this.path;
}
@Override
public @NotNull String getChildPath() {
@NotNull
public String getChildPath() {
return this.childPath;
}
@Override
public @NotNull Object getDefaultValue() {
@NotNull
public Object getDefaultValue() {
return this.value;
}
@Override
public @NotNull String getCommandName() {
@NotNull
public String getCommandName() {
return this.commandName;
}
@Override
public @NotNull SettingValueType getValueType() {
@NotNull
public SettingValueType getValueType() {
return this.valueType;
}
@Override
public @NotNull String getDescription() {
@NotNull
public String getDescription() {
return this.description;
}