From 90511df08fff7d1a494d1468d6427aa0bc694630 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 2 Jan 2019 15:02:56 -0500 Subject: [PATCH] Give reason when delivery items do not match --- .../java/me/blackvein/quests/NpcListener.java | 29 +++++++++++++++++-- .../me/blackvein/quests/util/ItemUtil.java | 3 +- src/main/resources/strings.yml | 7 +++-- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/blackvein/quests/NpcListener.java b/src/main/java/me/blackvein/quests/NpcListener.java index ec89bc416..df8f25bcb 100644 --- a/src/main/java/me/blackvein/quests/NpcListener.java +++ b/src/main/java/me/blackvein/quests/NpcListener.java @@ -62,8 +62,10 @@ public class NpcListener implements Listener { if (quester.containsObjective(quest, "deliverItem") && player.getItemInHand() != null) { ItemStack hand = player.getItemInHand(); ItemStack found = null; + int reasonCode = 0; for (ItemStack is : quester.getCurrentStage(quest).itemsToDeliver) { - if (ItemUtil.compareItems(is, hand, true) == 0) { + reasonCode = ItemUtil.compareItems(is, hand, true); + if (reasonCode == 0) { found = is; break; } @@ -90,7 +92,30 @@ public class NpcListener implements Listener { text += (hand.getItemMeta().hasDisplayName() ? ")" : ""); } text += " x " + ChatColor.DARK_AQUA + hand.getAmount() + ChatColor.GRAY; - plugin.query.sendMessage(player, Lang.get(player, "questInvalidDeliveryItem").replace("", text), hand.getType(), hand.getDurability()); + plugin.query.sendMessage(player, Lang.get(player, "difference").replace("", text), hand.getType(), hand.getDurability()); + switch(reasonCode) { + case 1: + player.sendMessage(Lang.get(player, "difference").replace("", "one item is null")); + case 0: + // Should never happen + player.sendMessage(Lang.get(player, "difference").replace("", "ERROR")); + case -1: + player.sendMessage(Lang.get(player, "difference").replace("", "name")); + case -2: + player.sendMessage(Lang.get(player, "difference").replace("", "amount")); + case -3: + player.sendMessage(Lang.get(player, "difference").replace("", "durability")); + case -4: + player.sendMessage(Lang.get(player, "difference").replace("", "display name or lore")); + case -5: + player.sendMessage(Lang.get(player, "difference").replace("", "enchantments")); + case -6: + player.sendMessage(Lang.get(player, "difference").replace("", "stored enchants")); + case -7: + player.sendMessage(Lang.get(player, "difference").replace("", "item flags")); + default: + player.sendMessage(Lang.get(player, "difference").replace("", "unknown")); + } if (hand.hasItemMeta()) { if (hand.getType().equals(Material.ENCHANTED_BOOK)) { EnchantmentStorageMeta esmeta = (EnchantmentStorageMeta) hand.getItemMeta(); diff --git a/src/main/java/me/blackvein/quests/util/ItemUtil.java b/src/main/java/me/blackvein/quests/util/ItemUtil.java index 5a755e60f..357f318c8 100644 --- a/src/main/java/me/blackvein/quests/util/ItemUtil.java +++ b/src/main/java/me/blackvein/quests/util/ItemUtil.java @@ -50,6 +50,7 @@ public class ItemUtil { * -4 if stack display name/lore is unequal
* -5 if stack enchantments are unequal
* -6 if stack stored enchants are unequal + * -7 if stack item flags are unequal */ @SuppressWarnings("deprecation") public static int compareItems(ItemStack one, ItemStack two, boolean ignoreAmount) { @@ -83,7 +84,7 @@ public class ItemUtil { } for (ItemFlag flag : ItemFlag.values()) { if (one.getItemMeta().hasItemFlag(flag) == false && two.getItemMeta().hasItemFlag(flag)) { - return -4; + return -7; } } } diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index 4ca75d32a..2641d644d 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -185,7 +185,7 @@ stageEditorCustomPrompt: "Enter the name of a custom objective to add, , stageEditorCustomAlreadyAdded: "That custom objective has already been added!" stageEditorCustomCleared: "Custom objectives cleared." stageEditorCustomDataPrompt: "Enter value for :" -stageEditorEnterBlockNames: "Enter block names (or IDs), , " +stageEditorEnterBlockNames: "Enter block names, , " stageEditorBreakBlocksPrompt: "Enter break amounts (numbers), , " stageEditorDamageBlocksPrompt: "Enter damage amounts (numbers), , " stageEditorPlaceBlocksPrompt: "Enter place amounts (numbers), , " @@ -540,7 +540,7 @@ itemCreateLoadHand: "Load item in hand" itemCreateSetName: "Set name" itemCreateSetAmount: "Set amount" itemCreateSetDurab: "Set durability" -itemCreateSetEnchs: "Add/clear enchantments" +itemCreateSetEnchs: "Set enchantments" itemCreateSetDisplay: "Set display name" itemCreateSetLore: "Set lore" itemCreateSetClearMeta: "Clear extra data" @@ -854,4 +854,5 @@ timerMessage: "%green%Time left to finish the quest/stage:%red%