修复配置文件加载和保存失败

This commit is contained in:
Izzel_Aliz 2018-04-08 22:42:31 +08:00
parent 7758ac2241
commit 33905330f3
4 changed files with 55 additions and 56 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 = new TLibConfig();
private TLibConfig config;
private TConfigWatcher configWatcher = new TConfigWatcher();

View File

@ -41,16 +41,11 @@ public class TDependency {
TDependencyLoader.addToPath(Main.getInst(), file);
return true;
} else {
boolean downloadFinish = false;
try {
downloadFinish = downloadMaven(repo, arr[0], arr[1], arr[2], file, url);
} catch (Exception ignored) {
ignored.printStackTrace();
}
if (downloadFinish) {
if (downloadMaven(repo, arr[0], arr[1], arr[2], file, url)) {
TDependencyLoader.addToPath(Main.getInst(), file);
}
return downloadFinish;
return true;
} else
return false;
}
}
return false;
@ -63,11 +58,14 @@ public class TDependency {
}
ReentrantLock lock = new ReentrantLock();
AtomicBoolean failed = new AtomicBoolean(false);
String link = dl.length() == 0 ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl;
EagletTask task = new EagletTask()
.url(dl.length() == 0 ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl)
.url(link)
.file(target)
.setThreads(TLib.getTLib().getConfig().getDownloadPoolSize())
.setOnStart(event -> lock.lock())
.setOnError(event -> {
})
.setOnConnected(event -> TLib.getTLib().getLogger().info(" 正在下载 " + String.join(":",
new String[]{groupId, artifactId, version}) +
" 大小 " + ProgressEvent.format(event.getContentLength())))
@ -78,6 +76,8 @@ public class TDependency {
TLib.getTLib().getLogger().info(" 下载 " + String.join(":", new String[]{groupId, artifactId, version}) + " 完成");
} else {
failed.set(true);
TLib.getTLib().getLogger().error(" 下载 " + String.join(":", new String[]{groupId, artifactId, version}) + " 失败");
TLib.getTLib().getLogger().error(" 请手动下载 " + link + " 并重命名为 " + target.getName() + " 后放在 /TabooLib/libs 文件夹内");
}
lock.unlock();
});

View File

@ -15,11 +15,11 @@ public class DependencyInjector {
public static void inject(Plugin plugin, Object o) {
try {
injectConfig(plugin, o);
injectLogger(plugin, o);
} catch (NoClassDefFoundError ignored) {
}
try {
injectLogger(plugin, o);
injectConfig(plugin, o);
} catch (NoClassDefFoundError ignored) {
}
try {
@ -37,10 +37,7 @@ public class DependencyInjector {
}
static void onDisable(Plugin plugin) {
try {
ejectConfig(plugin, plugin);
} catch (NoClassDefFoundError ignored) {
}
eject(plugin, plugin);
}
public static void eject(Plugin plugin, Object o) {
@ -56,10 +53,11 @@ public class DependencyInjector {
if ((config = field.getType().getAnnotation(Config.class)) != null) {
try {
field.setAccessible(true);
TConfigInjector.saveConfig(plugin, o);
TConfigInjector.saveConfig(plugin, field.get(o));
TLib.getTLib().getLogger().info("插件 " + plugin + " 的配置 " + config.name() + " 已保存");
} catch (Exception e) {
TLib.getTLib().getLogger().warn("插件 " + plugin + " 的配置 " + config.name() + " 保存失败");
e.printStackTrace();
}
}
}
@ -143,7 +141,8 @@ public class DependencyInjector {
}
private static void injectDependencies(Plugin plugin, Object o) {
Dependency[] dependencies = new Dependency[0]; {
Dependency[] dependencies = new Dependency[0];
{
Dependencies d = o.getClass().getAnnotation(Dependencies.class);
if (d != null) {
dependencies = d.value();

View File

@ -31,7 +31,7 @@ public class TConfigInjector {
Validate.notNull(config);
File file = new File(plugin.getDataFolder(), config.name());
if (!file.exists()) if (config.fromJar()) plugin.saveResource(config.name(), true);
else saveConfig(plugin, clazz);
else saveConfig(plugin, clazz.newInstance());
return unserialize(plugin, clazz);
} catch (NullPointerException e) {
TLib.getTLib().getLogger().warn("插件 " + plugin + " 的配置类 " + clazz.getSimpleName() + " 加载失败:没有 @Config 注解");