From 35836c60bcd7e988d14018c2b54656d0d50907a5 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Wed, 28 Jul 2021 13:18:45 +0800 Subject: [PATCH] Force shop database updating in async thread --- .../maxgamer/quickshop/shop/ContainerShop.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java index ba148d46f..6cc07601d 100644 --- a/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/shop/ContainerShop.java @@ -711,7 +711,13 @@ public class ContainerShop implements Shop { */ @Override public synchronized void update() { - Util.mainThreadRun(this::update0); + Util.ensureThread(false); + ShopUpdateEvent shopUpdateEvent = new ShopUpdateEvent(this); + if (Util.fireCancellableEvent(shopUpdateEvent)) { + Util.debugLog("The Shop update action was canceled by a plugin."); + return; + } + Bukkit.getScheduler().runTaskAsynchronously(plugin, this::update0); } private void notifyDisplayItemChange() { @@ -722,12 +728,8 @@ public class ContainerShop implements Shop { } private void update0() { - Util.ensureThread(false); - ShopUpdateEvent shopUpdateEvent = new ShopUpdateEvent(this); - if (Util.fireCancellableEvent(shopUpdateEvent)) { - Util.debugLog("The Shop update action was canceled by a plugin."); - return; - } + // Make sure this only trigged in async thread, we will start the I/O actions + Util.ensureThread(true); int x = this.getLocation().getBlockX(); int y = this.getLocation().getBlockY(); int z = this.getLocation().getBlockZ();