mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 09:39:40 -05:00
Fix removeDupe will remove wrong dupe shop's display bug
Former-commit-id: 8ede807d661209cbcc8ccce09c752dd5bc6c86cb [formerly 16a46c70be7880eb8b137d08984e11eb9913adc3] Former-commit-id: f45e841f0db174a5bb96577cd99135328bfde420
This commit is contained in:
1 parent
3273b328b2
commit
0a99def55d
3 files changed
+43
-12
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> lore = new ArrayList<String>();
|
||||
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<String> 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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user