Adds blacksmith title #9

This commit is contained in:
Kristian Knarvik 2022-10-14 11:28:00 +02:00
parent 4fa47349c6
commit 0c6a28d7df
4 changed files with 29 additions and 6 deletions

View File

@ -48,6 +48,14 @@ public enum NPCSetting {
*/
REFORGE_ABLE_ITEMS("reforgeAbleItems", SettingValueType.STRING_LIST, new String[]{}, "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"),
/*-----------
| Messages |
-----------*/
@ -74,7 +82,7 @@ public enum NPCSetting {
* 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<price> &eto reforge that &a<item>&e! Click again to reforge!", "costMessage"),
"&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
@ -92,7 +100,7 @@ public enum NPCSetting {
* The message displayed if the blacksmith encounters an item they cannot reforge
*/
INVALID_ITEM_MESSAGE("messages.invalidItemMessage", SettingValueType.STRING,
"&cI'm sorry, but I don't know how to reforge that!", "invalidItemMessage"),
"&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

View File

@ -251,6 +251,15 @@ public class NPCSettings {
return ConfigHelper.asBoolean(getValue(NPCSetting.DROP_ITEM));
}
/**
* Gets the title of the blacksmith, describing which items it can reforge
*
* @return <p>The title of the blacksmith</p>
*/
public String getBlacksmithTitle() {
return asString(NPCSetting.BLACKSMITH_TITLE);
}
/**
* Gets whether to disable the reforge-cool-down
*

View File

@ -5,6 +5,7 @@ import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import net.knarcraft.blacksmith.BlacksmithPlugin;
import net.knarcraft.blacksmith.config.NPCSettings;
import net.knarcraft.blacksmith.formatting.StringFormatter;
import net.knarcraft.blacksmith.manager.EconomyManager;
import net.knarcraft.blacksmith.util.ItemHelper;
import org.bukkit.Bukkit;
@ -170,7 +171,9 @@ public class BlacksmithTrait extends Trait {
//Refuse if not repairable, or if reforge-able items is set, but doesn't include the held item
List<Material> reforgeAbleItems = config.getReforgeAbleItems();
if (!isRepairable(hand) || (!reforgeAbleItems.isEmpty() && !reforgeAbleItems.contains(hand.getType()))) {
sendNPCMessage(this.npc, player, config.getInvalidItemMessage());
String invalidMessage = StringFormatter.replacePlaceholder(config.getInvalidItemMessage(),
"{title}", config.getBlacksmithTitle());
sendNPCMessage(this.npc, player, invalidMessage);
return;
}
@ -186,7 +189,7 @@ public class BlacksmithTrait extends Trait {
//Tell the player the cost of repairing the item
String cost = EconomyManager.formatCost(player);
String itemName = hand.getType().name().toLowerCase().replace('_', ' ');
sendNPCMessage(this.npc, player, config.getCostMessage().replace("<price>", cost).replace("<item>", itemName));
sendNPCMessage(this.npc, player, config.getCostMessage().replace("{cost}", cost).replace("{item}", itemName));
}
/**

View File

@ -52,6 +52,9 @@ defaults:
# The cool-down period between each reforge
reforgeCoolDown: 60
# The title describing the blacksmith's usage/speciality
blacksmithTitle: "blacksmith"
# All messages used by the NPC
messages:
# The message to display when another player is using the blacksmith
@ -64,7 +67,7 @@ defaults:
coolDownUnexpiredMessage: "&cYou've already had your chance! Give me a break!"
# The message to display when informing a player about the reforging cost
costMessage: "&eIt will cost &a<price> &eto reforge that &a<item>&e! Click again to reforge!"
costMessage: "&eIt will cost &a{cost}&e to reforge that &a{item}&e! Click again to reforge!"
# The message to display when the blacksmith fails to reforge an item
failReforgeMessage: "&cWhoops! Didn't mean to do that! Maybe next time?"
@ -73,7 +76,7 @@ defaults:
insufficientFundsMessage: "&cYou don't have enough money to reforge that item!"
# The message to display when holding an item the blacksmith is unable to reforge
invalidItemMessage: "&cI'm sorry, but I don't know how to reforge that!"
invalidItemMessage: "&cI'm sorry, but I'm a/an {title}, I don't know how to reforge that!"
# The message to display when presenting a different item than the one just evaluated
itemChangedMessage: "&cThat's not the item you wanted to reforge before!"