diff --git a/src/main/src/me/skymc/taboolib/Main.java b/src/main/src/me/skymc/taboolib/Main.java index 82646f042..1daa4d4f3 100644 --- a/src/main/src/me/skymc/taboolib/Main.java +++ b/src/main/src/me/skymc/taboolib/Main.java @@ -38,6 +38,7 @@ import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.inventory.speciaitem.SpecialItem; import me.skymc.taboolib.javashell.JavaShell; +import me.skymc.taboolib.listener.ListenerNetWork; import me.skymc.taboolib.listener.ListenerPlayerCommand; import me.skymc.taboolib.listener.ListenerPlayerQuit; import me.skymc.taboolib.listener.ListenerPlayerJump; @@ -51,6 +52,7 @@ import me.skymc.taboolib.support.SupportPlaceholder; import me.skymc.taboolib.team.TagUtils; import me.skymc.taboolib.timecycle.TimeCycleManager; +import me.skymc.taboolib.update.UpdateTask; import me.skymc.tlm.TLM; import me.skymc.tlm.command.TLMCommands; import me.skymc.tlm.module.TabooLibraryModule; @@ -223,6 +225,9 @@ public void run() { } }.runTask(this); + // 更新检测 + new UpdateTask(); + // 启动 started = true; } @@ -316,6 +321,11 @@ private void registerListener() { getServer().getPluginManager().registerEvents(new EntityUtils(), this); getServer().getPluginManager().registerEvents(new SignUtils(), this); } + + // 如果 YUM 插件存在 + if (Bukkit.getPluginManager().getPlugin("YUM") != null) { + getServer().getPluginManager().registerEvents(new ListenerNetWork(), this); + } } public static enum StorageType { diff --git a/src/main/src/me/skymc/taboolib/TabooLib.java b/src/main/src/me/skymc/taboolib/TabooLib.java index 2a27a900a..6f17ce28a 100644 --- a/src/main/src/me/skymc/taboolib/TabooLib.java +++ b/src/main/src/me/skymc/taboolib/TabooLib.java @@ -11,6 +11,20 @@ public class TabooLib { + /** + * ȡ汾 + * + * @return + */ + public static double getPluginVersion() { + try { + return Double.valueOf(Main.getInst().getDescription().getVersion()); + } + catch (Exception e) { + return 0D; + } + } + /** * ȡ NMS 汾 * diff --git a/src/main/src/me/skymc/taboolib/commands/language/Language2Command.java b/src/main/src/me/skymc/taboolib/commands/language/Language2Command.java index d7b458901..9e058adaa 100644 --- a/src/main/src/me/skymc/taboolib/commands/language/Language2Command.java +++ b/src/main/src/me/skymc/taboolib/commands/language/Language2Command.java @@ -23,7 +23,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String sender.sendMessage("f"); sender.sendMessage("bl----- 3lLanguage2 Commands bl-----"); sender.sendMessage("f"); - sender.sendMessage("f /language2 send 8[7ҡ8] 8[7ԡ8] 8<78> 6- eʾ"); + sender.sendMessage("f /language2 send 8[7/ALL8] 8[7ԡ8] 8<78> 6- eʾ"); sender.sendMessage("f /language2 reload 6- eԿ"); sender.sendMessage("f"); } @@ -38,35 +38,41 @@ else if (args[0].equalsIgnoreCase("send")) { MsgUtils.send(sender, "4"); } else { - // ȡ - Player player = Bukkit.getPlayerExact(args[1]); - if (player == null) { - MsgUtils.send(sender, "4Ҳ"); + // ʱ + long time = System.currentTimeMillis(); + + // ȡļ + Language2Value value = Main.getExampleLangauge2().get(args[2]); + // б + if (args.length > 3) { + int i = 0; + for (String variable : args[3].split("\\|")) { + value.addPlaceholder("$" + i, variable); + i++; + } + } + + // ǹ + if (args[1].equals("ALL")) { + // Ϣ + value.broadcast(); } else { - // ʱ - long time = System.currentTimeMillis(); - - // ȡļ - Language2Value value = Main.getExampleLangauge2().get(args[2]); - - // б - if (args.length > 3) { - int i = 0; - for (String variable : args[3].split("\\|")) { - value.addPlaceholder("$" + i, variable); - i++; - } + // ȡ + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + MsgUtils.send(sender, "4Ҳ"); } - - // Ϣ - value.send(player); - - // - if (sender instanceof Player && ((Player) sender).getItemInHand().getType().equals(Material.COMMAND)) { - MsgUtils.send(sender, "7Ϣѷ, μʱ: &f" + (System.currentTimeMillis() - time) + "ms"); + else { + // Ϣ + value.send(player); } } + + // + if (sender instanceof Player && ((Player) sender).getItemInHand().getType().equals(Material.COMMAND)) { + MsgUtils.send(sender, "7Ϣѷ, μʱ: &f" + (System.currentTimeMillis() - time) + "ms"); + } } } return true; diff --git a/src/main/src/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/src/me/skymc/taboolib/fileutils/FileUtils.java index 8158c4ddf..7f1c17bdc 100644 --- a/src/main/src/me/skymc/taboolib/fileutils/FileUtils.java +++ b/src/main/src/me/skymc/taboolib/fileutils/FileUtils.java @@ -12,6 +12,7 @@ import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; import me.skymc.taboolib.client.LogClient; +import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.methods.MethodsUtils; public class FileUtils { @@ -78,7 +79,7 @@ public static String getStringFromInputStream(InputStream in, int size, String e bos.close(); return new String(bos.toByteArray(), encode); } catch (IOException e) { - e.printStackTrace(); + MsgUtils.warn("ȡ: &4" + e.getMessage()); } return null; } @@ -101,7 +102,7 @@ public static String getStringFromFile(File file, int size, String encode) { fin.close(); return new String(bos.toByteArray(), encode); } catch (IOException e) { - e.printStackTrace(); + MsgUtils.warn("ļȡ: &4" + e.getMessage()); } return null; } @@ -123,7 +124,7 @@ public static String getStringFromURL(String url, int size) { bin.close(); return new String(bos.toByteArray(), conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding()); } catch (IOException e) { - e.printStackTrace(); + MsgUtils.warn("ʳ: &4" + e.getMessage()); } return null; } diff --git a/src/main/src/me/skymc/taboolib/listener/ListenerNetWork.java b/src/main/src/me/skymc/taboolib/listener/ListenerNetWork.java new file mode 100644 index 000000000..d0426be3e --- /dev/null +++ b/src/main/src/me/skymc/taboolib/listener/ListenerNetWork.java @@ -0,0 +1,28 @@ +package me.skymc.taboolib.listener; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.message.MsgUtils; +import pw.yumc.Yum.events.PluginNetworkEvent; + +/** + * @author sky + * @since 2018223 11:10:03 + */ +public class ListenerNetWork implements Listener { + + public static final String GG = "ֻΪ˷ֹĸ¼ⱻ YUM ֹá"; + + @EventHandler (priority = EventPriority.HIGHEST) + public void onNetWork(PluginNetworkEvent e) { + if (e.getPlugin() != null && e.getPlugin().equals(Main.getInst())) { + // ȡֹ + e.setCancelled(false); + // ̨ʾ + MsgUtils.warn("ȡ &4YUM &cԱʵֹ!"); + } + } +} diff --git a/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java b/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java index 2c729367e..5b6c7bff0 100644 --- a/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java +++ b/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.string.language2; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedHashMap; @@ -199,6 +200,17 @@ public void send(CommandSender sender) { } } + /** + * ȫ + */ + public void broadcast() { + List players = new ArrayList<>(); + for (Player player : Bukkit.getOnlinePlayers()) { + players.add(player); + } + send(players); + } + /** * ȡı * diff --git a/src/main/src/me/skymc/taboolib/update/UpdateTask.java b/src/main/src/me/skymc/taboolib/update/UpdateTask.java new file mode 100644 index 000000000..42908a81e --- /dev/null +++ b/src/main/src/me/skymc/taboolib/update/UpdateTask.java @@ -0,0 +1,56 @@ +package me.skymc.taboolib.update; + +import java.io.File; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.bukkit.scheduler.BukkitRunnable; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.fileutils.FileUtils; +import me.skymc.taboolib.message.MsgUtils; + +/** + * @author sky + * @since 2018223 10:39:14 + */ +public class UpdateTask { + + /** + * + */ + public UpdateTask() { + new BukkitRunnable() { + + @Override + public void run() { + // Ƿ + if (!Main.getInst().getConfig().getBoolean("UPDATE-CHECK")) { + return; + } + + String value = FileUtils.getStringFromURL("https://github.com/Bkm016/TabooLib/releases", 1024); + Pattern pattern = Pattern.compile(""); + Matcher matcher = pattern.matcher(value); + if (matcher.find()) { + // °汾 + double newVersion = Double.valueOf(matcher.group(1)); + // ° + if (TabooLib.getPluginVersion() == newVersion) { + MsgUtils.send("°, !"); + } + else { + MsgUtils.send("&8####################################################"); + MsgUtils.send("⵽µİ汾!"); + MsgUtils.send("ǰ汾: &f" + TabooLib.getPluginVersion()); + MsgUtils.send("°汾: &f" + newVersion); + MsgUtils.send("صַ: &fhttp://www.mcbbs.net/thread-773065-1-1.html"); + MsgUtils.send("Դַ: &fhttps://github.com/Bkm016/TabooLib/"); + MsgUtils.send("&8####################################################"); + } + } + } + }.runTaskLaterAsynchronously(Main.getInst(), 100); + } +} diff --git a/src/resources/config.yml b/src/resources/config.yml index 2f65092e3..dc86cf147 100644 --- a/src/resources/config.yml +++ b/src/resources/config.yml @@ -17,6 +17,9 @@ DATAURL: # 启用后将收到来自其他插件的调试信息 DEBUG: false +# 是否启用更新检测 +UPDATE-CHECK: true + # 是否在关闭服务器时清理玩家数据 # 该配置将在启用数据库储存时失效 DELETE-DATA: false