Skip to content
This repository was archived by the owner on Dec 5, 2021. It is now read-only.

Commit 3f58881

Browse files
Sync getting chunk to prevent asynchronous ChunkMapDistance::addTicket
Former-commit-id: 6891b63
1 parent 09d9238 commit 3f58881

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/main/java/org/maxgamer/quickshop/shop/VirtualDisplayItem.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.*;
4747
import java.util.concurrent.ConcurrentLinkedQueue;
4848
import java.util.concurrent.ConcurrentSkipListSet;
49+
import java.util.concurrent.ExecutionException;
4950
import java.util.concurrent.atomic.AtomicInteger;
5051

5152
public class VirtualDisplayItem extends DisplayItem {
@@ -320,16 +321,21 @@ public void onPacketSending(@NotNull PacketEvent event) {
320321
if (!shop.isLoaded() || !isDisplay || !isFull || !Util.isLoaded(shop.getLocation())) {
321322
return;
322323
}
324+
//chunk x
323325
int x = event.getPacket().getIntegers().read(0);
324326
//chunk z
325327
int z = event.getPacket().getIntegers().read(1);
326328
asyncPacketSendQueue.offer(() -> {
327-
//chunk x
328-
329-
//check later to prevent deadlock
329+
//lazy initialize
330330
if (chunkLocation == null) {
331331
World world = shop.getLocation().getWorld();
332-
Chunk chunk = shop.getLocation().getChunk();
332+
Chunk chunk = null;
333+
try {
334+
//sync getting chunk
335+
chunk = Bukkit.getScheduler().callSyncMethod(plugin, () -> shop.getLocation().getChunk()).get();
336+
} catch (InterruptedException | ExecutionException e) {
337+
throw new RuntimeException("An error occurred when getting chunk from the world", e);
338+
}
333339
chunkLocation = new ShopChunk(world.getName(), chunk.getX(), chunk.getZ());
334340
}
335341
Player player = event.getPlayer();

0 commit comments

Comments
 (0)