测试上传
This commit is contained in:
parent
d8f8ffc5a3
commit
b22ade7cff
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -64,8 +64,6 @@ public class Main extends JavaPlugin implements Listener {
|
||||
@Getter
|
||||
private static File serverDataFolder;
|
||||
@Getter
|
||||
private static File docsFolder;
|
||||
@Getter
|
||||
private static StorageType storageType;
|
||||
@Getter
|
||||
private static boolean disable = false;
|
||||
@ -105,14 +103,12 @@ public class Main extends JavaPlugin implements Listener {
|
||||
@Override
|
||||
public void onLoad() {
|
||||
inst = this; disable = false;
|
||||
|
||||
TLib.init();
|
||||
|
||||
// 启动监控
|
||||
new Metrics(this);
|
||||
|
||||
// 载入配置
|
||||
saveDefaultConfig();
|
||||
|
||||
// 加载依赖
|
||||
TLib.init();
|
||||
|
||||
// 载入目录
|
||||
setupDataFolder();
|
||||
// 注册配置
|
||||
@ -218,6 +214,8 @@ public class Main extends JavaPlugin implements Listener {
|
||||
|
||||
// 更新检测
|
||||
new UpdateTask();
|
||||
// 启动监控
|
||||
new Metrics(this);
|
||||
|
||||
// 启动
|
||||
started = true;
|
||||
@ -286,16 +284,10 @@ public class Main extends JavaPlugin implements Listener {
|
||||
if (!playerDataFolder.exists()) {
|
||||
playerDataFolder.mkdirs();
|
||||
}
|
||||
|
||||
serverDataFolder = new File(getConfig().getString("DATAURL.SERVER-DATA"));
|
||||
if (!serverDataFolder.exists()) {
|
||||
serverDataFolder.mkdirs();
|
||||
}
|
||||
|
||||
docsFolder = new File(getDataFolder(), "Document");
|
||||
if (!docsFolder.exists()) {
|
||||
docsFolder.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
private void registerListener() {
|
||||
|
@ -76,9 +76,13 @@ public class ItemUtils {
|
||||
}
|
||||
|
||||
public static void LoadLib() {
|
||||
itemdir = YamlConfiguration.loadConfiguration(new File(Main.getInst().getConfig().getString("DATAURL.ITEMDIR")));
|
||||
reloadItemName();
|
||||
reloadItemCache();
|
||||
try {
|
||||
reloadItemName();
|
||||
reloadItemCache();
|
||||
itemdir = YamlConfiguration.loadConfiguration(new File(Main.getInst().getConfig().getString("DATAURL.ITEMDIR")));
|
||||
} catch (Exception e) {
|
||||
MsgUtils.warn("物品库载入失败: &4" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadItemsFile(File file, boolean finalFile) {
|
||||
@ -135,7 +139,6 @@ public class ItemUtils {
|
||||
return item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : itemlib.get(item.getType() + ":" + data) == null ? item.getType().toString() : itemlib.get(item.getType() + ":" + data);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static ItemStack getItemFromDir(String name) {
|
||||
if (itemdir != null) {
|
||||
return itemdir.getItemStack("item." + name);
|
||||
|
@ -2,6 +2,8 @@ package me.skymc.taboolib.string.language2;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.skymc.taboolib.string.language2.value.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -102,38 +104,39 @@ public class Language2Format implements Language2Line {
|
||||
return;
|
||||
}
|
||||
// 变量转换
|
||||
list = language2Value.setPlaceholder(list, player);
|
||||
List<String> listPlaceholder = language2Value.setPlaceholder(list, player);
|
||||
// 大标题
|
||||
switch (type) {
|
||||
case TITLE:
|
||||
language2Lines.add(new Language2Title(this, list));
|
||||
language2Lines.add(new Language2Title(this, listPlaceholder));
|
||||
break;
|
||||
// 小标题
|
||||
case ACTION:
|
||||
language2Lines.add(new Language2Action(this, list));
|
||||
language2Lines.add(new Language2Action(this, listPlaceholder));
|
||||
break;
|
||||
// JSON
|
||||
case JSON:
|
||||
language2Lines.add(new Language2Json(this, list, player));
|
||||
language2Lines.add(new Language2Json(this, listPlaceholder, player));
|
||||
break;
|
||||
// JSON2
|
||||
case JSON2:
|
||||
language2Lines.add(new Language2Json2(this, list, player));
|
||||
language2Lines.add(new Language2Json2(this, listPlaceholder, player));
|
||||
break;
|
||||
// 音效
|
||||
case SOUND:
|
||||
language2Lines.add(new Language2Sound(this, list));
|
||||
language2Lines.add(new Language2Sound(this, listPlaceholder));
|
||||
break;
|
||||
// 书本
|
||||
case BOOK:
|
||||
language2Lines.add(new Language2Book(this, list, player));
|
||||
language2Lines.add(new Language2Book(this, listPlaceholder, player));
|
||||
break;
|
||||
default:
|
||||
language2Lines.add(new Language2Text(this, list));
|
||||
language2Lines.add(new Language2Text(this, listPlaceholder));
|
||||
break;
|
||||
}
|
||||
// 清理数据
|
||||
list.clear();
|
||||
listPlaceholder.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,6 +17,10 @@ DATAURL:
|
||||
# 启用后将收到来自其他插件的调试信息
|
||||
DEBUG: false
|
||||
|
||||
# 是否启用离线模式
|
||||
# 离线模式下将不会下载依赖
|
||||
OFFLINE-MODE: false
|
||||
|
||||
# 是否启用更新检测
|
||||
UPDATE-CHECK: true
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user