From cc005483c5194a5431a9124aa78974120b53a6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 12 Feb 2018 14:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=9B=B4=E6=96=B0=E8=87=B3?= =?UTF-8?q?=203.51?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复:物品列表点击空白处报错 新增:TitleUtils 内方法新增简写方式 新增:ConfigUtils 内新增释放配置方法 新增:TimeCycleInitializeEvent 内新增 canll() 方法 修改:PlayerLoadedEvent 监听器改为异步 修改:ItemUtils 内 loadItemsFile 方法内变量类型修改 修改:TimeCycleManager 算法调整 --- .../itemlist/listener/ItemLibraryPatch.java | 2 +- .../me/skymc/taboolib/display/TitleUtils.java | 4 ++++ .../skymc/taboolib/fileutils/ConfigUtils.java | 21 +++++++++++++++++-- .../skymc/taboolib/inventory/ItemUtils.java | 2 +- .../timecycle/TimeCycleInitializeEvent.java | 6 ++++++ .../taboolib/timecycle/TimeCycleManager.java | 19 ++++++++++------- 6 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java b/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java index ca6ebfc..e9f5fba 100644 --- a/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java +++ b/src/main/src/me/skymc/taboolib/commands/sub/itemlist/listener/ItemLibraryPatch.java @@ -31,7 +31,7 @@ public class ItemLibraryPatch implements Listener { if (e.getInventory().getHolder() instanceof ItemLibraryHolder) { e.setCancelled(true); - if (e.getCurrentItem() == null) { + if (e.getCurrentItem() == null || e.getCurrentItem().getType().equals(Material.AIR)) { return; } diff --git a/src/main/src/me/skymc/taboolib/display/TitleUtils.java b/src/main/src/me/skymc/taboolib/display/TitleUtils.java index 0145ffc..abded02 100644 --- a/src/main/src/me/skymc/taboolib/display/TitleUtils.java +++ b/src/main/src/me/skymc/taboolib/display/TitleUtils.java @@ -36,6 +36,10 @@ public class TitleUtils { return null; } + public static void sendTitle(Player p, String title, String subtitle, int fadein, int stay, int fadeout) { + sendTitle(p, title, fadein, stay, fadeout, subtitle, fadein, stay, fadeout); + } + public static void sendTitle(Player p, String title, int fadeint, int stayt, int fadeoutt, String subtitle, int fadeinst, int stayst, int fadeoutst) { if (title == null) { diff --git a/src/main/src/me/skymc/taboolib/fileutils/ConfigUtils.java b/src/main/src/me/skymc/taboolib/fileutils/ConfigUtils.java index 15443ef..b710be8 100644 --- a/src/main/src/me/skymc/taboolib/fileutils/ConfigUtils.java +++ b/src/main/src/me/skymc/taboolib/fileutils/ConfigUtils.java @@ -27,6 +27,23 @@ public class ConfigUtils { return Base64Coder.encodeLines(file.saveToString().getBytes()).replaceAll("\\s+", ""); } + /** + * UTF-8 ĸʽͷļ + * + * ¼ʱ䣺201821021:28:30 + * ¼汾3.49 + * + * @param plugin + * @return + */ + public static FileConfiguration saveDefaultConfig(Plugin plugin, String name) { + File file = new File(plugin.getDataFolder(), name); + if (!file.exists()) { + plugin.saveResource(name, true); + } + return load(plugin, file); + } + /** * UTF-8 ĸʽļ * @@ -34,7 +51,7 @@ public class ConfigUtils { * @param filename * @return */ - public static YamlConfiguration load(Plugin plugin, File file) { + public static FileConfiguration load(Plugin plugin, File file) { YamlConfiguration yaml = new YamlConfiguration(); try { yaml = YamlConfiguration.loadConfiguration(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8)); @@ -47,7 +64,7 @@ public class ConfigUtils { } @Deprecated - public static YamlConfiguration load(Plugin plugin, String file) { + public static FileConfiguration load(Plugin plugin, String file) { return load(plugin, FileUtils.file(file)); } } diff --git a/src/main/src/me/skymc/taboolib/inventory/ItemUtils.java b/src/main/src/me/skymc/taboolib/inventory/ItemUtils.java index 1a12e0b..71b24c1 100644 --- a/src/main/src/me/skymc/taboolib/inventory/ItemUtils.java +++ b/src/main/src/me/skymc/taboolib/inventory/ItemUtils.java @@ -93,7 +93,7 @@ public class ItemUtils { } public static void loadItemsFile(File file, boolean finalFile) { - YamlConfiguration conf = ConfigUtils.load(Main.getInst(), file); + FileConfiguration conf = ConfigUtils.load(Main.getInst(), file); for (String name : conf.getConfigurationSection("").getKeys(false)) { if (isExists(name)) { MsgUtils.warn("޷Ʒ &4" + name + "&c, ΪѾ"); diff --git a/src/main/src/me/skymc/taboolib/timecycle/TimeCycleInitializeEvent.java b/src/main/src/me/skymc/taboolib/timecycle/TimeCycleInitializeEvent.java index eb7b527..9c1037c 100644 --- a/src/main/src/me/skymc/taboolib/timecycle/TimeCycleInitializeEvent.java +++ b/src/main/src/me/skymc/taboolib/timecycle/TimeCycleInitializeEvent.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.timecycle; +import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -15,6 +16,11 @@ public class TimeCycleInitializeEvent extends Event { this.time = time; } + public TimeCycleInitializeEvent call() { + Bukkit.getPluginManager().callEvent(this); + return this; + } + public Long getTimeline() { return time; } diff --git a/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java b/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java index 515b061..cbf4e90 100644 --- a/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java +++ b/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java @@ -144,19 +144,22 @@ public class TimeCycleManager { for (TimeCycle cycle : cycles.values()) { // ûбִй if (!GlobalDataManager.contains("timecycle:" + cycle.getName())) { - long time = System.currentTimeMillis(); - // - TimeCycleInitializeEvent event1 = new TimeCycleInitializeEvent(cycle, time); - Bukkit.getPluginManager().callEvent(event1); + long time = new TimeCycleInitializeEvent(cycle, System.currentTimeMillis()).call().getTimeline(); // ʼ - GlobalDataManager.setVariable("timecycle:" + cycle.getName(), event1.getTimeline().toString()); + GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(time)); // Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle)); } - // ִ - else if (System.currentTimeMillis() - getAfterTimeline(cycle.getName()) >= cycle.getCycle()) { + // ˢʱ + else if (System.currentTimeMillis() >= getAfterTimeline(cycle.getName())) { + long time = System.currentTimeMillis(); + // ʱ 30 + if (time - getAfterTimeline(cycle.getName()) > 30000) { + // ʼ + time = new TimeCycleInitializeEvent(cycle, time).call().getTimeline(); + } // - GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(System.currentTimeMillis())); + GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(time)); // Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle)); }