1
0
mirror of https://e.coding.net/circlecloud/Soulbound.git synced 2024-11-24 02:09:08 +00:00

兼容部分ESS的Kit命令生成的装备...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2016-01-13 12:54:20 +08:00
parent 29fa1ec343
commit d2d216be3b
2 changed files with 311 additions and 312 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.me.tft_02.soulbound</groupId> <groupId>com.me.tft_02.soulbound</groupId>
<artifactId>Soulbound</artifactId> <artifactId>Soulbound</artifactId>
<version>1.3.1</version> <version>1.3.2</version>
<name>Soulbound</name> <name>Soulbound</name>
<description>Soulbound items for your RPG servers!</description> <description>Soulbound items for your RPG servers!</description>
<url>https://github.com/TfT-02/Soulbound</url> <url>https://github.com/TfT-02/Soulbound</url>
@ -61,7 +61,7 @@
<properties> <properties>
<jenkins.url>http://ci.citycraft.cn:8080</jenkins.url> <jenkins.url>http://ci.citycraft.cn:8080</jenkins.url>
<env.BUILD_NUMBER>Debug</env.BUILD_NUMBER> <env.BUILD_NUMBER>Debug</env.BUILD_NUMBER>
<update.description>&amp;c修复背包满时 拾取物品 绑定物品消失BUG(感谢john180修复)...</update.description> <update.description>&amp;a兼容部分ESS的Kit命令生成的装备...&amp;c修复背包满时 拾取物品 绑定物品消失BUG(感谢john180修复)...</update.description>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<repositories> <repositories>

View File

@ -13,361 +13,360 @@ import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.events.SoulbindItemEvent; import com.me.tft_02.soulbound.events.SoulbindItemEvent;
public class ItemUtils { public class ItemUtils {
public static ItemStack boeItem(final ItemStack itemStack) { public static ItemStack boeItem(final ItemStack itemStack) {
if (itemStack == null) { if (itemStack == null) {
return itemStack; return itemStack;
} }
if (isBindOnEquip(itemStack)) { if (isBindOnEquip(itemStack)) {
return itemStack; return itemStack;
} }
final ItemMeta itemMeta = itemStack.getItemMeta(); final ItemMeta itemMeta = itemStack.getItemMeta();
final List<String> itemLore = new ArrayList<String>(); final List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) { if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore()); itemLore.addAll(itemMeta.getLore());
} }
itemLore.add(Misc.EQUIPBIND_TAG); itemLore.add(Misc.EQUIPBIND_TAG);
itemMeta.setLore(itemLore); itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
return itemStack; return itemStack;
} }
public static ItemStack bopItem(final ItemStack itemStack) { public static ItemStack bopItem(final ItemStack itemStack) {
if (itemStack == null) { if (itemStack == null) {
return itemStack; return itemStack;
} }
if (isBindOnPickup(itemStack)) { if (isBindOnPickup(itemStack)) {
return itemStack; return itemStack;
} }
final ItemMeta itemMeta = itemStack.getItemMeta(); final ItemMeta itemMeta = itemStack.getItemMeta();
final List<String> itemLore = new ArrayList<String>(); final List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) { if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore()); itemLore.addAll(itemMeta.getLore());
} }
itemLore.add(Misc.PICKUPBIND_TAG); itemLore.add(Misc.PICKUPBIND_TAG);
itemMeta.setLore(itemLore); itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
return itemStack; return itemStack;
} }
public static ItemStack bouItem(final ItemStack itemStack) { public static ItemStack bouItem(final ItemStack itemStack) {
if (itemStack == null) { if (itemStack == null) {
return itemStack; return itemStack;
} }
if (isBindOnUse(itemStack)) { if (isBindOnUse(itemStack)) {
return itemStack; return itemStack;
} }
final ItemMeta itemMeta = itemStack.getItemMeta(); final ItemMeta itemMeta = itemStack.getItemMeta();
final List<String> itemLore = new ArrayList<String>(); final List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) { if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore()); itemLore.addAll(itemMeta.getLore());
} }
itemLore.add(Misc.USEBIND_TAG); itemLore.add(Misc.USEBIND_TAG);
itemMeta.setLore(itemLore); itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta); itemStack.setItemMeta(itemMeta);
return itemStack; return itemStack;
} }
public static ItemType getItemType(final ItemStack itemStack) { public static ItemType getItemType(final ItemStack itemStack) {
if (itemStack == null) { if (itemStack == null) {
return ItemType.NORMAL; return ItemType.NORMAL;
} else if (isSoulbound(itemStack)) { } else if (isSoulbound(itemStack)) {
return ItemType.SOULBOUND; return ItemType.SOULBOUND;
} else if (isBindOnPickup(itemStack)) { } else if (isBindOnPickup(itemStack)) {
return ItemType.BIND_ON_PICKUP; return ItemType.BIND_ON_PICKUP;
} else if (isBindOnUse(itemStack)) { } else if (isBindOnUse(itemStack)) {
return ItemType.BIND_ON_USE; return ItemType.BIND_ON_USE;
} else if (isBindOnEquip(itemStack)) { } else if (isBindOnEquip(itemStack)) {
return ItemType.BIND_ON_EQUIP; return ItemType.BIND_ON_EQUIP;
} else { } else {
return ItemType.NORMAL; return ItemType.NORMAL;
} }
} }
public static boolean isBindedPlayer(final Player player, final ItemStack itemStack) { public static boolean isBindedPlayer(final Player player, final ItemStack itemStack) {
final List<String> itemLore = itemStack.getItemMeta().getLore(); final List<String> 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) { final ItemMeta itemMeta = itemStack.getItemMeta();
if (!itemStack.hasItemMeta()) { if (itemMeta.hasLore()) {
return false; final List<String> itemLore = itemMeta.getLore();
} if (itemLore.contains(Misc.EQUIPBIND_TAG)) {
return true;
}
}
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta(); public static boolean isBindOnPickup(final ItemStack itemStack) {
if (itemMeta.hasLore()) { if (!itemStack.hasItemMeta()) {
final List<String> itemLore = itemMeta.getLore(); return false;
if (itemLore.contains(Misc.EQUIPBIND_TAG)) { }
return true;
}
}
return false;
}
public static boolean isBindOnPickup(final ItemStack itemStack) { final ItemMeta itemMeta = itemStack.getItemMeta();
if (!itemStack.hasItemMeta()) { if (itemMeta.hasLore()) {
return false; final List<String> itemLore = itemMeta.getLore();
} if (itemLore.contains(Misc.PICKUPBIND_TAG)) {
return true;
}
}
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta(); public static boolean isBindOnUse(final ItemStack itemStack) {
if (itemMeta.hasLore()) { if (!itemStack.hasItemMeta()) {
final List<String> itemLore = itemMeta.getLore(); return false;
if (itemLore.contains(Misc.PICKUPBIND_TAG)) { }
return true;
}
}
return false;
}
public static boolean isBindOnUse(final ItemStack itemStack) { final ItemMeta itemMeta = itemStack.getItemMeta();
if (!itemStack.hasItemMeta()) { if (itemMeta.hasLore()) {
return false; final List<String> itemLore = itemMeta.getLore();
} if (itemLore.contains(Misc.USEBIND_TAG)) {
return true;
}
}
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta(); /**
if (itemMeta.hasLore()) { * Checks to see if an item is a chainmail armor piece.
final List<String> itemLore = itemMeta.getLore(); *
if (itemLore.contains(Misc.USEBIND_TAG)) { * @param is
return true; * Item to check
} *
} * @return true if the item is chainmail armor, false otherwise
return false; */
} 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. * Checks to see if an item is a diamond armor piece.
* *
* @param is * @param is
* Item to check * Item to check
* *
* @return true if the item is chainmail armor, false otherwise * @return true if the item is diamond armor, false otherwise
*/ */
public static boolean isChainmailArmor(final ItemStack is) { public static boolean isDiamondArmor(final ItemStack is) {
switch (is.getType()) { switch (is.getType()) {
case CHAINMAIL_BOOTS: case DIAMOND_BOOTS:
case CHAINMAIL_CHESTPLATE: case DIAMOND_CHESTPLATE:
case CHAINMAIL_HELMET: case DIAMOND_HELMET:
case CHAINMAIL_LEGGINGS: case DIAMOND_LEGGINGS:
return true; return true;
default: default:
return false; return false;
} }
} }
/** /**
* Checks to see if an item is a diamond armor piece. * Checks to see if an item is an equipable item.
* *
* @param is * @param is
* Item to check * Item to check
* *
* @return true if the item is diamond armor, false otherwise * @return true if the item is equipable, false otherwise
*/ */
public static boolean isDiamondArmor(final ItemStack is) { public static boolean isEquipable(final ItemStack is) {
switch (is.getType()) { return isMinecraftArmor(is) || is.getType() == Material.SKULL_ITEM || is.getType() == Material.JACK_O_LANTERN;
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. * Checks to see if an item is a gold armor piece.
* *
* @param is * @param is
* Item to check * Item to check
* *
* @return true if the item is equipable, false otherwise * @return true if the item is gold armor, false otherwise
*/ */
public static boolean isEquipable(final ItemStack is) { public static boolean isGoldArmor(final ItemStack is) {
return isMinecraftArmor(is) || is.getType() == Material.SKULL_ITEM || is.getType() == Material.JACK_O_LANTERN; 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. * Checks to see if an item is an iron armor piece.
* *
* @param is * @param is
* Item to check * Item to check
* *
* @return true if the item is gold armor, false otherwise * @return true if the item is iron armor, false otherwise
*/ */
public static boolean isGoldArmor(final ItemStack is) { public static boolean isIronArmor(final ItemStack is) {
switch (is.getType()) { switch (is.getType()) {
case GOLD_BOOTS: case IRON_BOOTS:
case GOLD_CHESTPLATE: case IRON_CHESTPLATE:
case GOLD_HELMET: case IRON_HELMET:
case GOLD_LEGGINGS: case IRON_LEGGINGS:
return true; return true;
default: default:
return false; return false;
} }
} }
/** /**
* Checks to see if an item is an iron armor piece. * Checks to see if an item is a leather armor piece.
* *
* @param is * @param is
* Item to check * Item to check
* *
* @return true if the item is iron armor, false otherwise * @return true if the item is leather armor, false otherwise
*/ */
public static boolean isIronArmor(final ItemStack is) { public static boolean isLeatherArmor(final ItemStack is) {
switch (is.getType()) { switch (is.getType()) {
case IRON_BOOTS: case LEATHER_BOOTS:
case IRON_CHESTPLATE: case LEATHER_CHESTPLATE:
case IRON_HELMET: case LEATHER_HELMET:
case IRON_LEGGINGS: case LEATHER_LEGGINGS:
return true; return true;
default: default:
return false; return false;
} }
} }
/** /**
* Checks to see if an item is a leather armor piece. * Checks to see if an item is a wearable armor piece.
* *
* @param is * @param is
* Item to check * Item to check
* *
* @return true if the item is leather armor, false otherwise * @return true if the item is armor, false otherwise
*/ */
public static boolean isLeatherArmor(final ItemStack is) { public static boolean isMinecraftArmor(final ItemStack is) {
switch (is.getType()) { return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is) || isChainmailArmor(is);
case LEATHER_BOOTS: }
case LEATHER_CHESTPLATE:
case LEATHER_HELMET:
case LEATHER_LEGGINGS:
return true;
default:
return false;
}
}
/** public static boolean isNormalItem(final ItemStack itemStack) {
* Checks to see if an item is a wearable armor piece. return !itemStack.hasItemMeta() && !itemStack.getItemMeta().hasLore() || ItemUtils.getItemType(itemStack) == ItemType.NORMAL;
* }
* @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) { public static boolean isSoulbound(final ItemStack itemStack) {
return !itemStack.hasItemMeta() && !itemStack.getItemMeta().hasLore() || ItemUtils.getItemType(itemStack) == ItemType.NORMAL; if (!itemStack.hasItemMeta()) {
} return false;
}
public static boolean isSoulbound(final ItemStack itemStack) { final ItemMeta itemMeta = itemStack.getItemMeta();
if (!itemStack.hasItemMeta()) { if (itemMeta.hasLore()) {
return false; final List<String> itemLore = itemMeta.getLore();
} for (final String lore : itemLore) {
if (lore.contains(Misc.SOULBOUND_TAG)) {
return true;
}
}
}
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta(); public static ItemStack soulbindItem(final Player player, ItemStack itemStack) {
if (itemMeta.hasLore()) { if (itemStack == null) {
final List<String> itemLore = itemMeta.getLore(); return itemStack;
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 (isSoulbound(itemStack)) {
if (itemStack == null) { return itemStack;
return itemStack; }
}
if (isSoulbound(itemStack)) { final SoulbindItemEvent soulbindItemEvent = new SoulbindItemEvent(player, itemStack);
return itemStack; Soulbound.p.getServer().getPluginManager().callEvent(soulbindItemEvent);
} itemStack = soulbindItemEvent.getItemStack();
final SoulbindItemEvent soulbindItemEvent = new SoulbindItemEvent(player, itemStack); if (soulbindItemEvent.isCancelled()) {
Soulbound.p.getServer().getPluginManager().callEvent(soulbindItemEvent); return itemStack;
itemStack = soulbindItemEvent.getItemStack(); }
if (soulbindItemEvent.isCancelled()) { final ItemMeta itemMeta = itemStack.getItemMeta();
return itemStack; final List<String> itemLore = new ArrayList<String>();
}
final ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta.hasLore()) {
final List<String> itemLore = new ArrayList<String>(); final List<String> oldLore = itemMeta.getLore();
oldLore.remove(Misc.EQUIPBIND_TAG);
oldLore.remove(Misc.PICKUPBIND_TAG);
oldLore.remove(Misc.USEBIND_TAG);
itemLore.addAll(oldLore);
}
if (itemMeta.hasLore()) { itemLore.add(Misc.SOULBOUND_TAG);
final List<String> 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); if (Config.getShowNameInLore()) {
itemLore.add(player.getName());
}
if (Config.getShowNameInLore()) { itemMeta.setLore(itemLore);
itemLore.add(player.getName()); itemStack.setItemMeta(itemMeta);
} return itemStack;
}
itemMeta.setLore(itemLore); public static ItemStack unbindItem(final ItemStack itemStack) {
itemStack.setItemMeta(itemMeta); if (itemStack == null) {
return itemStack; return null;
} }
public static ItemStack unbindItem(final ItemStack itemStack) { final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemStack == null) { if (itemMeta.hasLore() && isSoulbound(itemStack)) {
return null; final List<String> oldLore = itemMeta.getLore();
} final int loreSize = oldLore.size();
final ItemMeta itemMeta = itemStack.getItemMeta(); if (loreSize <= 2) {
if (itemMeta.hasLore() && isSoulbound(itemStack)) { itemMeta.setLore(null);
final List<String> oldLore = itemMeta.getLore(); itemStack.setItemMeta(itemMeta);
final int loreSize = oldLore.size(); return itemStack;
}
if (loreSize <= 2) { final List<String> itemLore = new ArrayList<String>();
itemMeta.setLore(null); itemLore.addAll(oldLore);
itemStack.setItemMeta(itemMeta); final int index = StringUtils.getIndexOfSoulbound(itemLore);
return itemStack;
}
final List<String> itemLore = new ArrayList<String>(); if (index == -1) {
itemLore.addAll(oldLore); return null;
final int index = StringUtils.getIndexOfSoulbound(itemLore); }
if (index == -1) { itemLore.remove(index);
return null; if (index < itemLore.size()) {
} itemLore.remove(index);
}
itemLore.remove(index); itemMeta.setLore(itemLore);
if (index < itemLore.size()) { }
itemLore.remove(index);
}
itemMeta.setLore(itemLore); itemStack.setItemMeta(itemMeta);
} return itemStack;
}
itemStack.setItemMeta(itemMeta); public enum ItemType {
return itemStack; BIND_ON_EQUIP,
} BIND_ON_PICKUP,
BIND_ON_USE,
public enum ItemType { NORMAL,
BIND_ON_EQUIP, SOULBOUND;
BIND_ON_PICKUP, }
BIND_ON_USE,
NORMAL,
SOULBOUND;
}
} }