mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-30 14:43:29 +01:00
Improve Bukkit identifyClassLoader (#2444)
This commit is contained in:
parent
361a4d66bc
commit
ee3bb22c2c
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user