From 5efba6687cfc3ea9f3059466e4f4b3ee95554214 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sat, 3 Aug 2024 13:09:09 +0200 Subject: [PATCH] Adds a separate message for clicking an NPC with an empty hand --- README.md | 2 ++ .../config/blacksmith/BlacksmithNPCSettings.java | 10 ++++++++++ .../config/blacksmith/BlacksmithSetting.java | 6 ++++++ .../config/scrapper/ScrapperNPCSettings.java | 14 +++++++++++++- .../config/scrapper/ScrapperSetting.java | 6 ++++++ .../blacksmith/trait/BlacksmithTrait.java | 5 +++++ .../knarcraft/blacksmith/trait/ScrapperTrait.java | 5 +++++ src/main/resources/config.yml | 8 +++++++- 8 files changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c6ae363..e8210fe 100644 --- a/README.md +++ b/README.md @@ -230,6 +230,7 @@ All currently supported presets, and available filters for each preset: | startReforgeMessage | &eOk, let's see what I can do... | The message displayed when a blacksmith starts reforging an item. | | successMessage | There you go! All better! | The message displayed when a blacksmith successfully repairs an item. | | notDamagedMessage | &cThat item is not in need of repair | The message displayed if a player tries to reforge an item with full durability. | +| noItemMessage | Please present the item you want to reforge | The message displayed when a blacksmith is clicked with an empty hand | ### Scrapper global-only options @@ -284,6 +285,7 @@ All currently supported presets, and available filters for each preset: | cannotSalvageArmorTrimMessage | &cI'm sorry, but I'm unable to salvage armor trims! | The message displayed when telling a player that the scrapper cannot salvage items with armor trim. | | armorTrimSalvageNotFoundMessage | &cI'm sorry, but I don't know how to salvage that armor trim! | The message displayed when telling a player that the scrapper cannot find the correct items to return as armor trim salvage. This will happen if more armor trim materials are added, or the Spigot API is changed. | | cannotSalvageNetheriteMessage | &cI'm sorry, but I'm unable to salvage netherite items! | The message displayed when telling a player that the scrapper cannot salvage netherite items. | +| noItemMessage | Please present the item you want to salvage | The message displayed when a scrapper is clicked with an empty hand | ## Language customization diff --git a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java index 91ec6b3..ac68cf0 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithNPCSettings.java @@ -175,6 +175,16 @@ public class BlacksmithNPCSettings implements TraitSettings { return asString(BlacksmithSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE); } + /** + * Gets the message displayed if a player presents the blacksmith with an empty hand + * + * @return

The no item message

+ */ + @NotNull + public String getNoItemMessage() { + return asString(BlacksmithSetting.NO_ITEM_MESSAGE); + } + /** * Gets all items reforge-able by this NPC * diff --git a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java index 085e82b..46638d2 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/blacksmith/BlacksmithSetting.java @@ -186,6 +186,12 @@ public enum BlacksmithSetting implements Setting { "The message to display if a player is trying to reforge an item with full durability", true, true), + /** + * The message displayed when clicking a blacksmith with an empty hand + */ + NO_ITEM_MESSAGE("noItemMessage", SettingValueType.STRING, "Please present the item you want to reforge", + "The message to display when a blacksmith is clicked with an empty hand", true, true), + /*------------------ | Global settings | ------------------*/ diff --git a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSettings.java b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSettings.java index 436fb21..0f435c2 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSettings.java +++ b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperNPCSettings.java @@ -178,13 +178,25 @@ public class ScrapperNPCSettings implements TraitSettings { } /** - * The message displayed if a player presents a different item after seeing the price to salvage an item + * Gets the message displayed if a player presents a different item after seeing the price to salvage an item + * + * @return

The item changed message

*/ @NotNull public String getItemChangedMessage() { return asString(ScrapperSetting.ITEM_UNEXPECTEDLY_CHANGED_MESSAGE); } + /** + * Gets the message displayed if a player presents the scrapper with an empty hand + * + * @return

The no item message

+ */ + @NotNull + public String getNoItemMessage() { + return asString(ScrapperSetting.NO_ITEM_MESSAGE); + } + /** * Gets the minimum delay used to wait for a salvaging to finish. * diff --git a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java index bfd6c4a..d24a43f 100644 --- a/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java +++ b/src/main/java/net/knarcraft/blacksmith/config/scrapper/ScrapperSetting.java @@ -236,6 +236,12 @@ public enum ScrapperSetting implements Setting { "&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), + /** + * The message displayed when clicking a scrapper with an empty hand + */ + NO_ITEM_MESSAGE("noItemMessage", SettingValueType.STRING, "Please present the item you want to salvage", + "The message to display when a scrapper is clicked with an empty hand", true, true), + /*------------------ | Global settings | ------------------*/ diff --git a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java index 8bd9a83..80bc932 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/BlacksmithTrait.java @@ -68,6 +68,11 @@ public class BlacksmithTrait extends CustomTrait { @Override public void startSession(@NotNull Player player) { ItemStack hand = player.getInventory().getItemInMainHand(); + if (hand.getType().isAir()) { + sendNPCMessage(this.npc, player, config.getNoItemMessage()); + return; + } + //Refuse if not repairable, or if reforge-able items is set, but doesn't include the held item List reforgeAbleItems = config.getReforgeAbleItems(); diff --git a/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java b/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java index ee922a6..d4e649c 100644 --- a/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java +++ b/src/main/java/net/knarcraft/blacksmith/trait/ScrapperTrait.java @@ -85,6 +85,11 @@ public class ScrapperTrait extends CustomTrait { */ public void startSession(@NotNull Player player) { ItemStack itemInHand = player.getInventory().getItemInMainHand().clone(); + if (itemInHand.getType().isAir()) { + sendNPCMessage(this.npc, player, config.getNoItemMessage()); + return; + } + List salvageAbleItems = getSettings().getSalvageAbleItems(); boolean extended = getSettings().extendedSalvageEnabled(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7a9a96d..92e720f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -111,6 +111,9 @@ blacksmith: # The message to display if a player is trying to reforge an item with full durability notDamagedMessage: "&cThat item is not in need of repair" + + # The message to display when a blacksmith is clicked with an empty hand + noItemMessage: "Please present the item you want to reforge" # Settings for the scrapper trait scrapper: @@ -239,4 +242,7 @@ scrapper: armorTrimSalvageNotFoundMessage: "&cI'm sorry, but I don't know how to salvage that armor trim!" # The message to display when asked to salvage netherite items, and that option is disabled - cannotSalvageNetheriteMessage: "&cI'm sorry, but I'm unable to salvage netherite items!" \ No newline at end of file + cannotSalvageNetheriteMessage: "&cI'm sorry, but I'm unable to salvage netherite items!" + + # The message to display when a scrapper is clicked with an empty hand + noItemMessage: "Please present the item you want to salvage" \ No newline at end of file