Give reason when delivery items do not match

This commit is contained in:
BuildTools 2019-01-02 15:02:56 -05:00
parent bbfbc6a98b
commit 90511df08f
3 changed files with 33 additions and 6 deletions

View File

@ -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("<item>", text), hand.getType(), hand.getDurability());
plugin.query.sendMessage(player, Lang.get(player, "difference").replace("<item>", text), hand.getType(), hand.getDurability());
switch(reasonCode) {
case 1:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "one item is null"));
case 0:
// Should never happen
player.sendMessage(Lang.get(player, "difference").replace("<data>", "ERROR"));
case -1:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "name"));
case -2:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "amount"));
case -3:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "durability"));
case -4:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "display name or lore"));
case -5:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "enchantments"));
case -6:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "stored enchants"));
case -7:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "item flags"));
default:
player.sendMessage(Lang.get(player, "difference").replace("<data>", "unknown"));
}
if (hand.hasItemMeta()) {
if (hand.getType().equals(Material.ENCHANTED_BOOK)) {
EnchantmentStorageMeta esmeta = (EnchantmentStorageMeta) hand.getItemMeta();

View File

@ -50,6 +50,7 @@ public class ItemUtil {
* -4 if stack display name/lore is unequal<br>
* -5 if stack enchantments are unequal<br>
* -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;
}
}
}

View File

@ -185,7 +185,7 @@ stageEditorCustomPrompt: "Enter the name of a custom objective to add, <clear>,
stageEditorCustomAlreadyAdded: "That custom objective has already been added!"
stageEditorCustomCleared: "Custom objectives cleared."
stageEditorCustomDataPrompt: "Enter value for <data>:"
stageEditorEnterBlockNames: "Enter block names (or IDs), <space>, <cancel>"
stageEditorEnterBlockNames: "Enter block names, <space>, <cancel>"
stageEditorBreakBlocksPrompt: "Enter break amounts (numbers), <space>, <cancel>"
stageEditorDamageBlocksPrompt: "Enter damage amounts (numbers), <space>, <cancel>"
stageEditorPlaceBlocksPrompt: "Enter place amounts (numbers), <space>, <cancel>"
@ -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% <time> seconds"
timerStart: "%green%You have%red% <time> seconds%green% to finish this quest/stage"
questErrorReadingFile: "Error reading Quests file."
questSaveError: "An error occurred while saving."
noPermission: "You do not have permission to do that."
noPermission: "You do not have permission to do that."
difference: "The difference is '<data>'."