From 44a9b7940400abff76d5e64a0c64780397aec689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sat, 6 Jul 2019 19:30:56 +0800 Subject: [PATCH] Fix --- src/main/scala/io/izzel/taboolib/PluginLoader.java | 5 +++++ src/main/scala/io/izzel/taboolib/TabooLib.java | 2 +- src/main/scala/io/izzel/taboolib/TabooLibAPI.java | 2 +- .../io/izzel/taboolib/module/inject/TScheduleLoader.java | 7 +++++++ .../scala/io/izzel/taboolib/module/lite/SimpleI18n.java | 8 ++++---- .../scala/io/izzel/taboolib/module/locale/TLocale.java | 4 ++-- .../io/izzel/taboolib/module/locale/TLocaleLoader.java | 4 ++++ src/main/scala/io/izzel/taboolib/module/nms/NMS.java | 8 ++++---- src/main/scala/io/izzel/taboolib/util/item/Items.java | 4 ++-- src/main/scala/io/izzel/taboolib/util/lite/Particles.java | 2 +- 10 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/main/scala/io/izzel/taboolib/PluginLoader.java b/src/main/scala/io/izzel/taboolib/PluginLoader.java index dc1308a..51d7854 100644 --- a/src/main/scala/io/izzel/taboolib/PluginLoader.java +++ b/src/main/scala/io/izzel/taboolib/PluginLoader.java @@ -10,6 +10,7 @@ import io.izzel.taboolib.module.db.local.Local; import io.izzel.taboolib.module.db.source.DBSource; import io.izzel.taboolib.module.dependency.TDependencyInjector; import io.izzel.taboolib.module.inject.TListenerHandler; +import io.izzel.taboolib.module.inject.TScheduleLoader; import io.izzel.taboolib.module.locale.TLocaleLoader; import org.bukkit.plugin.Plugin; @@ -55,10 +56,14 @@ public abstract class PluginLoader { public void onActivated(Plugin plugin) { // 注册监听器 TListenerHandler.registerListener(plugin); + // 注册调度器 + TScheduleLoader.run(plugin); } @Override public void onStopping(Plugin plugin) { + // 卸载语言文件 + TLocaleLoader.unload(plugin); // 保存数据 Local.saveFiles(plugin.getName()); Local.clearFiles(plugin.getName()); diff --git a/src/main/scala/io/izzel/taboolib/TabooLib.java b/src/main/scala/io/izzel/taboolib/TabooLib.java index 12d7d16..90891db 100644 --- a/src/main/scala/io/izzel/taboolib/TabooLib.java +++ b/src/main/scala/io/izzel/taboolib/TabooLib.java @@ -63,7 +63,7 @@ public class TabooLib { TabooLibLoader.init(); // 创建线程检测服务器是否关闭 Executors.newSingleThreadExecutor().submit(() -> { - while (NMS.getHandler().isRunning()) { + while (NMS.handle().isRunning()) { } // 保存数据 Local.saveFiles(); diff --git a/src/main/scala/io/izzel/taboolib/TabooLibAPI.java b/src/main/scala/io/izzel/taboolib/TabooLibAPI.java index cd0e2f6..fb0bffa 100644 --- a/src/main/scala/io/izzel/taboolib/TabooLibAPI.java +++ b/src/main/scala/io/izzel/taboolib/TabooLibAPI.java @@ -42,7 +42,7 @@ public class TabooLibAPI { } public static double[] getTPS() { - return NMS.getHandler().getTPS(); + return NMS.handle().getTPS(); } public static boolean isDebug() { diff --git a/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java index c567e93..b6510bd 100644 --- a/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/inject/TScheduleLoader.java @@ -21,6 +21,13 @@ public class TScheduleLoader implements TabooLibLoader.Loader { static Map> schedules = Maps.newHashMap(); + public static void run(Plugin plugin) { + List list = schedules.get(plugin.getName()); + if (list != null) { + list.forEach(data -> run(plugin, data.getRunnable(), data.getAnnotation().delay(), data.getAnnotation().period(), data.getAnnotation().async())); + } + } + public static void run(Plugin plugin, BukkitRunnable runnable, int delay, int period, boolean async) { if (async) { runnable.runTaskTimerAsynchronously(plugin, delay, period); diff --git a/src/main/scala/io/izzel/taboolib/module/lite/SimpleI18n.java b/src/main/scala/io/izzel/taboolib/module/lite/SimpleI18n.java index 5a4ce65..6053a3a 100644 --- a/src/main/scala/io/izzel/taboolib/module/lite/SimpleI18n.java +++ b/src/main/scala/io/izzel/taboolib/module/lite/SimpleI18n.java @@ -56,7 +56,7 @@ public class SimpleI18n { } public static String getName(Entity entity) { - return entity == null ? "-" : lang.getString(NMS.getHandler().getName(entity).replace(".", "_"), entity.getName()); + return entity == null ? "-" : lang.getString(NMS.handle().getName(entity).replace(".", "_"), entity.getName()); } public static String getName(ItemStack item) { @@ -69,7 +69,7 @@ public class SimpleI18n { } if (!Version.isAfter(Version.v1_11)) { if (item.getType().name().equals("MONSTER_EGG")) { - NBTCompound nbtCompound = NMS.getHandler().loadNBT(item); + NBTCompound nbtCompound = NMS.handle().loadNBT(item); if (nbtCompound.containsKey("EntityTag")) { return lang.getString("item_monsterPlacer_name") + " " + lang.getString("entity_" + nbtCompound.get("EntityTag").asCompound().get("id").asString() + "_name"); } @@ -79,11 +79,11 @@ public class SimpleI18n { if (itemMeta instanceof SpawnEggMeta) { String spawnEggType = lang.getString("entity_" + ((SpawnEggMeta) itemMeta).getSpawnedType().getEntityClass().getSimpleName().replace(".", "_") + "_name"); if (spawnEggType != null) { - return lang.getString(NMS.getHandler().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")) + " " + spawnEggType; + return lang.getString(NMS.handle().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")) + " " + spawnEggType; } } } - return lang.getString(NMS.getHandler().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")); + return lang.getString(NMS.handle().getName(item).replace(".", "_"), item.getType().name().toLowerCase().replace("_", "")); } private static void releaseLocales(Plugin plugin) { diff --git a/src/main/scala/io/izzel/taboolib/module/locale/TLocale.java b/src/main/scala/io/izzel/taboolib/module/locale/TLocale.java index 450adf6..7620c9d 100644 --- a/src/main/scala/io/izzel/taboolib/module/locale/TLocale.java +++ b/src/main/scala/io/izzel/taboolib/module/locale/TLocale.java @@ -96,11 +96,11 @@ public class TLocale { } public static void sendTitle(Player player, String title, String subTitle, int fadein, int stay, int fadeout) { - NMS.getHandler().sendTitle(player, title, fadein, stay, fadeout, subTitle, fadein, stay, fadeout); + NMS.handle().sendTitle(player, title, fadein, stay, fadeout, subTitle, fadein, stay, fadeout); } public static void sendActionBar(Player player, String text) { - NMS.getHandler().sendActionBar(player, text); + NMS.handle().sendActionBar(player, text); } } diff --git a/src/main/scala/io/izzel/taboolib/module/locale/TLocaleLoader.java b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleLoader.java index 51e5d1b..ef0a6b1 100644 --- a/src/main/scala/io/izzel/taboolib/module/locale/TLocaleLoader.java +++ b/src/main/scala/io/izzel/taboolib/module/locale/TLocaleLoader.java @@ -87,6 +87,10 @@ public class TLocaleLoader { } } + public static void unload(Plugin plugin) { + map.remove(plugin.getName()); + } + public static boolean isLocaleLoaded(Plugin plugin) { return map.containsKey(plugin.getName()); } diff --git a/src/main/scala/io/izzel/taboolib/module/nms/NMS.java b/src/main/scala/io/izzel/taboolib/module/nms/NMS.java index d06a92a..f3dc202 100644 --- a/src/main/scala/io/izzel/taboolib/module/nms/NMS.java +++ b/src/main/scala/io/izzel/taboolib/module/nms/NMS.java @@ -15,15 +15,15 @@ import org.bukkit.inventory.ItemStack; @TFunction(enable = "init") public abstract class NMS { - private static NMS handler; + private static NMS impl; - public static NMS getHandler() { - return handler; + public static NMS handle() { + return impl; } static void init() { try { - handler = (NMS) SimpleVersionControl.createNMS("io.izzel.taboolib.module.nms.NMSHandlerImpl").translate().newInstance(); + impl = (NMS) SimpleVersionControl.createNMS("io.izzel.taboolib.module.nms.NMSImpl").translate().newInstance(); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/scala/io/izzel/taboolib/util/item/Items.java b/src/main/scala/io/izzel/taboolib/util/item/Items.java index 19da110..1a3a444 100644 --- a/src/main/scala/io/izzel/taboolib/util/item/Items.java +++ b/src/main/scala/io/izzel/taboolib/util/item/Items.java @@ -232,7 +232,7 @@ public class Items { // 元数据 item.setItemMeta(meta); // 数据 - NBTCompound nbt = NMS.getHandler().loadNBT(item); + NBTCompound nbt = NMS.handle().loadNBT(item); // 物品标签 if (section.contains("nbt")) { for (String name : section.getConfigurationSection("nbt").getKeys(false)) { @@ -281,6 +281,6 @@ public class Items { } nbt.put("AttributeModifiers", attr); } - return NMS.getHandler().saveNBT(item, nbt); + return NMS.handle().saveNBT(item, nbt); } } diff --git a/src/main/scala/io/izzel/taboolib/util/lite/Particles.java b/src/main/scala/io/izzel/taboolib/util/lite/Particles.java index c50f66a..66c3fb5 100644 --- a/src/main/scala/io/izzel/taboolib/util/lite/Particles.java +++ b/src/main/scala/io/izzel/taboolib/util/lite/Particles.java @@ -843,7 +843,7 @@ public enum Particles { data = getDustColor((OrdinaryColor) data, size); } } - this.packet = NMS.getHandler().toPacketPlayOutWorldParticles(effect.getBukkitParticle(), longDistance, (float) center.getX(), (float) center.getY(), (float) center.getZ(), offsetX, offsetY, offsetZ, speed, amount, data); + this.packet = NMS.handle().toPacketPlayOutWorldParticles(effect.getBukkitParticle(), longDistance, (float) center.getX(), (float) center.getY(), (float) center.getZ(), offsetX, offsetY, offsetZ, speed, amount, data); } catch (Throwable exception) { throw new PacketInstantiationException("Packet instantiation failed", exception); }