From 2987ce00df3d410613ac2ad345f45738012ef586 Mon Sep 17 00:00:00 2001 From: Izzel_Aliz Date: Fri, 6 Jul 2018 20:31:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AA=81=E7=84=B6=E5=B0=B1=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BA=86=E5=8D=B3=E5=B0=86=E6=8E=A8=E5=87=BA=E7=9A=84=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ilummc/tlib/util/Ref.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/ilummc/tlib/util/Ref.java b/src/main/java/com/ilummc/tlib/util/Ref.java index 722af03..bd9c35b 100644 --- a/src/main/java/com/ilummc/tlib/util/Ref.java +++ b/src/main/java/com/ilummc/tlib/util/Ref.java @@ -2,9 +2,9 @@ package com.ilummc.tlib.util; import com.google.gson.annotations.SerializedName; import com.ilummc.tlib.TLib; -import com.ilummc.tlib.resources.TLocale; import com.ilummc.tlib.util.asm.AsmAnalyser; import me.skymc.taboolib.Main; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; @@ -99,15 +99,20 @@ public class Ref { return Optional.empty(); } - public static JavaPlugin getCallerPlugin(Class callerClass) { + public static Plugin getCallerPlugin(Class callerClass) { try { return JavaPlugin.getProvidingPlugin(callerClass); - } catch (IllegalArgumentException ignored) { - TLocale.Logger.error("LOCALE.CALLER-PLUGIN-NOT-FOUND", callerClass.getName()); - } catch (IllegalStateException e) { - TLocale.Logger.error("LOCALE.STATIC-CLASS-LOADER", callerClass.getName()); + } catch (Exception ignored) { + try { + ClassLoader loader = callerClass.getClassLoader(); + 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 {