测试上传
This commit is contained in:
parent
d8f8ffc5a3
commit
b22ade7cff
@ -19,7 +19,7 @@ public class TLib {
|
|||||||
|
|
||||||
private static TLib 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 TLogger tLogger;
|
||||||
|
|
||||||
private TLibConfig config;
|
private TLibConfig config;
|
||||||
@ -45,7 +45,6 @@ public class TLib {
|
|||||||
return tLib;
|
return tLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
new File(Main.getInst().getDataFolder(), "/libs").mkdirs();
|
new File(Main.getInst().getDataFolder(), "/libs").mkdirs();
|
||||||
tLib = new TLib();
|
tLib = new TLib();
|
||||||
|
@ -40,20 +40,30 @@ public class TDependency {
|
|||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
TDependencyLoader.addToPath(Main.getInst(), file);
|
TDependencyLoader.addToPath(Main.getInst(), file);
|
||||||
return true;
|
return true;
|
||||||
} else if (downloadMaven(repo, arr[0], arr[1], arr[2], file, url)) {
|
} else {
|
||||||
TDependencyLoader.addToPath(Main.getInst(), file);
|
boolean downloadFinish = false;
|
||||||
return true;
|
try {
|
||||||
} else return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean downloadMaven(String url, String groupId, String artifactId, String version, File target, String dl) {
|
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();
|
ReentrantLock lock = new ReentrantLock();
|
||||||
AtomicBoolean failed = new AtomicBoolean(false);
|
AtomicBoolean failed = new AtomicBoolean(false);
|
||||||
EagletTask task = new EagletTask()
|
EagletTask task = new EagletTask()
|
||||||
.url(dl == null ? url + "/" + groupId.replace('.', '/') + "/" +
|
.url(dl == null ? url + "/" + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl)
|
||||||
artifactId + "/" + version + "/" + artifactId + "-" + version + ".jar" : dl)
|
|
||||||
.file(target)
|
.file(target)
|
||||||
.setThreads(TLib.getTLib().getConfig().getDownloadPoolSize())
|
.setThreads(TLib.getTLib().getConfig().getDownloadPoolSize())
|
||||||
.setOnStart(event -> lock.lock())
|
.setOnStart(event -> lock.lock())
|
||||||
|
@ -15,10 +15,10 @@ import java.lang.reflect.Field;
|
|||||||
public class DependencyInjector {
|
public class DependencyInjector {
|
||||||
|
|
||||||
public static void inject(Plugin plugin, Object o) {
|
public static void inject(Plugin plugin, Object o) {
|
||||||
injectLogger(plugin, o);
|
injectLogger(plugin, o);
|
||||||
injectPluginInstance(plugin, o);
|
injectPluginInstance(plugin, o);
|
||||||
injectDependencies(plugin, o);
|
injectDependencies(plugin, o);
|
||||||
injectConfig(plugin, o);
|
injectConfig(plugin, o);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void injectOnEnable(Plugin plugin) {
|
static void injectOnEnable(Plugin plugin) {
|
||||||
@ -41,7 +41,7 @@ public class DependencyInjector {
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
TConfigInjector.saveConfig(plugin, o);
|
TConfigInjector.saveConfig(plugin, o);
|
||||||
TLib.getTLib().getLogger().info("插件 " + plugin + " 的配置 " + config.name() + " 已保存");
|
TLib.getTLib().getLogger().info("插件 " + plugin + " 的配置 " + config.name() + " 已保存");
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
TLib.getTLib().getLogger().warn("插件 " + plugin + " 的配置 " + config.name() + " 保存失败");
|
TLib.getTLib().getLogger().warn("插件 " + plugin + " 的配置 " + config.name() + " 保存失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,9 +85,9 @@ public class DependencyInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void injectLogger(Plugin plugin, Object o) {
|
private static void injectLogger(Plugin plugin, Object o) {
|
||||||
for (Field field : o.getClass().getDeclaredFields()) {
|
for (Field field : o.getClass().getDeclaredFields()) {
|
||||||
try {
|
try {
|
||||||
Logger logger;
|
Logger logger;
|
||||||
if ((logger = field.getAnnotation(Logger.class)) != null) {
|
if ((logger = field.getAnnotation(Logger.class)) != null) {
|
||||||
field.getType().asSubclass(TLogger.class);
|
field.getType().asSubclass(TLogger.class);
|
||||||
TLogger tLogger = new TLogger(logger.value(), plugin, logger.level());
|
TLogger tLogger = new TLogger(logger.value(), plugin, logger.level());
|
||||||
@ -97,7 +97,7 @@ public class DependencyInjector {
|
|||||||
}
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void injectPluginInstance(Plugin plugin, Object o) {
|
private static void injectPluginInstance(Plugin plugin, Object o) {
|
||||||
@ -126,28 +126,33 @@ public class DependencyInjector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void injectDependencies(Plugin plugin, Object o) {
|
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);
|
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);
|
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) {
|
if (dependencies.length != 0) {
|
||||||
TLib.getTLib().getLogger().info("正在加载 " + plugin.getName() + " 插件所需的依赖");
|
TLib.getTLib().getLogger().info("正在加载 " + plugin.getName() + " 插件所需的依赖");
|
||||||
for (Dependency dependency : dependencies) {
|
for (Dependency dependency : dependencies) {
|
||||||
if (dependency.type() == Dependency.Type.PLUGIN)
|
if (dependency.type() == Dependency.Type.PLUGIN) {
|
||||||
if (TDependency.requestPlugin(dependency.plugin()))
|
if (TDependency.requestPlugin(dependency.plugin())) {
|
||||||
TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的插件 " + dependency.plugin() + " 加载成功。");
|
TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的插件 " + dependency.plugin() + " 加载成功。");
|
||||||
else
|
} else {
|
||||||
TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的插件 " + dependency.plugin() + " 加载失败。");
|
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(":",
|
if (dependency.type() == Dependency.Type.LIBRARY) {
|
||||||
dependency.maven()) + " 加载成功。");
|
if (TDependency.requestLib(dependency.maven(), dependency.mavenRepo(), dependency.url())) {
|
||||||
else
|
TLib.getTLib().getLogger().info(" " + plugin.getName() + " 请求的库文件 " + String.join(":", dependency.maven()) + " 加载成功。");
|
||||||
TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的库文件 " + String.join(":",
|
} else {
|
||||||
dependency.maven()) + " 加载失败。");
|
TLib.getTLib().getLogger().warn(" " + plugin.getName() + " 请求的库文件 " + String.join(":", dependency.maven()) + " 加载失败。");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TLib.getTLib().getLogger().info("依赖加载完成");
|
TLib.getTLib().getLogger().info("依赖加载完成");
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ public class TConfigInjector {
|
|||||||
Files.write(arr, target);
|
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);
|
Double.class, Float.class, Boolean.class, Short.class, Byte.class, Character.class, Long.class, String.class);
|
||||||
|
|
||||||
private static class Serializer {
|
private static class Serializer {
|
||||||
@ -118,13 +118,13 @@ public class TConfigInjector {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
private Object serialize(Object o) {
|
private Object serialize(Object o) {
|
||||||
try {
|
try {
|
||||||
if (o.getClass().isPrimitive() || primitiveType.contains(o.getClass())) {
|
if (o.getClass().isPrimitive() || primitiveType.contains(o.getClass())) {
|
||||||
return o;
|
return o;
|
||||||
} else if (o.getClass().isArray()) {
|
} else if (o.getClass().isArray()) {
|
||||||
List list = new ArrayList();
|
List list = new ArrayList<>();
|
||||||
int len = (int) o.getClass().getField("length").get(o);
|
int len = (int) o.getClass().getField("length").get(o);
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
list.add(serialize(Array.get(o, i)));
|
list.add(serialize(Array.get(o, i)));
|
||||||
@ -133,11 +133,11 @@ public class TConfigInjector {
|
|||||||
} else if (o instanceof Collection) {
|
} else if (o instanceof Collection) {
|
||||||
return ((Collection) o).stream().map(this::serialize).collect(Collectors.toList());
|
return ((Collection) o).stream().map(this::serialize).collect(Collectors.toList());
|
||||||
} else if (o instanceof Map) {
|
} 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)));
|
((Map) o).forEach((o1, o2) -> map.put((String) o1, serialize(o2)));
|
||||||
return map;
|
return map;
|
||||||
} else if (o instanceof ConfigurationSerializable) {
|
} else if (o instanceof ConfigurationSerializable) {
|
||||||
Map map = new LinkedHashMap();
|
Map map = new LinkedHashMap<>();
|
||||||
map.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY,
|
map.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY,
|
||||||
ConfigurationSerialization.getAlias((Class<? extends ConfigurationSerializable>) o.getClass()));
|
ConfigurationSerialization.getAlias((Class<? extends ConfigurationSerializable>) o.getClass()));
|
||||||
map.putAll(((ConfigurationSerializable) o).serialize());
|
map.putAll(((ConfigurationSerializable) o).serialize());
|
||||||
|
@ -47,17 +47,17 @@ public class TLogger {
|
|||||||
|
|
||||||
public void warn(String msg) {
|
public void warn(String msg) {
|
||||||
if (level <= WARN)
|
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) {
|
public void error(String msg) {
|
||||||
if (level <= ERROR)
|
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) {
|
public void fatal(String msg) {
|
||||||
if (level <= FATAL)
|
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
|
@Getter
|
||||||
private static File serverDataFolder;
|
private static File serverDataFolder;
|
||||||
@Getter
|
@Getter
|
||||||
private static File docsFolder;
|
|
||||||
@Getter
|
|
||||||
private static StorageType storageType;
|
private static StorageType storageType;
|
||||||
@Getter
|
@Getter
|
||||||
private static boolean disable = false;
|
private static boolean disable = false;
|
||||||
@ -105,14 +103,12 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
inst = this; disable = false;
|
inst = this; disable = false;
|
||||||
|
|
||||||
TLib.init();
|
|
||||||
|
|
||||||
// 启动监控
|
|
||||||
new Metrics(this);
|
|
||||||
|
|
||||||
// 载入配置
|
// 载入配置
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
// 加载依赖
|
||||||
|
TLib.init();
|
||||||
|
|
||||||
// 载入目录
|
// 载入目录
|
||||||
setupDataFolder();
|
setupDataFolder();
|
||||||
// 注册配置
|
// 注册配置
|
||||||
@ -218,6 +214,8 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
// 更新检测
|
// 更新检测
|
||||||
new UpdateTask();
|
new UpdateTask();
|
||||||
|
// 启动监控
|
||||||
|
new Metrics(this);
|
||||||
|
|
||||||
// 启动
|
// 启动
|
||||||
started = true;
|
started = true;
|
||||||
@ -286,16 +284,10 @@ public class Main extends JavaPlugin implements Listener {
|
|||||||
if (!playerDataFolder.exists()) {
|
if (!playerDataFolder.exists()) {
|
||||||
playerDataFolder.mkdirs();
|
playerDataFolder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
serverDataFolder = new File(getConfig().getString("DATAURL.SERVER-DATA"));
|
serverDataFolder = new File(getConfig().getString("DATAURL.SERVER-DATA"));
|
||||||
if (!serverDataFolder.exists()) {
|
if (!serverDataFolder.exists()) {
|
||||||
serverDataFolder.mkdirs();
|
serverDataFolder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
docsFolder = new File(getDataFolder(), "Document");
|
|
||||||
if (!docsFolder.exists()) {
|
|
||||||
docsFolder.mkdirs();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerListener() {
|
private void registerListener() {
|
||||||
|
@ -76,9 +76,13 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadLib() {
|
public static void LoadLib() {
|
||||||
itemdir = YamlConfiguration.loadConfiguration(new File(Main.getInst().getConfig().getString("DATAURL.ITEMDIR")));
|
try {
|
||||||
reloadItemName();
|
reloadItemName();
|
||||||
reloadItemCache();
|
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) {
|
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);
|
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) {
|
public static ItemStack getItemFromDir(String name) {
|
||||||
if (itemdir != null) {
|
if (itemdir != null) {
|
||||||
return itemdir.getItemStack("item." + name);
|
return itemdir.getItemStack("item." + name);
|
||||||
|
@ -2,6 +2,8 @@ package me.skymc.taboolib.string.language2;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.skymc.taboolib.string.language2.value.*;
|
import me.skymc.taboolib.string.language2.value.*;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -100,40 +102,41 @@ public class Language2Format implements Language2Line {
|
|||||||
private void parseValue(Player player, List<String> list, Language2Type type) {
|
private void parseValue(Player player, List<String> list, Language2Type type) {
|
||||||
if (list.size() == 0) {
|
if (list.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 变量转换
|
// 变量转换
|
||||||
list = language2Value.setPlaceholder(list, player);
|
List<String> listPlaceholder = language2Value.setPlaceholder(list, player);
|
||||||
// 大标题
|
// 大标题
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TITLE:
|
case TITLE:
|
||||||
language2Lines.add(new Language2Title(this, list));
|
language2Lines.add(new Language2Title(this, listPlaceholder));
|
||||||
break;
|
break;
|
||||||
// 小标题
|
// 小标题
|
||||||
case ACTION:
|
case ACTION:
|
||||||
language2Lines.add(new Language2Action(this, list));
|
language2Lines.add(new Language2Action(this, listPlaceholder));
|
||||||
break;
|
break;
|
||||||
// JSON
|
// JSON
|
||||||
case JSON:
|
case JSON:
|
||||||
language2Lines.add(new Language2Json(this, list, player));
|
language2Lines.add(new Language2Json(this, listPlaceholder, player));
|
||||||
break;
|
break;
|
||||||
// JSON2
|
// JSON2
|
||||||
case JSON2:
|
case JSON2:
|
||||||
language2Lines.add(new Language2Json2(this, list, player));
|
language2Lines.add(new Language2Json2(this, listPlaceholder, player));
|
||||||
break;
|
break;
|
||||||
// 音效
|
// 音效
|
||||||
case SOUND:
|
case SOUND:
|
||||||
language2Lines.add(new Language2Sound(this, list));
|
language2Lines.add(new Language2Sound(this, listPlaceholder));
|
||||||
break;
|
break;
|
||||||
// 书本
|
// 书本
|
||||||
case BOOK:
|
case BOOK:
|
||||||
language2Lines.add(new Language2Book(this, list, player));
|
language2Lines.add(new Language2Book(this, listPlaceholder, player));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
language2Lines.add(new Language2Text(this, list));
|
language2Lines.add(new Language2Text(this, listPlaceholder));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// 清理数据
|
// 清理数据
|
||||||
list.clear();
|
list.clear();
|
||||||
|
listPlaceholder.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,6 +17,10 @@ DATAURL:
|
|||||||
# 启用后将收到来自其他插件的调试信息
|
# 启用后将收到来自其他插件的调试信息
|
||||||
DEBUG: false
|
DEBUG: false
|
||||||
|
|
||||||
|
# 是否启用离线模式
|
||||||
|
# 离线模式下将不会下载依赖
|
||||||
|
OFFLINE-MODE: false
|
||||||
|
|
||||||
# 是否启用更新检测
|
# 是否启用更新检测
|
||||||
UPDATE-CHECK: true
|
UPDATE-CHECK: true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user