Add AsyncDetector util.

Former-commit-id: 48eb70ebda9eff161be382df7ff466118352609f [formerly 42f868a96cf98f16a2994b73db37e93c45ed1a57]
Former-commit-id: 1781f1bfc688f613085d506d14771e7125230ba5
This commit is contained in:
Ghost_chu committed 2019-11-29 20:56:28 +08:00
1 parent 5ec7b79fad
commit 43b1b77e0f
1 file changed
+21
@@ -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;
}
}
}