From 43b1b77e0f405e57f64fe5c7fbf461fc0ac95368 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Fri, 29 Nov 2019 20:56:28 +0800 Subject: [PATCH] Add AsyncDetector util. Former-commit-id: 48eb70ebda9eff161be382df7ff466118352609f [formerly 42f868a96cf98f16a2994b73db37e93c45ed1a57] Former-commit-id: 1781f1bfc688f613085d506d14771e7125230ba5 --- .../quickshop/Util/AsyncDetector.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/org/maxgamer/quickshop/Util/AsyncDetector.java diff --git a/src/main/java/org/maxgamer/quickshop/Util/AsyncDetector.java b/src/main/java/org/maxgamer/quickshop/Util/AsyncDetector.java new file mode 100644 index 000000000..b277cb481 --- /dev/null +++ b/src/main/java/org/maxgamer/quickshop/Util/AsyncDetector.java @@ -0,0 +1,21 @@ +package org.maxgamer.quickshop.Util; + +import org.maxgamer.quickshop.QuickShop; + +public class AsyncDetector { + /** + * A helper to allow quickshop check the task is running under async thread. + * @return The calling method running under async thread. + */ + public static boolean isAsync() { + try { + Object serverInstance = Util.getNMSClass(null).getMethod("getServer").invoke(null); + Object serverThread = serverInstance.getClass().getField("serverThread"); + return Thread.currentThread() != serverThread; + }catch (Throwable throwable){ + QuickShop.instance.getLogger().warning("Failed to get Minecraft server instance, did you up-to-date the QuickShop?"); + return false; + } + + } +}