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; + } + + } +}