测试上传
This commit is contained in:
@@ -19,7 +19,7 @@ public class TLib {
|
||||
|
||||
private static TLib tLib;
|
||||
|
||||
@Logger("§3[§6TLib§3|{1}§3] §f{2}")
|
||||
@Logger("§8[§3§lTabooLib§8][§r{1}§8] §f{2}")
|
||||
private TLogger tLogger;
|
||||
|
||||
private TLibConfig config;
|
||||
@@ -45,7 +45,6 @@ public class TLib {
|
||||
return tLib;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static void init() {
|
||||
new File(Main.getInst().getDataFolder(), "/libs").mkdirs();
|
||||
tLib = new TLib();
|
||||
|
||||
@@ -40,20 +40,30 @@ public class TDependency {
|
||||
if (file.exists()) {
|
||||
TDependencyLoader.addToPath(Main.getInst(), file);
|
||||
return true;
|
||||
} else if (downloadMaven(repo, arr[0], arr[1], arr[2], file, url)) {
|
||||
TDependencyLoader.addToPath(Main.getInst(), file);
|
||||
return true;
|
||||
} else return false;
|
||||
} else {
|
||||
boolean downloadFinish = false;
|
||||
try {
|
||||
downloadFinish = downloadMaven(repo, arr[0], arr[1], arr[2], file, url);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
if (downloadFinish) {
|
||||
TDependencyLoader.addToPath(Main.getInst(), file);
|
||||
}
|
||||
return downloadFinish;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean downloadMaven(String url, String groupId, String artifactId, String version, File target, String dl) {
|
||||
if (Main.getInst().getConfig().getBoolean("OFFLINE-MODE")) {
|
||||
TLib.getTLib().getLogger().warn("已启用离线模式, 将不会下载第三方依赖库");
|
||||
return false;
|
||||
}
|
||||
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 == null ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl)
|
||||
.file(target)
|
||||
.setThreads(TLib.getTLib().getConfig().getDownloadPoolSize())
|
||||
.setOnStart(event -> lock.lock())
|
||||
|
||||
@@ -15,10 +15,10 @@ 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);
|
||||
injectLogger(plugin, o);
|
||||
injectPluginInstance(plugin, o);
|
||||
injectDependencies(plugin, o);
|
||||
injectConfig(plugin, o);
|
||||
}
|
||||
|
||||
static void injectOnEnable(Plugin plugin) {
|
||||
@@ -41,7 +41,7 @@ public class DependencyInjector {
|
||||
field.setAccessible(true);
|
||||
TConfigInjector.saveConfig(plugin, o);
|
||||
TLib.getTLib().getLogger().info("插件 " + plugin + " 的配置 " + config.name() + " 已保存");
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
TLib.getTLib().getLogger().warn("插件 " + plugin + " 的配置 " + config.name() + " 保存失败");
|
||||
}
|
||||
}
|
||||
@@ -85,9 +85,9 @@ public class DependencyInjector {
|
||||
}
|
||||
|
||||
private static void injectLogger(Plugin plugin, Object o) {
|
||||
for (Field field : o.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
Logger logger;
|
||||
for (Field field : o.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
Logger logger;
|
||||
if ((logger = field.getAnnotation(Logger.class)) != null) {
|
||||
field.getType().asSubclass(TLogger.class);
|
||||
TLogger tLogger = new TLogger(logger.value(), plugin, logger.level());
|
||||
@@ -97,7 +97,7 @@ public class DependencyInjector {
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void injectPluginInstance(Plugin plugin, Object o) {
|
||||
@@ -126,28 +126,33 @@ 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();
|
||||
if (d != null) {
|
||||
dependencies = d.value();
|
||||
}
|
||||
Dependency d2 = o.getClass().getAnnotation(Dependency.class);
|
||||
if (d2 != null) dependencies = new Dependency[]{d2};
|
||||
if (d2 != null) {
|
||||
dependencies = new Dependency[]{d2};
|
||||
}
|
||||
}
|
||||
if (dependencies.length != 0) {
|
||||
TLib.getTLib().getLogger().info("正在加载 " + plugin.getName() + " 插件所需的依赖");
|
||||
for (Dependency dependency : dependencies) {
|
||||
if (dependency.type() == Dependency.Type.PLUGIN)
|
||||
if (TDependency.requestPlugin(dependency.plugin()))
|
||||
if (dependency.type() == Dependency.Type.PLUGIN) {
|
||||
if (TDependency.requestPlugin(dependency.plugin())) {
|
||||
TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的插件 " + dependency.plugin() + " 加载成功。");
|
||||
else
|
||||
} else {
|
||||
TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的插件 " + dependency.plugin() + " 加载失败。");
|
||||
if (dependency.type() == Dependency.Type.LIBRARY)
|
||||
if (TDependency.requestLib(dependency.maven(), dependency.mavenRepo(), dependency.url()))
|
||||
TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的库文件 " + String.join(":",
|
||||
dependency.maven()) + " 加载成功。");
|
||||
else
|
||||
TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的库文件 " + String.join(":",
|
||||
dependency.maven()) + " 加载失败。");
|
||||
}
|
||||
}
|
||||
if (dependency.type() == Dependency.Type.LIBRARY) {
|
||||
if (TDependency.requestLib(dependency.maven(), dependency.mavenRepo(), dependency.url())) {
|
||||
TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的库文件 " + String.join(":", dependency.maven()) + " 加载成功。");
|
||||
} else {
|
||||
TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的库文件 " + String.join(":", dependency.maven()) + " 加载失败。");
|
||||
}
|
||||
}
|
||||
}
|
||||
TLib.getTLib().getLogger().info("依赖加载完成");
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class TConfigInjector {
|
||||
Files.write(arr, target);
|
||||
}
|
||||
|
||||
private static final List<Class> primitiveType = Lists.newArrayList(Integer.class,
|
||||
private static final List<Class<?>> primitiveType = Lists.newArrayList(Integer.class,
|
||||
Double.class, Float.class, Boolean.class, Short.class, Byte.class, Character.class, Long.class, String.class);
|
||||
|
||||
private static class Serializer {
|
||||
@@ -118,13 +118,13 @@ public class TConfigInjector {
|
||||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private Object serialize(Object o) {
|
||||
try {
|
||||
if (o.getClass().isPrimitive() || primitiveType.contains(o.getClass())) {
|
||||
return o;
|
||||
} else if (o.getClass().isArray()) {
|
||||
List list = new ArrayList();
|
||||
List list = new ArrayList<>();
|
||||
int len = (int) o.getClass().getField("length").get(o);
|
||||
for (int i = 0; i < len; i++) {
|
||||
list.add(serialize(Array.get(o, i)));
|
||||
@@ -133,11 +133,11 @@ public class TConfigInjector {
|
||||
} else if (o instanceof Collection) {
|
||||
return ((Collection) o).stream().map(this::serialize).collect(Collectors.toList());
|
||||
} else if (o instanceof Map) {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
Map map = new LinkedHashMap<>();
|
||||
((Map) o).forEach((o1, o2) -> map.put((String) o1, serialize(o2)));
|
||||
return map;
|
||||
} else if (o instanceof ConfigurationSerializable) {
|
||||
Map map = new LinkedHashMap();
|
||||
Map map = new LinkedHashMap<>();
|
||||
map.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY,
|
||||
ConfigurationSerialization.getAlias((Class<? extends ConfigurationSerializable>) o.getClass()));
|
||||
map.putAll(((ConfigurationSerializable) o).serialize());
|
||||
|
||||
@@ -47,17 +47,17 @@ public class TLogger {
|
||||
|
||||
public void warn(String msg) {
|
||||
if (level <= WARN)
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§6警告", msg));
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§6警告", "§6" + msg));
|
||||
}
|
||||
|
||||
public void error(String msg) {
|
||||
if (level <= ERROR)
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§c错误", msg));
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§c错误", "§c" + msg));
|
||||
}
|
||||
|
||||
public void fatal(String msg) {
|
||||
if (level <= FATAL)
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§4致命错误", msg));
|
||||
Bukkit.getConsoleSender().sendMessage(Strings.replaceWithOrder(pattern, plugin.getName(), "§4致命错误", "§4" + msg));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user