Compare commits

..

7 commits

7 changed files with 36 additions and 64 deletions

View file

@ -30,14 +30,6 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
</exclusion>
<exclusion>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</exclusion>
<exclusion> <exclusion>
<groupId>com.googlecode.json-simple</groupId> <groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId> <artifactId>json-simple</artifactId>
@ -59,7 +51,7 @@
<dependency> <dependency>
<groupId>com.mojang</groupId> <groupId>com.mojang</groupId>
<artifactId>authlib</artifactId> <artifactId>authlib</artifactId>
<version>6.0.54</version> <version>6.0.58</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -25,9 +25,6 @@ import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; 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 { public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Listener, PreparedPlugin {
protected final Path dataDirectory; protected final Path dataDirectory;
@ -35,8 +32,6 @@ public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Liste
protected final Language language = new Language(); protected final Language language = new Language();
protected final SqlAdapter sqlAdapter = createSqlAdapter(); protected final SqlAdapter sqlAdapter = createSqlAdapter();
private ExecutorService singleThreadExecutor;
public BukkitPreparedPlugin() { public BukkitPreparedPlugin() {
super(); super();
dataDirectory = getDataFolder().toPath(); dataDirectory = getDataFolder().toPath();
@ -178,10 +173,6 @@ public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Liste
closeSqlAdapter(); closeSqlAdapter();
defaultConfig.clear(); defaultConfig.clear();
if (singleThreadExecutor != null) {
singleThreadExecutor.shutdownNow();
}
BukkitUtils.unregisterCommandIf(command -> command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) command).getPlugin() == this); BukkitUtils.unregisterCommandIf(command -> command instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) command).getPlugin() == this);
} }
@ -195,18 +186,4 @@ public abstract class BukkitPreparedPlugin extends BukkitPlugin implements Liste
disable(); 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);
}
});
}
} }

View file

@ -54,7 +54,12 @@ class BukkitReflectionUtils {
private static class ModernGameProfileConsumer implements GameProfileConsumer { private static class ModernGameProfileConsumer implements GameProfileConsumer {
private final Class<?> __ResolvableProfile_CLASS = ReflectionUtils.getType("net.minecraft.world.item.component.ResolvableProfile"); private final Class<?> __ResolvableProfile_CLASS = ReflectionUtils.getType("net.minecraft.world.item.component.ResolvableProfile");
private final Constructor<?> __ResolvableProfile_CONSTRUCTOR; private final Constructor<?> __ResolvableProfile_CONSTRUCTOR;
protected final Method __setProfile__CraftMetaSkull__METHOD = ReflectionUtils.getMethod(__ResolvableProfile_CLASS, "setProfile", __ResolvableProfile_CLASS); protected final Method __setProfile__CraftMetaSkull__METHOD = ReflectionUtils.methodSearcher()
.type(__CraftMetaSkull__CLASS)
.methodOf("setProfile")
.parameters(__ResolvableProfile_CLASS)
.returns(void.class)
.search();
ModernGameProfileConsumer() { ModernGameProfileConsumer() {
Constructor<?> resolvableConstructor; Constructor<?> resolvableConstructor;

View file

@ -5,7 +5,9 @@ import org.zhdev.reflection.MethodSearcher;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -25,6 +27,12 @@ public class ReflectionUtils {
return field; 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) { private static boolean compareParameters(Class<?>[] required, Class<?>... parameters) {
if (required.length != parameters.length) { if (required.length != parameters.length) {
return false; return false;
@ -174,6 +182,22 @@ 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<Class<?>> consumer) { public static void forEachClass(ClassLoader loader, JarFile jarFile, String packageName, Consumer<Class<?>> consumer) {
for (Enumeration<JarEntry> entry = jarFile.entries(); entry.hasMoreElements(); ) { for (Enumeration<JarEntry> entry = jarFile.entries(); entry.hasMoreElements(); ) {
JarEntry jarEntry = entry.nextElement(); JarEntry jarEntry = entry.nextElement();

View file

@ -23,19 +23,19 @@
<groupId>org.xerial</groupId> <groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>3.42.0.0</version> <version>3.42.0.0</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>2.2.220</version> <version>2.2.220</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.mysql</groupId> <groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId> <artifactId>mysql-connector-j</artifactId>
<version>8.2.0</version> <version>9.2.0</version>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

26
pom.xml
View file

@ -52,32 +52,6 @@
<target>8</target> <target>8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>

View file

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.velocitypowered</groupId> <groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId> <artifactId>velocity-api</artifactId>
<version>3.1.2-SNAPSHOT</version> <version>3.4.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>