diff --git a/src/main/java/de/epiceric/shopchest/nms/ArmorStandWrapper.java b/src/main/java/de/epiceric/shopchest/nms/ArmorStandWrapper.java index fba1059..5ef548c 100644 --- a/src/main/java/de/epiceric/shopchest/nms/ArmorStandWrapper.java +++ b/src/main/java/de/epiceric/shopchest/nms/ArmorStandWrapper.java @@ -17,24 +17,24 @@ public class ArmorStandWrapper { private final Class dataWatcherClass = Utils.getNMSClass("DataWatcher"); private final UUID uuid = UUID.randomUUID(); - + private final int entityId; + private ShopChest plugin; private Object entity; private Location location; private String customName; - private int entityId = -1; public ArmorStandWrapper(ShopChest plugin, Location location, String customName, boolean interactable) { this.plugin = plugin; this.location = location; this.customName = customName; + this.entityId = Utils.getFreeEntityId(); } public void setVisible(Player player, boolean visible) { try { if (visible) { Object dataWatcher = Utils.createDataWatcher(customName, null); - entityId = Utils.getFreeEntityId(); Utils.sendPacket(plugin, Utils.createPacketSpawnEntity(plugin, entityId, uuid, location, EntityType.ARMOR_STAND), player); Utils.sendPacket(plugin, packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class) .newInstance(entityId, dataWatcher, true), player); diff --git a/src/main/java/de/epiceric/shopchest/shop/ShopItem.java b/src/main/java/de/epiceric/shopchest/shop/ShopItem.java index fddbf1a..36014a7 100644 --- a/src/main/java/de/epiceric/shopchest/shop/ShopItem.java +++ b/src/main/java/de/epiceric/shopchest/shop/ShopItem.java @@ -22,8 +22,7 @@ public class ShopItem { private final ItemStack itemStack; private final Location location; private final UUID uuid = UUID.randomUUID(); - - private int entityId = -1; + private final int entityId; private final Class packetPlayOutEntityDestroyClass = Utils.getNMSClass("PacketPlayOutEntityDestroy"); private final Class packetPlayOutEntityVelocityClass = Utils.getNMSClass("PacketPlayOutEntityVelocity"); @@ -37,6 +36,7 @@ public class ShopItem { this.plugin = plugin; this.itemStack = itemStack; this.location = location; + this.entityId = Utils.getFreeEntityId(); Class entityClass = Utils.getNMSClass("Entity"); @@ -91,7 +91,6 @@ public class ShopItem { try { Object nmsItemStack = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemStack); Object dataWatcher = Utils.createDataWatcher(null, nmsItemStack); - entityId = Utils.getFreeEntityId(); Utils.sendPacket(plugin, Utils.createPacketSpawnEntity(plugin, entityId, uuid, location, EntityType.DROPPED_ITEM), p); Utils.sendPacket(plugin, packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class).newInstance(entityId, dataWatcher, true), p); if (Utils.getMajorVersion() < 14) {