From 8d40d2470a138db286197687cbb8d2f63c4cb3d2 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Fri, 29 Nov 2019 20:59:24 +0800 Subject: [PATCH] Add async detect for display check Former-commit-id: 58804d1c446e014159b510ae63a3608086439247 [formerly 47130e2fa73f678a9e25d0a45f377777293bc7d0] Former-commit-id: 5ab9dfacccacd4c44070a217dca9b2338714dba5 --- .../quickshop/Shop/ContainerShop.java | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java index 22e9fef92..156e7f7b7 100644 --- a/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java +++ b/src/main/java/org/maxgamer/quickshop/Shop/ContainerShop.java @@ -16,10 +16,12 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; +import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.maxgamer.quickshop.Event.*; import org.maxgamer.quickshop.QuickShop; +import org.maxgamer.quickshop.Util.AsyncDetector; import org.maxgamer.quickshop.Util.MsgUtil; import org.maxgamer.quickshop.Util.Util; @@ -398,20 +400,58 @@ public class ContainerShop implements Shop { if (!this.displayItem.isSpawned()) { /* Not spawned yet. */ Util.debugLog("Target item not spawned, spawning..."); - this.displayItem.spawn(); + if (!AsyncDetector.isAsync()) { + displayItem.spawn(); + } else { + new BukkitRunnable() { + @Override + public void run() { + displayItem.spawn(); + } + }.runTask(plugin); + } } else { /* If not spawned, we didn't need check these, only check them when we need. */ if (this.displayItem.checkDisplayNeedRegen()) { - this.displayItem.fixDisplayNeedRegen(); + if (!AsyncDetector.isAsync()) { + displayItem.fixDisplayNeedRegen(); + } else { + new BukkitRunnable() { + @Override + public void run() { + displayItem.fixDisplayNeedRegen(); + } + }.runTask(plugin); + } } else {/* If display was regened, we didn't need check it moved, performance! */ if (this.displayItem.checkDisplayIsMoved()) { - this.displayItem.fixDisplayMoved(); + if (!AsyncDetector.isAsync()) { + displayItem.fixDisplayMoved(); + } else { + new BukkitRunnable() { + @Override + public void run() { + displayItem.fixDisplayMoved(); + } + }.runTask(plugin); + } + } } } /* Dupe is always need check, if enabled display */ if (plugin.isDisplay()) { - this.displayItem.removeDupe(); + + if (!AsyncDetector.isAsync()) { + displayItem.removeDupe(); + } else { + new BukkitRunnable() { + @Override + public void run() { + displayItem.removeDupe(); + } + }.runTask(plugin); + } } }