Improve Bukkit identifyClassLoader (#2444)

This commit is contained in:
Luck 2020-08-13 10:31:20 +01:00
parent 361a4d66bc
commit ee3bb22c2c
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -42,6 +42,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Method;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@ -282,9 +283,14 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
} }
@Override @Override
public @Nullable String identifyClassLoader(ClassLoader classLoader) { public @Nullable String identifyClassLoader(ClassLoader classLoader) throws ReflectiveOperationException {
if (classLoader instanceof org.bukkit.plugin.java.PluginClassLoader) { Class<?> pluginClassLoaderClass = Class.forName("org.bukkit.plugin.java.PluginClassLoader");
return ((org.bukkit.plugin.java.PluginClassLoader) classLoader).getPlugin().getName(); if (pluginClassLoaderClass.isInstance(classLoader)) {
Method getPluginMethod = pluginClassLoaderClass.getDeclaredMethod("getPlugin");
getPluginMethod.setAccessible(true);
JavaPlugin plugin = (JavaPlugin) getPluginMethod.invoke(classLoader);
return plugin.getName();
} }
return null; return null;
} }