diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index 7591b5ab4..d2641a539 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -164,18 +164,17 @@ public class ContainerShop implements Shop { private void initDisplayItem() { Util.ensureThread(false); if (plugin.isDisplay()) { - Chunk chunk = getLocation().getChunk(); switch (DisplayItem.getNowUsing()) { case REALITEM: - this.displayItem = new RealDisplayItem(this, chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); + this.displayItem = new RealDisplayItem(this); break; case VIRTUALITEM: - this.displayItem = new VirtualDisplayItem(this, chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); + this.displayItem = new VirtualDisplayItem(this); break; default: Util.debugLog( "Warning: Failed to create a ContainerShop displayItem, the type we didn't know, fallback to RealDisplayItem"); - this.displayItem = new RealDisplayItem(this, chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); + this.displayItem = new RealDisplayItem(this); break; } } diff --git a/src/main/java/org/maxgamer/quickshop/shop/DisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/DisplayItem.java index 686dc312b..be9737e87 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/DisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/DisplayItem.java @@ -52,15 +52,9 @@ public abstract class DisplayItem { @Nullable protected ItemStack guardedIstack; private boolean pendingRemoval; - protected final int chunkX; - protected final int chunkZ; - protected final String worldName; - protected DisplayItem(Shop shop, String worldName, int chunkX, int chunkZ) { + protected DisplayItem(Shop shop) { this.shop = shop; - this.worldName = worldName; - this.chunkX = chunkX; - this.chunkZ = chunkZ; this.originalItemStack = shop.getItem().clone(); if (displayAllowStacks) { //Prevent stack over the normal size diff --git a/src/main/java/org/maxgamer/quickshop/shop/RealDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/RealDisplayItem.java index 159386e4d..0dcfb9ae4 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/RealDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/RealDisplayItem.java @@ -50,8 +50,8 @@ public class RealDisplayItem extends DisplayItem { * * @param shop The shop (See Shop) */ - RealDisplayItem(@NotNull Shop shop, @NotNull String worldName, int chunkX, int chunkZ) { - super(shop, worldName, chunkX, chunkZ); + RealDisplayItem(@NotNull Shop shop) { + super(shop); // this.displayLoc = shop.getLocation().clone().add(0.5, 1.2, 0.5); } diff --git a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java index 479df14d3..dbc01cc52 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java +++ b/src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java @@ -31,6 +31,7 @@ import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; @@ -87,8 +88,8 @@ public class VirtualDisplayItem extends DisplayItem { private AsyncListenerHandler asyncListenerHandler; - public VirtualDisplayItem(@NotNull Shop shop, @NotNull String worldName, int chunkX, int chunkZ) throws RuntimeException { - super(shop, worldName, chunkX, chunkZ); + public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException { + super(shop); } private void initFakeDropItemPacket() { @@ -126,9 +127,11 @@ public class VirtualDisplayItem extends DisplayItem { @Override public void remove() { - sendPacketToAll(fakeItemDestroyPacket); - unload(); - isDisplay = false; + if (isDisplay) { + sendPacketToAll(fakeItemDestroyPacket); + unload(); + isDisplay = false; + } } private void sendPacketToAll(@NotNull PacketContainer packet) { @@ -177,15 +180,16 @@ public class VirtualDisplayItem extends DisplayItem { @Override public void spawn() { Util.ensureThread(false); - if (shop.isLeftShop()) { + if (shop.isLeftShop() || isDisplay || shop.isDeleted() || !shop.isLoaded()) { return; } //lazy initialize if (!initialized) { initFakeDropItemPacket(); } - if (shop.isDeleted() || !shop.isLoaded()) { - return; + if (chunkLocation == null) { + Chunk chunk = shop.getLocation().getChunk(); + chunkLocation = new ShopChunk(chunk.getWorld().getName(), chunk.getX(), chunk.getZ()); } ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = new ShopDisplayItemSpawnEvent(shop, originalItemStack, DisplayType.VIRTUALITEM); plugin.getServer().getPluginManager().callEvent(shopDisplayItemSpawnEvent); @@ -246,9 +250,6 @@ public class VirtualDisplayItem extends DisplayItem { int x = integerStructureModifier.read(0); //chunk z int z = integerStructureModifier.read(1); - if (chunkLocation == null) { - chunkLocation = new ShopChunk(worldName, chunkX, chunkZ); - } if (chunkLocation.isSame(player.getWorld().getName(), x, z)) { packetSenders.add(player.getUniqueId()); sendFakeItem(player);