This repository was archived by the owner on Dec 5, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/java/org/maxgamer/quickshop/shop Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4646import java .util .*;
4747import java .util .concurrent .ConcurrentLinkedQueue ;
4848import java .util .concurrent .ConcurrentSkipListSet ;
49+ import java .util .concurrent .ExecutionException ;
4950import java .util .concurrent .atomic .AtomicInteger ;
5051
5152public 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 ();
You can’t perform that action at this time.
0 commit comments