From d2d216be3b60a1e2b847f9437641d3f0410b902c Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 13 Jan 2016 12:54:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E9=83=A8=E5=88=86ESS?= =?UTF-8?q?=E7=9A=84Kit=E5=91=BD=E4=BB=A4=E7=94=9F=E6=88=90=E7=9A=84?= =?UTF-8?q?=E8=A3=85=E5=A4=87...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 4 +- .../me/tft_02/soulbound/util/ItemUtils.java | 619 +++++++++--------- 2 files changed, 311 insertions(+), 312 deletions(-) diff --git a/pom.xml b/pom.xml index c7f38b8..35db1e5 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.me.tft_02.soulbound Soulbound - 1.3.1 + 1.3.2 Soulbound Soulbound items for your RPG servers! https://github.com/TfT-02/Soulbound @@ -61,7 +61,7 @@ http://ci.citycraft.cn:8080 Debug - &c修复背包满时 拾取物品 绑定物品消失BUG(感谢john180修复)... + &a兼容部分ESS的Kit命令生成的装备...&c修复背包满时 拾取物品 绑定物品消失BUG(感谢john180修复)... UTF-8 diff --git a/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java b/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java index ac700b6..a43e561 100644 --- a/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java +++ b/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java @@ -13,361 +13,360 @@ import com.me.tft_02.soulbound.config.Config; import com.me.tft_02.soulbound.events.SoulbindItemEvent; public class ItemUtils { - public static ItemStack boeItem(final ItemStack itemStack) { - if (itemStack == null) { - return itemStack; - } + public static ItemStack boeItem(final ItemStack itemStack) { + if (itemStack == null) { + return itemStack; + } - if (isBindOnEquip(itemStack)) { - return itemStack; - } + if (isBindOnEquip(itemStack)) { + return itemStack; + } - final ItemMeta itemMeta = itemStack.getItemMeta(); + final ItemMeta itemMeta = itemStack.getItemMeta(); - final List itemLore = new ArrayList(); - if (itemMeta.hasLore()) { - itemLore.addAll(itemMeta.getLore()); - } - itemLore.add(Misc.EQUIPBIND_TAG); - itemMeta.setLore(itemLore); - itemStack.setItemMeta(itemMeta); - return itemStack; - } + final List itemLore = new ArrayList(); + if (itemMeta.hasLore()) { + itemLore.addAll(itemMeta.getLore()); + } + itemLore.add(Misc.EQUIPBIND_TAG); + itemMeta.setLore(itemLore); + itemStack.setItemMeta(itemMeta); + return itemStack; + } - public static ItemStack bopItem(final ItemStack itemStack) { - if (itemStack == null) { - return itemStack; - } + public static ItemStack bopItem(final ItemStack itemStack) { + if (itemStack == null) { + return itemStack; + } - if (isBindOnPickup(itemStack)) { - return itemStack; - } + if (isBindOnPickup(itemStack)) { + return itemStack; + } - final ItemMeta itemMeta = itemStack.getItemMeta(); + final ItemMeta itemMeta = itemStack.getItemMeta(); - final List itemLore = new ArrayList(); - if (itemMeta.hasLore()) { - itemLore.addAll(itemMeta.getLore()); - } - itemLore.add(Misc.PICKUPBIND_TAG); - itemMeta.setLore(itemLore); - itemStack.setItemMeta(itemMeta); - return itemStack; - } + final List itemLore = new ArrayList(); + if (itemMeta.hasLore()) { + itemLore.addAll(itemMeta.getLore()); + } + itemLore.add(Misc.PICKUPBIND_TAG); + itemMeta.setLore(itemLore); + itemStack.setItemMeta(itemMeta); + return itemStack; + } - public static ItemStack bouItem(final ItemStack itemStack) { - if (itemStack == null) { - return itemStack; - } + public static ItemStack bouItem(final ItemStack itemStack) { + if (itemStack == null) { + return itemStack; + } - if (isBindOnUse(itemStack)) { - return itemStack; - } + if (isBindOnUse(itemStack)) { + return itemStack; + } - final ItemMeta itemMeta = itemStack.getItemMeta(); + final ItemMeta itemMeta = itemStack.getItemMeta(); - final List itemLore = new ArrayList(); - if (itemMeta.hasLore()) { - itemLore.addAll(itemMeta.getLore()); - } - itemLore.add(Misc.USEBIND_TAG); - itemMeta.setLore(itemLore); - itemStack.setItemMeta(itemMeta); - return itemStack; - } + final List itemLore = new ArrayList(); + if (itemMeta.hasLore()) { + itemLore.addAll(itemMeta.getLore()); + } + itemLore.add(Misc.USEBIND_TAG); + itemMeta.setLore(itemLore); + itemStack.setItemMeta(itemMeta); + return itemStack; + } - public static ItemType getItemType(final ItemStack itemStack) { - if (itemStack == null) { - return ItemType.NORMAL; - } else if (isSoulbound(itemStack)) { - return ItemType.SOULBOUND; - } else if (isBindOnPickup(itemStack)) { - return ItemType.BIND_ON_PICKUP; - } else if (isBindOnUse(itemStack)) { - return ItemType.BIND_ON_USE; - } else if (isBindOnEquip(itemStack)) { - return ItemType.BIND_ON_EQUIP; - } else { - return ItemType.NORMAL; - } - } + public static ItemType getItemType(final ItemStack itemStack) { + if (itemStack == null) { + return ItemType.NORMAL; + } else if (isSoulbound(itemStack)) { + return ItemType.SOULBOUND; + } else if (isBindOnPickup(itemStack)) { + return ItemType.BIND_ON_PICKUP; + } else if (isBindOnUse(itemStack)) { + return ItemType.BIND_ON_USE; + } else if (isBindOnEquip(itemStack)) { + return ItemType.BIND_ON_EQUIP; + } else { + return ItemType.NORMAL; + } + } - public static boolean isBindedPlayer(final Player player, final ItemStack itemStack) { - final List itemLore = itemStack.getItemMeta().getLore(); + public static boolean isBindedPlayer(final Player player, final ItemStack itemStack) { + final List itemLore = itemStack.getItemMeta().getLore(); + return itemLore.contains(player.getName()) || itemLore.contains(player.getName().replaceAll("_", "")); + } - return itemLore.contains(player.getName()); - } + public static boolean isBindOnEquip(final ItemStack itemStack) { + if (!itemStack.hasItemMeta()) { + return false; + } - public static boolean isBindOnEquip(final ItemStack itemStack) { - if (!itemStack.hasItemMeta()) { - return false; - } + final ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta.hasLore()) { + final List itemLore = itemMeta.getLore(); + if (itemLore.contains(Misc.EQUIPBIND_TAG)) { + return true; + } + } + return false; + } - final ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta.hasLore()) { - final List itemLore = itemMeta.getLore(); - if (itemLore.contains(Misc.EQUIPBIND_TAG)) { - return true; - } - } - return false; - } + public static boolean isBindOnPickup(final ItemStack itemStack) { + if (!itemStack.hasItemMeta()) { + return false; + } - public static boolean isBindOnPickup(final ItemStack itemStack) { - if (!itemStack.hasItemMeta()) { - return false; - } + final ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta.hasLore()) { + final List itemLore = itemMeta.getLore(); + if (itemLore.contains(Misc.PICKUPBIND_TAG)) { + return true; + } + } + return false; + } - final ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta.hasLore()) { - final List itemLore = itemMeta.getLore(); - if (itemLore.contains(Misc.PICKUPBIND_TAG)) { - return true; - } - } - return false; - } + public static boolean isBindOnUse(final ItemStack itemStack) { + if (!itemStack.hasItemMeta()) { + return false; + } - public static boolean isBindOnUse(final ItemStack itemStack) { - if (!itemStack.hasItemMeta()) { - return false; - } + final ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta.hasLore()) { + final List itemLore = itemMeta.getLore(); + if (itemLore.contains(Misc.USEBIND_TAG)) { + return true; + } + } + return false; + } - final ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta.hasLore()) { - final List itemLore = itemMeta.getLore(); - if (itemLore.contains(Misc.USEBIND_TAG)) { - return true; - } - } - return false; - } + /** + * Checks to see if an item is a chainmail armor piece. + * + * @param is + * Item to check + * + * @return true if the item is chainmail armor, false otherwise + */ + public static boolean isChainmailArmor(final ItemStack is) { + switch (is.getType()) { + case CHAINMAIL_BOOTS: + case CHAINMAIL_CHESTPLATE: + case CHAINMAIL_HELMET: + case CHAINMAIL_LEGGINGS: + return true; + default: + return false; + } + } - /** - * Checks to see if an item is a chainmail armor piece. - * - * @param is - * Item to check - * - * @return true if the item is chainmail armor, false otherwise - */ - public static boolean isChainmailArmor(final ItemStack is) { - switch (is.getType()) { - case CHAINMAIL_BOOTS: - case CHAINMAIL_CHESTPLATE: - case CHAINMAIL_HELMET: - case CHAINMAIL_LEGGINGS: - return true; - default: - return false; - } - } + /** + * Checks to see if an item is a diamond armor piece. + * + * @param is + * Item to check + * + * @return true if the item is diamond armor, false otherwise + */ + public static boolean isDiamondArmor(final ItemStack is) { + switch (is.getType()) { + case DIAMOND_BOOTS: + case DIAMOND_CHESTPLATE: + case DIAMOND_HELMET: + case DIAMOND_LEGGINGS: + return true; + default: + return false; + } + } - /** - * Checks to see if an item is a diamond armor piece. - * - * @param is - * Item to check - * - * @return true if the item is diamond armor, false otherwise - */ - public static boolean isDiamondArmor(final ItemStack is) { - switch (is.getType()) { - case DIAMOND_BOOTS: - case DIAMOND_CHESTPLATE: - case DIAMOND_HELMET: - case DIAMOND_LEGGINGS: - return true; - default: - return false; - } - } + /** + * Checks to see if an item is an equipable item. + * + * @param is + * Item to check + * + * @return true if the item is equipable, false otherwise + */ + public static boolean isEquipable(final ItemStack is) { + return isMinecraftArmor(is) || is.getType() == Material.SKULL_ITEM || is.getType() == Material.JACK_O_LANTERN; + } - /** - * Checks to see if an item is an equipable item. - * - * @param is - * Item to check - * - * @return true if the item is equipable, false otherwise - */ - public static boolean isEquipable(final ItemStack is) { - return isMinecraftArmor(is) || is.getType() == Material.SKULL_ITEM || is.getType() == Material.JACK_O_LANTERN; - } + /** + * Checks to see if an item is a gold armor piece. + * + * @param is + * Item to check + * + * @return true if the item is gold armor, false otherwise + */ + public static boolean isGoldArmor(final ItemStack is) { + switch (is.getType()) { + case GOLD_BOOTS: + case GOLD_CHESTPLATE: + case GOLD_HELMET: + case GOLD_LEGGINGS: + return true; + default: + return false; + } + } - /** - * Checks to see if an item is a gold armor piece. - * - * @param is - * Item to check - * - * @return true if the item is gold armor, false otherwise - */ - public static boolean isGoldArmor(final ItemStack is) { - switch (is.getType()) { - case GOLD_BOOTS: - case GOLD_CHESTPLATE: - case GOLD_HELMET: - case GOLD_LEGGINGS: - return true; - default: - return false; - } - } + /** + * Checks to see if an item is an iron armor piece. + * + * @param is + * Item to check + * + * @return true if the item is iron armor, false otherwise + */ + public static boolean isIronArmor(final ItemStack is) { + switch (is.getType()) { + case IRON_BOOTS: + case IRON_CHESTPLATE: + case IRON_HELMET: + case IRON_LEGGINGS: + return true; + default: + return false; + } + } - /** - * Checks to see if an item is an iron armor piece. - * - * @param is - * Item to check - * - * @return true if the item is iron armor, false otherwise - */ - public static boolean isIronArmor(final ItemStack is) { - switch (is.getType()) { - case IRON_BOOTS: - case IRON_CHESTPLATE: - case IRON_HELMET: - case IRON_LEGGINGS: - return true; - default: - return false; - } - } + /** + * Checks to see if an item is a leather armor piece. + * + * @param is + * Item to check + * + * @return true if the item is leather armor, false otherwise + */ + public static boolean isLeatherArmor(final ItemStack is) { + switch (is.getType()) { + case LEATHER_BOOTS: + case LEATHER_CHESTPLATE: + case LEATHER_HELMET: + case LEATHER_LEGGINGS: + return true; + default: + return false; + } + } - /** - * Checks to see if an item is a leather armor piece. - * - * @param is - * Item to check - * - * @return true if the item is leather armor, false otherwise - */ - public static boolean isLeatherArmor(final ItemStack is) { - switch (is.getType()) { - case LEATHER_BOOTS: - case LEATHER_CHESTPLATE: - case LEATHER_HELMET: - case LEATHER_LEGGINGS: - return true; - default: - return false; - } - } + /** + * Checks to see if an item is a wearable armor piece. + * + * @param is + * Item to check + * + * @return true if the item is armor, false otherwise + */ + public static boolean isMinecraftArmor(final ItemStack is) { + return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is) || isChainmailArmor(is); + } - /** - * Checks to see if an item is a wearable armor piece. - * - * @param is - * Item to check - * - * @return true if the item is armor, false otherwise - */ - public static boolean isMinecraftArmor(final ItemStack is) { - return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is) || isChainmailArmor(is); - } + public static boolean isNormalItem(final ItemStack itemStack) { + return !itemStack.hasItemMeta() && !itemStack.getItemMeta().hasLore() || ItemUtils.getItemType(itemStack) == ItemType.NORMAL; + } - public static boolean isNormalItem(final ItemStack itemStack) { - return !itemStack.hasItemMeta() && !itemStack.getItemMeta().hasLore() || ItemUtils.getItemType(itemStack) == ItemType.NORMAL; - } + public static boolean isSoulbound(final ItemStack itemStack) { + if (!itemStack.hasItemMeta()) { + return false; + } - public static boolean isSoulbound(final ItemStack itemStack) { - if (!itemStack.hasItemMeta()) { - return false; - } + final ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta.hasLore()) { + final List itemLore = itemMeta.getLore(); + for (final String lore : itemLore) { + if (lore.contains(Misc.SOULBOUND_TAG)) { + return true; + } + } + } + return false; + } - final ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta.hasLore()) { - final List itemLore = itemMeta.getLore(); - for (final String lore : itemLore) { - if (lore.contains(Misc.SOULBOUND_TAG)) { - return true; - } - } - } - return false; - } + public static ItemStack soulbindItem(final Player player, ItemStack itemStack) { + if (itemStack == null) { + return itemStack; + } - public static ItemStack soulbindItem(final Player player, ItemStack itemStack) { - if (itemStack == null) { - return itemStack; - } + if (isSoulbound(itemStack)) { + return itemStack; + } - if (isSoulbound(itemStack)) { - return itemStack; - } + final SoulbindItemEvent soulbindItemEvent = new SoulbindItemEvent(player, itemStack); + Soulbound.p.getServer().getPluginManager().callEvent(soulbindItemEvent); + itemStack = soulbindItemEvent.getItemStack(); - final SoulbindItemEvent soulbindItemEvent = new SoulbindItemEvent(player, itemStack); - Soulbound.p.getServer().getPluginManager().callEvent(soulbindItemEvent); - itemStack = soulbindItemEvent.getItemStack(); + if (soulbindItemEvent.isCancelled()) { + return itemStack; + } - if (soulbindItemEvent.isCancelled()) { - return itemStack; - } + final ItemMeta itemMeta = itemStack.getItemMeta(); + final List itemLore = new ArrayList(); - final ItemMeta itemMeta = itemStack.getItemMeta(); - final List itemLore = new ArrayList(); + if (itemMeta.hasLore()) { + final List oldLore = itemMeta.getLore(); + oldLore.remove(Misc.EQUIPBIND_TAG); + oldLore.remove(Misc.PICKUPBIND_TAG); + oldLore.remove(Misc.USEBIND_TAG); + itemLore.addAll(oldLore); + } - if (itemMeta.hasLore()) { - final List oldLore = itemMeta.getLore(); - oldLore.remove(Misc.EQUIPBIND_TAG); - oldLore.remove(Misc.PICKUPBIND_TAG); - oldLore.remove(Misc.USEBIND_TAG); - itemLore.addAll(oldLore); - } + itemLore.add(Misc.SOULBOUND_TAG); - itemLore.add(Misc.SOULBOUND_TAG); + if (Config.getShowNameInLore()) { + itemLore.add(player.getName()); + } - if (Config.getShowNameInLore()) { - itemLore.add(player.getName()); - } + itemMeta.setLore(itemLore); + itemStack.setItemMeta(itemMeta); + return itemStack; + } - itemMeta.setLore(itemLore); - itemStack.setItemMeta(itemMeta); - return itemStack; - } + public static ItemStack unbindItem(final ItemStack itemStack) { + if (itemStack == null) { + return null; + } - public static ItemStack unbindItem(final ItemStack itemStack) { - if (itemStack == null) { - return null; - } + final ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemMeta.hasLore() && isSoulbound(itemStack)) { + final List oldLore = itemMeta.getLore(); + final int loreSize = oldLore.size(); - final ItemMeta itemMeta = itemStack.getItemMeta(); - if (itemMeta.hasLore() && isSoulbound(itemStack)) { - final List oldLore = itemMeta.getLore(); - final int loreSize = oldLore.size(); + if (loreSize <= 2) { + itemMeta.setLore(null); + itemStack.setItemMeta(itemMeta); + return itemStack; + } - if (loreSize <= 2) { - itemMeta.setLore(null); - itemStack.setItemMeta(itemMeta); - return itemStack; - } + final List itemLore = new ArrayList(); + itemLore.addAll(oldLore); + final int index = StringUtils.getIndexOfSoulbound(itemLore); - final List itemLore = new ArrayList(); - itemLore.addAll(oldLore); - final int index = StringUtils.getIndexOfSoulbound(itemLore); + if (index == -1) { + return null; + } - if (index == -1) { - return null; - } + itemLore.remove(index); + if (index < itemLore.size()) { + itemLore.remove(index); + } - itemLore.remove(index); - if (index < itemLore.size()) { - itemLore.remove(index); - } + itemMeta.setLore(itemLore); + } - itemMeta.setLore(itemLore); - } + itemStack.setItemMeta(itemMeta); + return itemStack; + } - itemStack.setItemMeta(itemMeta); - return itemStack; - } - - public enum ItemType { - BIND_ON_EQUIP, - BIND_ON_PICKUP, - BIND_ON_USE, - NORMAL, - SOULBOUND; - } + public enum ItemType { + BIND_ON_EQUIP, + BIND_ON_PICKUP, + BIND_ON_USE, + NORMAL, + SOULBOUND; + } }