From 7758ac22411641763dd2dd62d73be99a4494298b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sat, 7 Apr 2018 23:16:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=87=A0=E4=B8=AA?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E6=8F=92=E4=BB=B6=E6=97=B6=E7=9A=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ilummc/tlib/TLib.java | 3 +- .../ilummc/tlib/dependency/TDependency.java | 3 +- .../tlib/inject/DependencyInjector.java | 47 +++++++++++++------ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/ilummc/tlib/TLib.java b/src/main/java/com/ilummc/tlib/TLib.java index 8a5ac8a..f16f01c 100644 --- a/src/main/java/com/ilummc/tlib/TLib.java +++ b/src/main/java/com/ilummc/tlib/TLib.java @@ -22,7 +22,7 @@ public class TLib { @Logger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}") private TLogger tLogger; - private TLibConfig config; + private TLibConfig config = new TLibConfig(); private TConfigWatcher configWatcher = new TConfigWatcher(); @@ -75,5 +75,4 @@ public class TLib { return downloadPoolSize; } } - } diff --git a/src/main/java/com/ilummc/tlib/dependency/TDependency.java b/src/main/java/com/ilummc/tlib/dependency/TDependency.java index e15e975..3987e25 100644 --- a/src/main/java/com/ilummc/tlib/dependency/TDependency.java +++ b/src/main/java/com/ilummc/tlib/dependency/TDependency.java @@ -45,6 +45,7 @@ public class TDependency { try { downloadFinish = downloadMaven(repo, arr[0], arr[1], arr[2], file, url); } catch (Exception ignored) { + ignored.printStackTrace(); } if (downloadFinish) { TDependencyLoader.addToPath(Main.getInst(), file); @@ -63,7 +64,7 @@ public class TDependency { ReentrantLock lock = new ReentrantLock(); AtomicBoolean failed = new AtomicBoolean(false); EagletTask task = new EagletTask() - .url(dl == null ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl) + .url(dl.length() == 0 ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl) .file(target) .setThreads(TLib.getTLib().getConfig().getDownloadPoolSize()) .setOnStart(event -> lock.lock()) diff --git a/src/main/java/com/ilummc/tlib/inject/DependencyInjector.java b/src/main/java/com/ilummc/tlib/inject/DependencyInjector.java index dc98f4c..bcf97e8 100644 --- a/src/main/java/com/ilummc/tlib/inject/DependencyInjector.java +++ b/src/main/java/com/ilummc/tlib/inject/DependencyInjector.java @@ -9,16 +9,27 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; -import java.io.IOException; import java.lang.reflect.Field; public class DependencyInjector { public static void inject(Plugin plugin, Object o) { - injectLogger(plugin, o); - injectPluginInstance(plugin, o); - injectDependencies(plugin, o); - injectConfig(plugin, o); + try { + injectConfig(plugin, o); + } catch (NoClassDefFoundError ignored) { + } + try { + injectLogger(plugin, o); + } catch (NoClassDefFoundError ignored) { + } + try { + injectPluginInstance(plugin, o); + } catch (NoClassDefFoundError ignored) { + } + try { + injectDependencies(plugin, o); + } catch (NoClassDefFoundError ignored) { + } } static void injectOnEnable(Plugin plugin) { @@ -26,11 +37,17 @@ public class DependencyInjector { } static void onDisable(Plugin plugin) { - ejectConfig(plugin, plugin); + try { + ejectConfig(plugin, plugin); + } catch (NoClassDefFoundError ignored) { + } } public static void eject(Plugin plugin, Object o) { - ejectConfig(plugin, o); + try { + ejectConfig(plugin, o); + } catch (NoClassDefFoundError ignored) { + } } private static void ejectConfig(Plugin plugin, Object o) { @@ -79,7 +96,7 @@ public class DependencyInjector { } } } - } catch (IllegalAccessException ignored) { + } catch (Exception ignored) { } } } @@ -95,15 +112,15 @@ public class DependencyInjector { field.setAccessible(true); field.set(o, tLogger); } - } catch (Exception ignored) { - } + } catch (Exception ignored2) { + } } } private static void injectPluginInstance(Plugin plugin, Object o) { - try { - for (Field field : o.getClass().getDeclaredFields()) { - PluginInstance instance; + for (Field field : o.getClass().getDeclaredFields()) { + try { + PluginInstance instance; if ((instance = field.getAnnotation(PluginInstance.class)) != null) { if (!field.isAccessible()) field.setAccessible(true); @@ -120,8 +137,8 @@ public class DependencyInjector { if (pl != null) field.set(o, pl); } - } - } catch (Exception ignored) { + } catch (Exception ignored) { + } } }