[VirtualDisplayItem] Reduce task amount and making chunkLocation volatile

This commit is contained in:
sandtechnology committed 2021-06-05 18:06:02 +08:00
1 parent 0974001c1d
commit 69bf45c47a
1 file changed
+8 -8
@@ -85,7 +85,7 @@ public class VirtualDisplayItem extends DisplayItem {
private PacketAdapter unloadPacketAdapter;
//cache chunk x and z
private ShopChunk chunkLocation;
private volatile ShopChunk chunkLocation;
public VirtualDisplayItem(@NotNull Shop shop) throws RuntimeException {
@@ -343,6 +343,13 @@ public class VirtualDisplayItem extends DisplayItem {
if (!shop.isLoaded() || !isDisplay || !isFull || shop.isLeftShop()) {
return;
}
Player player = event.getPlayer();
if (player instanceof TemporaryPlayer) {
return;
}
if (player == null || !player.isOnline()) {
return;
}
StructureModifier<Integer> integerStructureModifier = event.getPacket().getIntegers();
//chunk x
int x = integerStructureModifier.read(0);
@@ -360,13 +367,6 @@ public class VirtualDisplayItem extends DisplayItem {
}
chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ());
}
Player player = event.getPlayer();
if (player instanceof TemporaryPlayer) {
return;
}
if (player == null || !player.isOnline()) {
return;
}
if (chunkLocation.isSame(player.getWorld().getName(), x, z)) {
packetSenders.add(player.getUniqueId());
sendFakeItem(player);