Fix class source validator on spigot.

This commit is contained in:
wizjany 2022-03-06 08:59:44 -05:00
parent 27dca2b506
commit 216b061172
No known key found for this signature in database
GPG Key ID: 1DB5861C03B76B5E
1 changed files with 6 additions and 3 deletions

View File

@ -47,14 +47,17 @@ public class ClassSourceValidator {
private static final String SEPARATOR_LINE = Strings.repeat("*", 46);
private static final Method loadClass;
private static Class<?> pluginClassLoaderClass;
static {
Method tmp;
try {
tmp = PluginClassLoader.class.getDeclaredMethod("loadClass0",
pluginClassLoaderClass = Class.forName("org.bukkit.plugin.java.PluginClassLoader", false,
Bukkit.class.getClassLoader());
tmp = pluginClassLoaderClass.getDeclaredMethod("loadClass0",
String.class, boolean.class, boolean.class, boolean.class);
tmp.setAccessible(true);
} catch (NoSuchMethodException e) {
} catch (NoSuchMethodException | ClassNotFoundException e) {
tmp = null;
}
loadClass = tmp;
@ -95,7 +98,7 @@ public class ClassSourceValidator {
continue;
}
ClassLoader targetLoader = target.getClass().getClassLoader();
if (!(targetLoader instanceof PluginClassLoader)) {
if (!(pluginClassLoaderClass.isAssignableFrom(targetLoader.getClass()))) {
continue;
}
for (Class<?> testClass : classes) {