修复:几个加载插件时的异常

This commit is contained in:
坏黑 2018-04-07 23:16:25 +08:00
parent b22ade7cff
commit 7758ac2241
3 changed files with 35 additions and 18 deletions

View File

@ -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;
}
}
}

View File

@ -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())

View File

@ -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) {
}
}
}