diff --git a/bukkit/pom.xml b/bukkit/pom.xml index b27a3b5..e1d72ef 100644 --- a/bukkit/pom.xml +++ b/bukkit/pom.xml @@ -30,6 +30,14 @@ ${project.version} compile + + org.xerial + sqlite-jdbc + + + com.mysql + mysql-connector-j + com.googlecode.json-simple json-simple @@ -51,7 +59,7 @@ com.mojang authlib - 6.0.58 + 6.0.54 provided diff --git a/bukkit/src/main/java/org/zhdev/BukkitPreparedPlugin.java b/bukkit/src/main/java/org/zhdev/BukkitPreparedPlugin.java index 109fd6f..daf8da1 100644 --- a/bukkit/src/main/java/org/zhdev/BukkitPreparedPlugin.java +++ b/bukkit/src/main/java/org/zhdev/BukkitPreparedPlugin.java @@ -25,6 +25,9 @@ import java.io.File; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.logging.Level; public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Listener, PreparedPlugin { protected final Path dataDirectory; @@ -32,6 +35,8 @@ public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Liste protected final Language language = new Language(); protected final SqlAdapter sqlAdapter = createSqlAdapter(); + private ExecutorService singleThreadExecutor; + public BukkitPreparedPlugin() { super(); dataDirectory = getDataFolder().toPath(); @@ -173,6 +178,10 @@ public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Liste closeSqlAdapter(); defaultConfig.clear(); + if (singleThreadExecutor != null) { + singleThreadExecutor.shutdownNow(); + } + BukkitUtils.unregisterCommandIf(command -> command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) command).getPlugin() == this); } @@ -186,4 +195,18 @@ public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Liste disable(); } } + + public void runTaskSeparately(Runnable runnable) { + if (singleThreadExecutor == null) { + singleThreadExecutor = Executors.newSingleThreadExecutor(); + } + + singleThreadExecutor.execute(() -> { + try { + runnable.run(); + } catch (Throwable throwable) { + getLogger().log(Level.SEVERE, "Unhandled exception while running separated task", throwable); + } + }); + } } diff --git a/bukkit/src/main/java/org/zhdev/util/BukkitReflectionUtils.java b/bukkit/src/main/java/org/zhdev/util/BukkitReflectionUtils.java index b50cb74..ccd093b 100644 --- a/bukkit/src/main/java/org/zhdev/util/BukkitReflectionUtils.java +++ b/bukkit/src/main/java/org/zhdev/util/BukkitReflectionUtils.java @@ -54,12 +54,7 @@ class BukkitReflectionUtils { private static class ModernGameProfileConsumer implements GameProfileConsumer { private final Class __ResolvableProfile_CLASS = ReflectionUtils.getType("net.minecraft.world.item.component.ResolvableProfile"); private final Constructor __ResolvableProfile_CONSTRUCTOR; - protected final Method __setProfile__CraftMetaSkull__METHOD = ReflectionUtils.methodSearcher() - .type(__CraftMetaSkull__CLASS) - .methodOf("setProfile") - .parameters(__ResolvableProfile_CLASS) - .returns(void.class) - .search(); + protected final Method __setProfile__CraftMetaSkull__METHOD = ReflectionUtils.getMethod(__ResolvableProfile_CLASS, "setProfile", __ResolvableProfile_CLASS); ModernGameProfileConsumer() { Constructor resolvableConstructor; diff --git a/common/src/main/java/org/zhdev/util/ReflectionUtils.java b/common/src/main/java/org/zhdev/util/ReflectionUtils.java index 900761e..dd71599 100644 --- a/common/src/main/java/org/zhdev/util/ReflectionUtils.java +++ b/common/src/main/java/org/zhdev/util/ReflectionUtils.java @@ -5,9 +5,7 @@ import org.zhdev.reflection.MethodSearcher; import java.io.File; import java.io.IOException; -import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Enumeration; import java.util.function.Consumer; @@ -27,12 +25,6 @@ public class ReflectionUtils { return field; } - private static Constructor getConstructor0(Class type, Class... parameterTypes) throws NoSuchMethodException { - Constructor constructor = type.getDeclaredConstructor(parameterTypes); - constructor.setAccessible(true); - return constructor; - } - private static boolean compareParameters(Class[] required, Class... parameters) { if (required.length != parameters.length) { return false; @@ -182,22 +174,6 @@ public class ReflectionUtils { } } - public static Constructor getConstructor(Class type, Class... parameterTypes) throws NoSuchMethodError { - try { - return getConstructor0(type, parameterTypes); - } catch (NoSuchMethodException e) { - throw new NoSuchMethodError(e.getMessage()); - } - } - - public static Object newInstance(Constructor constructor, Object... args) throws NoSuchMethodError { - try { - return constructor.newInstance(args); - } catch (ReflectiveOperationException e) { - throw new IllegalStateException(e); - } - } - public static void forEachClass(ClassLoader loader, JarFile jarFile, String packageName, Consumer> consumer) { for (Enumeration entry = jarFile.entries(); entry.hasMoreElements(); ) { JarEntry jarEntry = entry.nextElement(); diff --git a/db/pom.xml b/db/pom.xml index d594c22..1b61707 100644 --- a/db/pom.xml +++ b/db/pom.xml @@ -23,19 +23,19 @@ org.xerial sqlite-jdbc 3.42.0.0 - provided + compile com.h2database h2 2.2.220 - provided + compile com.mysql mysql-connector-j - 9.2.0 - provided + 8.2.0 + compile \ No newline at end of file diff --git a/pom.xml b/pom.xml index 73089a6..2c4bb9d 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,32 @@ 8 + + org.apache.maven.plugins + maven-shade-plugin + 3.5.3 + + + + *:* + + META-INF/** + + + + true + false + true + + + + package + + shade + + + + org.apache.maven.plugins maven-jar-plugin diff --git a/velocity/pom.xml b/velocity/pom.xml index e246a2d..32aa20e 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -29,7 +29,7 @@ com.velocitypowered velocity-api - 3.4.0-SNAPSHOT + 3.1.2-SNAPSHOT provided