突然就支持了即将推出的脚本插件
This commit is contained in:
parent
81fb265a8f
commit
2987ce00df
@ -2,9 +2,9 @@ package com.ilummc.tlib.util;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import com.ilummc.tlib.TLib;
|
import com.ilummc.tlib.TLib;
|
||||||
import com.ilummc.tlib.resources.TLocale;
|
|
||||||
import com.ilummc.tlib.util.asm.AsmAnalyser;
|
import com.ilummc.tlib.util.asm.AsmAnalyser;
|
||||||
import me.skymc.taboolib.Main;
|
import me.skymc.taboolib.Main;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
@ -99,15 +99,20 @@ public class Ref {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JavaPlugin getCallerPlugin(Class<?> callerClass) {
|
public static Plugin getCallerPlugin(Class<?> callerClass) {
|
||||||
try {
|
try {
|
||||||
return JavaPlugin.getProvidingPlugin(callerClass);
|
return JavaPlugin.getProvidingPlugin(callerClass);
|
||||||
} catch (IllegalArgumentException ignored) {
|
} catch (Exception ignored) {
|
||||||
TLocale.Logger.error("LOCALE.CALLER-PLUGIN-NOT-FOUND", callerClass.getName());
|
try {
|
||||||
} catch (IllegalStateException e) {
|
ClassLoader loader = callerClass.getClassLoader();
|
||||||
TLocale.Logger.error("LOCALE.STATIC-CLASS-LOADER", callerClass.getName());
|
Field pluginF = loader.getClass().getDeclaredField("plugin");
|
||||||
|
pluginF.setAccessible(true);
|
||||||
|
Object o = pluginF.get(loader);
|
||||||
|
return (JavaPlugin) o;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Main.getInst();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return (JavaPlugin) Main.getInst();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static abstract class CallerClass {
|
private static abstract class CallerClass {
|
||||||
|
Loading…
Reference in New Issue
Block a user