diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java index 060acbacb..ccd62239d 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ArmorStandDisplayItem.java @@ -84,7 +84,7 @@ public class ArmorStandDisplayItem implements DisplayItem { } ArmorStand armorStand = (ArmorStand) entity; //Set item protect in the armorstand's hand - this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack); + this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); armorStand.setItemInHand(guardedIstack); Util.debugLog("Successfully safeGuard ArmorStand: " + armorStand.getLocation().toString()); } @@ -221,10 +221,12 @@ public class ArmorStandDisplayItem implements DisplayItem { ArmorStand eArmorStand = (ArmorStand) entity; if (plugin.getItemMatcher().matches(eArmorStand.getItemInHand(), this.guardedIstack)) { if (!eArmorStand.getUniqueId().equals(this.armorStand.getUniqueId())) { - Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId().toString() + " at " + eArmorStand - .getLocation().toString()); - entity.remove(); - removed = true; + if (DisplayItem.checkIsTargetShopDisplay(eArmorStand.getItemInHand(), this.shop)) { + Util.debugLog("Removing dupes ArmorEntity " + eArmorStand.getUniqueId().toString() + " at " + eArmorStand + .getLocation().toString()); + entity.remove(); + removed = true; + } } } } diff --git a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java index 69a605c59..7b9df5671 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/DisplayItem.java @@ -97,7 +97,7 @@ public interface DisplayItem { * @param itemStack Old itemStack * @return New itemStack with protect flag. */ - public static ItemStack createGuardItemStack(ItemStack itemStack) { + public static ItemStack createGuardItemStack(ItemStack itemStack, Shop shop) { itemStack = itemStack.clone(); ItemMeta iMeta = itemStack.getItemMeta(); if (QuickShop.instance.getConfig().getBoolean("shop.display-item-use-name")) { @@ -105,7 +105,8 @@ public interface DisplayItem { } java.util.List lore = new ArrayList(); for (int i = 0; i < 21; i++) { - lore.add("QuickShop DisplayItem"); //Create 20 lines lore to make sure no stupid plugin accident remove mark. + lore.add("QuickShop DisplayItem#" + shop + .hashCode()); //Create 20 lines lore to make sure no stupid plugin accident remove mark. } iMeta.setLore(lore); itemStack.setItemMeta(iMeta); @@ -139,6 +140,32 @@ public interface DisplayItem { return false; } + /** + * Check the itemStack is target shop's display + * + * @param itemStack Target ItemStack + * @param shop Target shop + * @return Is target shop's display + */ + public static boolean checkIsTargetShopDisplay(ItemStack itemStack, Shop shop) { + if (itemStack == null) + return false; + itemStack = itemStack.clone(); + if (!itemStack.hasItemMeta()) + return false; + ItemMeta iMeta = itemStack.getItemMeta(); + if (!iMeta.hasLore()) + return false; + List lores = iMeta.getLore(); + for (String lore : lores) { + if (lore.toLowerCase().contains("quickshop displayitem")) { + if (lore.equals("quickshop displayitem#" + shop.hashCode())) + return true; + } + } + return false; + } + /** * Get plugin now is using which one DisplayType * @return Using displayType. diff --git a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java index 940f65e03..3b5b5194c 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/RealDisplayItem.java @@ -78,7 +78,7 @@ public class RealDisplayItem implements DisplayItem { } Item item = (Item) entity; //Set item protect in the armorstand's hand - this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack); + this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop); item.setItemStack(this.guardedIstack); Util.debugLog("Successfully safeGuard Item: " + item.getLocation().toString()); } @@ -110,10 +110,12 @@ public class RealDisplayItem implements DisplayItem { continue; if (plugin.getItemMatcher().matches(eItem.getItemStack(), this.guardedIstack)) { if (!eItem.getUniqueId().equals(this.item.getUniqueId())) { - Util.debugLog("Removing a duped ItemEntity " + eItem.getUniqueId().toString() + " at " + eItem - .getLocation().toString()); - entity.remove(); - removed = true; + if (DisplayItem.checkIsTargetShopDisplay(eItem.getItemStack(), this.shop)) { + Util.debugLog("Removing a duped ItemEntity " + eItem.getUniqueId().toString() + " at " + eItem + .getLocation().toString()); + entity.remove(); + removed = true; + } } } }