From c5583cc1d1863ed692b141371b735a053f711055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 7 May 2018 18:19:02 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/me/skymc/taboolib/Main.java | 2 +- .../skymc/taboolib/commands/MainCommands.java | 2 +- .../commands/language/Language2Command.java | 120 ++++----- .../locale/TabooLibLocaleCommand.java | 18 +- .../commands/sub/TagDeleteCommand.java | 48 ++-- .../commands/sub/TagPrefixCommand.java | 11 +- .../commands/sub/TagSuffixCommand.java | 58 ++-- .../commands/sub/cycle/CycleInfoCommand.java | 22 +- .../commands/sub/cycle/CycleListCommand.java | 28 +- .../commands/sub/cycle/CycleResetCommand.java | 7 +- .../sub/cycle/CycleUpdateCommand.java | 7 +- .../taboolib/cooldown/CooldownUtils.java | 76 +++--- .../cooldown/seconds/CooldownUtils2.java | 34 +-- .../taboolib/database/GlobalDataManager.java | 8 +- .../taboolib/database/PlayerDataManager.java | 7 +- .../me/skymc/taboolib/entity/EntityUtils.java | 5 +- .../skymc/taboolib/fileutils/ConfigUtils.java | 5 +- .../skymc/taboolib/fileutils/FileUtils.java | 251 +++++++++--------- .../skymc/taboolib/inventory/DropUtils.java | 17 +- .../skymc/taboolib/inventory/ItemUtils.java | 48 ++-- .../skymc/taboolib/object/WeightCategory.java | 1 + .../taboolib/object/WeightCollection.java | 99 +++++++ .../me/skymc/taboolib/other/NumberUtils.java | 43 ++- .../me/skymc/taboolib/other/WeightUtils.java | 3 +- src/main/resources/lang/zh_CN.yml | 132 +++++++-- 25 files changed, 581 insertions(+), 471 deletions(-) create mode 100644 src/main/java/me/skymc/taboolib/object/WeightCollection.java diff --git a/src/main/java/me/skymc/taboolib/Main.java b/src/main/java/me/skymc/taboolib/Main.java index f45c432..c0ece67 100644 --- a/src/main/java/me/skymc/taboolib/Main.java +++ b/src/main/java/me/skymc/taboolib/Main.java @@ -114,7 +114,7 @@ public class Main extends JavaPlugin implements Listener { } public static Random getRandom() { - return NumberUtils.getRand(); + return NumberUtils.getRandom(); } public static String getTablePrefix() { diff --git a/src/main/java/me/skymc/taboolib/commands/MainCommands.java b/src/main/java/me/skymc/taboolib/commands/MainCommands.java index 9209fcc..460c080 100644 --- a/src/main/java/me/skymc/taboolib/commands/MainCommands.java +++ b/src/main/java/me/skymc/taboolib/commands/MainCommands.java @@ -18,7 +18,7 @@ public class MainCommands implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0 || args[0].equalsIgnoreCase("help")) { - TLocale.sendTo(sender, "COMMANDS.TABOOLIB.HELP"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.HELP", label); } else if (args[0].equalsIgnoreCase("save")) { new SaveCommand(sender, args); } else if (args[0].equalsIgnoreCase("enchants")) { diff --git a/src/main/java/me/skymc/taboolib/commands/language/Language2Command.java b/src/main/java/me/skymc/taboolib/commands/language/Language2Command.java index 7c421e4..b1bf0e0 100644 --- a/src/main/java/me/skymc/taboolib/commands/language/Language2Command.java +++ b/src/main/java/me/skymc/taboolib/commands/language/Language2Command.java @@ -1,5 +1,8 @@ package me.skymc.taboolib.commands.language; +import com.ilummc.tlib.resources.TLocale; +import me.skymc.taboolib.Main; +import me.skymc.taboolib.string.language2.Language2Value; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.Command; @@ -7,74 +10,63 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import me.skymc.taboolib.Main; -import me.skymc.taboolib.message.MsgUtils; -import me.skymc.taboolib.string.language2.Language2Value; - /** * @author sky * @since 2018年2月13日 下午5:11:01 */ public class Language2Command implements CommandExecutor { - @Override - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (args.length == 0) { - sender.sendMessage("§f"); - sender.sendMessage("§b§l----- §3§lLanguage2 Commands §b§l-----"); - sender.sendMessage("§f"); - sender.sendMessage("§f /language2 send §8[§7玩家/ALL§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示"); - sender.sendMessage("§f /language2 reload §6- §e重载语言库"); - sender.sendMessage("§f"); - } - else if (args[0].equalsIgnoreCase("reload")) { - MsgUtils.send(sender, "§7重载中.."); - long time = System.currentTimeMillis(); - Main.getExampleLanguage2().reload(); - MsgUtils.send(sender, "§7重载完成! 耗时: &f" + (System.currentTimeMillis() - time) + "ms"); - } - else if (args[0].equalsIgnoreCase("send")) { - if (args.length < 3) { - MsgUtils.send(sender, "§4参数错误"); - } - else { - // 时间 - long time = System.currentTimeMillis(); - - // 获取语言文件 - Language2Value value = Main.getExampleLanguage2().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 { - // 获取玩家 - Player player = Bukkit.getPlayerExact(args[1]); - if (player == null) { - MsgUtils.send(sender, "§4玩家不在线"); - } - 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; - } + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (args.length == 0) { + TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.HELP", label); + } else if (args[0].equalsIgnoreCase("reload")) { + reload(sender); + } else if (args[0].equalsIgnoreCase("send")) { + send(sender, args); + } + return true; + } + + private void send(CommandSender sender, String[] args) { + if (args.length < 3) { + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); + } else { + long time = System.currentTimeMillis(); + Language2Value value = getLanguage2Value(args); + + if (args[1].equalsIgnoreCase("ALL")) { + value.broadcast(); + } else { + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.INVALID-PLAYER", args[1]); + } else { + value.send(player); + } + } + + if (sender instanceof Player && ((Player) sender).getItemInHand().getType().equals(Material.COMMAND)) { + TLocale.sendTo(sender, "COMMANDS.LANGUAGE2.SUCCESS-SEND", String.valueOf(System.currentTimeMillis() - time)); + } + } + } + + private Language2Value getLanguage2Value(String[] args) { + Language2Value value = Main.getExampleLanguage2().get(args[2]); + if (args.length > 3) { + int i = 0; + for (String variable : args[3].split("\\|")) { + value.addPlaceholder("$" + i++, variable); + } + } + return value; + } + + private void reload(CommandSender sender) { + TLocale.sendTo(sender, "COMMANDS.RELOAD.LOADING"); + long time = System.currentTimeMillis(); + Main.getExampleLanguage2().reload(); + TLocale.sendTo(sender, "COMMANDS.RELOAD.SUCCESS-ELAPSED-TIME", String.valueOf(System.currentTimeMillis() - time)); + } } diff --git a/src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java b/src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java index ba8664f..6ba02fd 100644 --- a/src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/locale/TabooLibLocaleCommand.java @@ -21,35 +21,31 @@ public class TabooLibLocaleCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command arg1, String label, String[] args) { if (args.length == 0) { - sender.sendMessage("§f"); - sender.sendMessage("§b§l----- §3§lTabooLibLoacle Commands §b§l-----"); - sender.sendMessage("§f"); - sender.sendMessage("§f /tloacle send §8[§7玩家/ALL§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示"); - sender.sendMessage("§f /tloacle reload §6- §e重载语言库"); - sender.sendMessage("§f"); + TLocale.sendTo(sender, "COMMANDS.TLOCALE.HELP", label); } else if (args[0].equalsIgnoreCase("send")) { send(sender, args); } else if (args[0].equalsIgnoreCase("reload")) { reload(sender); } else { - MsgUtils.send(sender, "§4参数错误"); + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); } return true; } void send(CommandSender sender, String[] args) { if (args.length < 3) { - MsgUtils.send(sender, "§4参数错误"); + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); return; } + long time = System.currentTimeMillis(); List target = new ArrayList<>(); if (args[1].equalsIgnoreCase("all")) { target.addAll(Bukkit.getOnlinePlayers()); } else { Player player = Bukkit.getPlayerExact(args[1]); if (player == null) { - MsgUtils.send(sender, "§4玩家不在线"); + TLocale.sendTo(sender, "COMMANDS.TLOCALE.INVALID-PLAYER", args[1]); return; } target.add(player); @@ -64,13 +60,13 @@ public class TabooLibLocaleCommand implements CommandExecutor { } if (sender instanceof Player) { - MsgUtils.send(sender, "§7信息已发送"); + TLocale.sendTo(sender, "COMMANDS.TLOCALE.SUCCESS-SEND", String.valueOf(System.currentTimeMillis() - time)); } } void reload(CommandSender sender) { TLocale.reload(); - MsgUtils.send(sender, "§7重载完成"); + TLocale.sendTo(sender, "COMMANDS.TLOCALE.SUCCESS-RELOAD"); } } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java index 674200a..7a067f6 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagDeleteCommand.java @@ -1,12 +1,12 @@ package me.skymc.taboolib.commands.sub; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - +import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.team.TagManager; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * @author sky @@ -14,27 +14,23 @@ import me.skymc.taboolib.team.TagManager; */ public class TagDeleteCommand extends SubCommand { - /** - * @param sender - * @param args - */ - public TagDeleteCommand(CommandSender sender, String[] args) { - super(sender, args); - if (args.length < 2) { - MsgUtils.send(sender, "参数错误"); - return; - } - - Player player = Bukkit.getPlayerExact(args[1]); - if (player == null) { - MsgUtils.send(sender, "玩家 &f" + args[1] + " &7不在线"); - return; - } - - TagManager.getInst().removeData(player); - if (sender instanceof Player) { - MsgUtils.send(sender, "删除玩家 &f" + args[1] + " &7的称号数据"); - } - } + public TagDeleteCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 2) { + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); + return; + } + + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]); + return; + } + + TagManager.getInst().removeData(player); + if (sender instanceof Player) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-DELETE", args[1]); + } + } } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java index 3c3c927..cd8a0bb 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagPrefixCommand.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.commands.sub; +import com.ilummc.tlib.resources.TLocale; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -15,20 +16,16 @@ import me.skymc.taboolib.team.TagManager; */ public class TagPrefixCommand extends SubCommand { - /** - * @param sender - * @param args - */ public TagPrefixCommand(CommandSender sender, String[] args) { super(sender, args); if (args.length < 3) { - MsgUtils.send(sender, "参数错误"); + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); return; } Player player = Bukkit.getPlayerExact(args[1]); if (player == null) { - MsgUtils.send(sender, "玩家 &f" + args[1] + " &7不在线"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]); return; } @@ -39,7 +36,7 @@ public class TagPrefixCommand extends SubCommand { TagManager.getInst().setPrefix(player, value); if (sender instanceof Player) { - MsgUtils.send(sender, "设置玩家 &f" + args[1] + " &7的前缀为 &f" + value); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-PREFIX-SET", args[1], value); } } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java index 2b141ad..72ff6ed 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/TagSuffixCommand.java @@ -1,13 +1,13 @@ package me.skymc.taboolib.commands.sub; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - +import com.ilummc.tlib.resources.TLocale; import me.clip.placeholderapi.PlaceholderAPI; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.message.MsgUtils; import me.skymc.taboolib.team.TagManager; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; /** * @author sky @@ -15,32 +15,28 @@ import me.skymc.taboolib.team.TagManager; */ public class TagSuffixCommand extends SubCommand { - /** - * @param sender - * @param args - */ - public TagSuffixCommand(CommandSender sender, String[] args) { - super(sender, args); - if (args.length < 3) { - MsgUtils.send(sender, "参数错误"); - return; - } - - Player player = Bukkit.getPlayerExact(args[1]); - if (player == null) { - MsgUtils.send(sender, "玩家 &f" + args[1] + " &7不在线"); - return; - } - - String value = getArgs(2).replace("&", "§"); - if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - value = PlaceholderAPI.setPlaceholders(player, value); - } - - TagManager.getInst().setSuffix(player, value); - if (sender instanceof Player) { - MsgUtils.send(sender, "设置玩家 &f" + args[1] + " &7的后缀为 &f" + value); - } - } + public TagSuffixCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 3) { + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); + return; + } + + Player player = Bukkit.getPlayerExact(args[1]); + if (player == null) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.INVALID-PLAYER", args[1]); + return; + } + + String value = getArgs(2).replace("&", "§"); + if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { + value = PlaceholderAPI.setPlaceholders(player, value); + } + + TagManager.getInst().setSuffix(player, value); + if (sender instanceof Player) { + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.PLAYERTAG.SUCCESS-SUFFIX-SET", args[1], value); + } + } } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java index 8579c08..9312e4e 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java @@ -2,6 +2,7 @@ package me.skymc.taboolib.commands.sub.cycle; import java.util.concurrent.TimeUnit; +import com.ilummc.tlib.resources.TLocale; import org.bukkit.command.CommandSender; import me.skymc.taboolib.commands.SubCommand; @@ -15,25 +16,21 @@ public class CycleInfoCommand extends SubCommand { public CycleInfoCommand(CommandSender sender, String[] args) { super(sender, args); if (args.length < 3) { - MsgUtils.send(sender, "&c请输入正确的检查器名称"); + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); return; } TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]); if (cycle == null) { - MsgUtils.send(sender, "&c检查器 &4" + args[2] + " &c不存在"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.INVALID-CYCLE", args[2]); return; } - - sender.sendMessage("§f"); - sender.sendMessage("§b§l----- §3§lTimeCycle Info §b§l-----"); - sender.sendMessage("§f"); - sender.sendMessage(" §f- §7注册周期: §f" + asString(cycle.getCycle() / 1000L)); - sender.sendMessage(" §f- §7注册插件: §f" + cycle.getPlugin().getName()); - sender.sendMessage("§f"); - sender.sendMessage(" §f- §7上次刷新时间: §f" + DateUtils.CH_ALL.format(TimeCycleManager.getBeforeTimeline(cycle.getName()))); - sender.sendMessage(" §f- §7下次刷新时间: §f" + DateUtils.CH_ALL.format(TimeCycleManager.getAfterTimeline(cycle.getName()))); - sender.sendMessage("§f"); + + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.CYCLE-INFO", + asString(cycle.getCycle() / 1000L), + cycle.getPlugin().getName(), + DateUtils.CH_ALL.format(TimeCycleManager.getBeforeTimeline(cycle.getName())), + DateUtils.CH_ALL.format(TimeCycleManager.getAfterTimeline(cycle.getName()))); } public String asString(long seconds) { @@ -48,5 +45,4 @@ public class CycleInfoCommand extends SubCommand { public boolean command() { return true; } - } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java index ba6da82..67c867a 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.commands.sub.cycle; +import com.ilummc.tlib.resources.TLocale; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -9,29 +10,20 @@ import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; import me.skymc.taboolib.timecycle.TimeCycle; import me.skymc.taboolib.timecycle.TimeCycleManager; +import org.bukkit.inventory.ItemFlag; + +import java.util.Arrays; public class CycleListCommand extends SubCommand { public CycleListCommand(CommandSender sender, String[] args) { super(sender, args); - - sender.sendMessage("§f"); - sender.sendMessage("§b§l----- §3§lTimeCycle List §b§l-----"); - sender.sendMessage("§f"); - - for (TimeCycle cycle : TimeCycleManager.getTimeCycles()) { - if (isPlayer()) { - JSONFormatter json = new JSONFormatter(); - json.append(" §7- §f" + cycle.getName()); - json.appendHoverClick(" §8(点击复制)", new ShowTextEvent("§f点击复制"), new SuggestCommandEvent(cycle.getName())); - json.send((Player) sender); - } - else { - sender.sendMessage(" §7- §f" + cycle.getName()); - } - } - - sender.sendMessage("§f"); + + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.LIST.HEAD"); + + TimeCycleManager.getTimeCycles().forEach(cycle -> TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.LIST.BODY", cycle.getName())); + + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.LIST.FOOT"); } @Override diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java index 8a1997d..6430043 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.commands.sub.cycle; +import com.ilummc.tlib.resources.TLocale; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; @@ -18,13 +19,13 @@ public class CycleResetCommand extends SubCommand { public CycleResetCommand(CommandSender sender, String[] args) { super(sender, args); if (args.length < 3) { - MsgUtils.send(sender, "&c请输入正确的检查器名称"); + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); return; } TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]); if (cycle == null) { - MsgUtils.send(sender, "&c检查器 &4" + args[2] + " &c不存在"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.INVALID-CYCLE", args[2]); return; } @@ -38,7 +39,7 @@ public class CycleResetCommand extends SubCommand { // 触发器 Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle)); // 提示 - MsgUtils.send(sender, "检查器 &f" + args[2] + " &7初始化完成"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.CYCLE-RESET", args[2]); } }.runTaskAsynchronously(Main.getInst()); } diff --git a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java index b16ac82..1c4bb91 100644 --- a/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.commands.sub.cycle; +import com.ilummc.tlib.resources.TLocale; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitRunnable; @@ -17,13 +18,13 @@ public class CycleUpdateCommand extends SubCommand { public CycleUpdateCommand(CommandSender sender, String[] args) { super(sender, args); if (args.length < 3) { - MsgUtils.send(sender, "&c请输入正确的检查器名称"); + TLocale.sendTo(sender, "COMMANDS.PARAMETER.UNKNOWN"); return; } TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]); if (cycle == null) { - MsgUtils.send(sender, "&c检查器 &4" + args[2] + " &c不存在"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.INVALID-CYCLE", args[2]); return; } @@ -36,7 +37,7 @@ public class CycleUpdateCommand extends SubCommand { // 触发器 Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle)); // 提示 - MsgUtils.send(sender, "检查器 &f" + args[2] + " &7已更新"); + TLocale.sendTo(sender, "COMMANDS.TABOOLIB.TIMECYCLE.CYCLE-UPDATE", args[2]); } }.runTaskAsynchronously(Main.getInst()); } diff --git a/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java b/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java index 10c5e90..d63557e 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java +++ b/src/main/java/me/skymc/taboolib/cooldown/CooldownUtils.java @@ -1,55 +1,47 @@ package me.skymc.taboolib.cooldown; -import java.util.concurrent.ConcurrentHashMap; - +import com.ilummc.tlib.resources.TLocale; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.server.PluginDisableEvent; import org.bukkit.plugin.Plugin; -import me.skymc.taboolib.message.MsgUtils; +import java.util.concurrent.ConcurrentHashMap; @Deprecated public class CooldownUtils implements Listener { - - private static ConcurrentHashMap packlist = new ConcurrentHashMap<>(); - public static void register(CooldownPack pack) { - packlist.put(pack.getPackName(), pack); - MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (匿名注册)"); - } - - public static void register(CooldownPack pack, Plugin plugin) { - pack.setPlugin(plugin.getName()); - - packlist.put(pack.getPackName(), pack); - MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (" + plugin.getName() + ")"); - } - - public static void unregister(String name) { - packlist.remove(name); - - MsgUtils.send("注销冷却包: " + name + " (主动注销)"); - } - - @EventHandler - public void quit(PlayerQuitEvent e) { - for (CooldownPack pack : packlist.values()) { - if (!pack.isCooldown(e.getPlayer().getName(), 0)) { - pack.unRegister(e.getPlayer().getName()); - } - } - } - - @EventHandler - public void disable(PluginDisableEvent e) { - for (CooldownPack pack : packlist.values()) { - if (pack.getPlugin().equals(e.getPlugin().getName())) { - packlist.remove(pack.getPackName()); - - MsgUtils.send("注销冷却包: " + pack.getPackName() + " (自动注销)"); - } - } - } + private static ConcurrentHashMap packlist = new ConcurrentHashMap<>(); + + public static void register(CooldownPack pack) { + packlist.put(pack.getPackName(), pack); + TLocale.Logger.info("COOLDOWNPACK.PACK-REGISTER-ANONYMOUS", pack.getPackName(), String.valueOf(pack.getPackSeconds())); + } + + public static void register(CooldownPack pack, Plugin plugin) { + pack.setPlugin(plugin.getName()); + packlist.put(pack.getPackName(), pack); + TLocale.Logger.info("COOLDOWNPACK.PACK-REGISTER", pack.getPackName(), String.valueOf(pack.getPackSeconds()), plugin.getName()); + } + + public static void unregister(String name) { + packlist.remove(name); + TLocale.Logger.info("COOLDOWNPACK.PACK-UNREGISTER", name); + } + + private static void unregister(CooldownPack pack) { + packlist.remove(pack.getPackName()); + TLocale.Logger.info("COOLDOWNPACK.PACK-UNREGISTER-AUTO", pack.getPackName()); + } + + @EventHandler + public void quit(PlayerQuitEvent e) { + packlist.values().stream().filter(pack -> !pack.isCooldown(e.getPlayer().getName(), 0)).forEach(pack -> pack.unRegister(e.getPlayer().getName())); + } + + @EventHandler + public void disable(PluginDisableEvent e) { + packlist.values().stream().filter(pack -> pack.getPlugin().equals(e.getPlugin().getName())).forEach(CooldownUtils::unregister); + } } diff --git a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java index 565eeac..9fa4638 100644 --- a/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java +++ b/src/main/java/me/skymc/taboolib/cooldown/seconds/CooldownUtils2.java @@ -2,6 +2,7 @@ package me.skymc.taboolib.cooldown.seconds; import java.util.concurrent.ConcurrentHashMap; +import com.ilummc.tlib.resources.TLocale; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; @@ -18,39 +19,32 @@ public class CooldownUtils2 implements Listener { public static void register(CooldownPack2 pack) { packlist.put(pack.getPackName(), pack); -// MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (匿名注册)"); + TLocale.Logger.info("COOLDOWNPACK.PACK-REGISTER-ANONYMOUS", pack.getPackName(), String.valueOf(pack.getPackSeconds())); } public static void register(CooldownPack2 pack, Plugin plugin) { pack.setPlugin(plugin.getName()); - packlist.put(pack.getPackName(), pack); -// MsgUtils.send("注册冷却包: " + pack.getPackName() + ", 时间: " + pack.getPackSeconds() + " 秒 (" + plugin.getName() + ")"); + TLocale.Logger.info("COOLDOWNPACK.PACK-REGISTER", pack.getPackName(), String.valueOf(pack.getPackSeconds()), plugin.getName()); } public static void unregister(String name) { packlist.remove(name); - -// MsgUtils.send("注销冷却包: " + name + " (主动注销)"); + TLocale.Logger.info("COOLDOWNPACK.PACK-UNREGISTER", name); } - - @EventHandler + + private static void unregister(CooldownPack2 pack) { + packlist.remove(pack.getPackName()); + TLocale.Logger.info("COOLDOWNPACK.PACK-UNREGISTER-AUTO", pack.getPackName()); + } + + @EventHandler public void quit(PlayerQuitEvent e) { - for (CooldownPack2 pack : packlist.values()) { - if (!pack.isCooldown(e.getPlayer().getName(), 0)) { - pack.unRegister(e.getPlayer().getName()); - } - } + packlist.values().stream().filter(pack -> !pack.isCooldown(e.getPlayer().getName(), 0)).forEach(pack -> pack.unRegister(e.getPlayer().getName())); } @EventHandler public void disable(PluginDisableEvent e) { - for (CooldownPack2 pack : packlist.values()) { - if (pack.getPlugin().equals(e.getPlugin().getName())) { - packlist.remove(pack.getPackName()); - -// MsgUtils.send("注销冷却包: " + pack.getPackName() + " (自动注销)"); - } - } - } + packlist.values().stream().filter(pack -> pack.getPlugin().equals(e.getPlugin().getName())).forEach(CooldownUtils2::unregister); + } } diff --git a/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java b/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java index 0f4183c..e0af21f 100644 --- a/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java +++ b/src/main/java/me/skymc/taboolib/database/GlobalDataManager.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.concurrent.ConcurrentHashMap; +import com.ilummc.tlib.resources.TLocale; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.scheduler.BukkitRunnable; @@ -344,8 +345,7 @@ public class GlobalDataManager { // 移除 variables.remove(name); // 提示 - MsgUtils.warn("变量出现异常: &4" + name); - MsgUtils.warn("原因: &4" + e.getMessage()); + TLocale.Logger.error("GLOBAL-DATAMANAGER.ERROR-CHECK-VARIABLE", String.valueOf(name), e.toString()); } } } @@ -410,8 +410,8 @@ public class GlobalDataManager { // 载入数据 loadVariables(false); // 提示信息 - MsgUtils.send("从数据库中获取 &f" + variables.size() + " &7个变量, 耗时: &f" + (System.currentTimeMillis() - time) + " &7(ms)"); - + TLocale.Logger.info("GLOBAL-DATAMANAGER.SUCCESS-LOADED-VARIABLE", String.valueOf(variables.size()), String.valueOf(System.currentTimeMillis() - time)); + // 检查更新 new BukkitRunnable() { diff --git a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java index 5efcf54..d35db04 100644 --- a/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java +++ b/src/main/java/me/skymc/taboolib/database/PlayerDataManager.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.database; +import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.Main; import me.skymc.taboolib.Main.StorageType; import me.skymc.taboolib.events.PlayerLoadedEvent; @@ -83,7 +84,7 @@ public class PlayerDataManager implements Listener { return PLAYER_DATA.get(username); } else if (offline) { if (Main.getStorageType() == StorageType.SQL) { - throw new PlayerOfflineException("不允许在储存模式为数据库的情况下获取离线玩家数据"); + throw new PlayerOfflineException(TLocale.asString("PLAYER-DATAMANAGER.ERROR-STORAGE-SQL")); } return loadPlayerData(username); } @@ -115,7 +116,7 @@ public class PlayerDataManager implements Listener { // 创建空数据 PLAYER_DATA.put(username, new YamlConfiguration()); // 反馈信息 - MsgUtils.warn("玩家 &4" + username + " &c的数据载入出现异常: &4" + e.getMessage()); + TLocale.Logger.error("PLAYER-DATAMANAGER.ERROR-PLAYER-DATA", username, e.toString()); } } else { // 创建空数据 @@ -189,7 +190,7 @@ public class PlayerDataManager implements Listener { } // 提示 if (!Main.getInst().getConfig().getBoolean("HIDE-NOTIFY")) { - MsgUtils.send("保存 &f" + PLAYER_DATA.size() + " &7条玩家数据, 耗时: &f" + (System.currentTimeMillis() - time) + " &7(ms)"); + TLocale.Logger.info("PLAYER-DATAMANAGER.SUCCESS-SAVE-DATA", String.valueOf(PLAYER_DATA.size()), String.valueOf(System.currentTimeMillis() - time)); } } }; diff --git a/src/main/java/me/skymc/taboolib/entity/EntityUtils.java b/src/main/java/me/skymc/taboolib/entity/EntityUtils.java index 37d76dd..d3ebf19 100644 --- a/src/main/java/me/skymc/taboolib/entity/EntityUtils.java +++ b/src/main/java/me/skymc/taboolib/entity/EntityUtils.java @@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.exception.PluginNotFoundException; import org.bukkit.Bukkit; import org.bukkit.World; @@ -71,7 +72,7 @@ public class EntityUtils implements Listener { public static void addGlow(Player player, Entity entity) { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) { try { - throw new PluginNotFoundException("缺少前置插件 ProtocolLib"); + throw new PluginNotFoundException(TLocale.asString("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB")); } catch (Exception e) { // } @@ -99,7 +100,7 @@ public class EntityUtils implements Listener { public static void delGlow(Player player, Entity entity) { if (Bukkit.getPluginManager().getPlugin("ProtocolLib") == null) { try { - throw new PluginNotFoundException("缺少前置插件 ProtocolLib"); + throw new PluginNotFoundException(TLocale.asString("ENTITY-UTILS.NOTFOUND-PROTOCOLLIB")); } catch (Exception e) { // } diff --git a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java index d6ab8da..33fd672 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/ConfigUtils.java @@ -4,6 +4,7 @@ import com.google.common.collect.Maps; import com.google.common.io.Files; import com.ilummc.tlib.TLib; import com.ilummc.tlib.bean.Property; +import com.ilummc.tlib.resources.TLocale; import com.ilummc.tlib.util.Ref; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.MemoryConfiguration; @@ -179,9 +180,7 @@ public class ConfigUtils { configuration.loadFromString(yaml); return configuration; } catch (Exception e) { - TLib.getTLib().getLogger().error("配置文件载入失败!"); - TLib.getTLib().getLogger().error("插件: &4" + plugin.getName()); - TLib.getTLib().getLogger().error("文件: &4" + file); + TLocale.Logger.error("FILE-UTILS.FALL-LOAD-CONFIGURATION", plugin.getName(), file.getName()); } return configuration; } diff --git a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java index 86013ef..c329cc3 100644 --- a/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java +++ b/src/main/java/me/skymc/taboolib/fileutils/FileUtils.java @@ -2,51 +2,58 @@ package me.skymc.taboolib.fileutils; import ch.njol.util.Closeable; import me.skymc.taboolib.message.MsgUtils; +import org.apache.commons.io.IOUtils; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.nio.channels.FileChannel; +import java.util.Objects; public class FileUtils { public static String ip() { + URL url; + URLConnection con; + try { + url = new URL("http://1212.ip138.com/ic.asp"); + con = url.openConnection(); + } catch (Exception ignored) { + return "[IP ERROR]"; + } + InputStream ins = null; + InputStreamReader inputStreamReader = null; + BufferedReader bufferedReader = null; try { - InputStream ins = null; - URL url = new URL("http://1212.ip138.com/ic.asp"); - URLConnection con = url.openConnection(); ins = con.getInputStream(); - InputStreamReader isReader = new InputStreamReader(ins, "GB2312"); - BufferedReader bReader = new BufferedReader(isReader); + inputStreamReader = new InputStreamReader(ins, "GB2312"); + bufferedReader = new BufferedReader(inputStreamReader); StringBuilder webContent = new StringBuilder(); - String str = null; - while ((str = bReader.readLine()) != null) { - webContent.append(str); - } + bufferedReader.lines().forEach(webContent::append); int start = webContent.indexOf("[") + 1; int end = webContent.indexOf("]"); - ins.close(); return webContent.substring(start, end); - } catch (Exception e) { - // TODO: handle exception + } catch (Exception ignored) { + return "[IP ERROR]"; + } finally { + IOUtils.close(con); + IOUtils.closeQuietly(bufferedReader); + IOUtils.closeQuietly(inputStreamReader); + IOUtils.closeQuietly(ins); } - return "[IP ERROR]"; } /** - * 创建并获取文件 + * 检测文件并创建 * - * @param filePath - * @return + * @param file 文件 */ - public static File file(String filePath) { - File file = new File(filePath); - if (!file.exists()) { + public static File createNewFile(File file) { + if (file != null && !file.exists()) { try { file.createNewFile(); - } catch (IOException e) { - // TODO Auto-generated catch block + } catch (Exception ignored) { } } return file; @@ -55,26 +62,28 @@ public class FileUtils { /** * 创建并获取文件 * - * @param Path - * @param filePath + * @param Path 目录 + * @param filePath 地址 * @return */ public static File file(File Path, String filePath) { - File file = new File(Path, filePath); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (IOException e) { - // TODO Auto-generated catch block - } - } - return file; + return createNewFile(new File(Path, filePath)); + } + + /** + * 创建并获取文件 + * + * @param filePath 地址 + * @return {@link File} + */ + public static File file(String filePath) { + return createNewFile(new File(filePath)); } /** * 删除文件夹 * - * @param file + * @param file 文件夹 */ public void deleteAllFile(File file) { if (!file.exists()) { @@ -84,8 +93,7 @@ public class FileUtils { file.delete(); return; } - File[] files = file.listFiles(); - for (File file1 : files) { + for (File file1 : Objects.requireNonNull(file.listFiles())) { deleteAllFile(file1); } file.delete(); @@ -96,20 +104,19 @@ public class FileUtils { * * @param file1 文件1 * @param file2 文件2 - * @throws Exception */ - public void copyAllFile(String file1, String file2) throws Exception { + public void copyAllFile(String file1, String file2) { File _file1 = new File(file1); File _file2 = new File(file2); if (!_file2.exists()) { if (!_file1.isDirectory()) { - _file2.createNewFile(); + createNewFile(_file2); } else { _file2.mkdirs(); } } if (_file1.isDirectory()) { - for (File file : _file1.listFiles()) { + for (File file : Objects.requireNonNull(_file1.listFiles())) { if (file.isDirectory()) { copyAllFile(file.getAbsolutePath(), file2 + "/" + file.getName()); } else { @@ -138,43 +145,33 @@ public class FileUtils { channelIn = fileIn.getChannel(); channelOut = fileOut.getChannel(); channelIn.transferTo(0, channelIn.size(), channelOut); - } catch (Exception e) { - // + } catch (IOException ignored) { } finally { - try { - fileIn.close(); - channelIn.close(); - fileOut.close(); - channelOut.close(); - } catch (Exception e) { - // - } + IOUtils.closeQuietly(channelIn); + IOUtils.closeQuietly(channelOut); + IOUtils.closeQuietly(fileIn); + IOUtils.closeQuietly(fileOut); } } /** * 通过输入流读取文本 * - * @param in - * @param size - * @param encode - * @return + * @param in 输入流 + * @param size 大小 + * @param encode 编码 + * @return 文本 */ public static String getStringFromInputStream(InputStream in, int size, String encode) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); - byte[] b = new byte[size]; - int i = 0; - + int i; while ((i = in.read(b)) > 0) { bos.write(b, 0, i); } - - bos.close(); return new String(bos.toByteArray(), encode); - } catch (IOException e) { - MsgUtils.warn("输入流读取出错: &4" + e.getMessage()); + } catch (IOException ignored) { } return null; } @@ -182,30 +179,28 @@ public class FileUtils { /** * 通过文件读取文本 * - * @param file - * @param size - * @param encode - * @return + * @param file 文件 + * @param size 大小 + * @param encode 编码 + * @return 文本 */ public static String getStringFromFile(File file, int size, String encode) { + FileInputStream fin = null; + BufferedInputStream bin = null; try { - FileInputStream fin = new FileInputStream(file); - BufferedInputStream bin = new BufferedInputStream(fin); + fin = new FileInputStream(file); + bin = new BufferedInputStream(fin); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - byte[] b = new byte[size]; - int i = 0; - + int i; while ((i = bin.read(b)) > 0) { bos.write(b, 0, i); } - - bos.close(); - bin.close(); - fin.close(); return new String(bos.toByteArray(), encode); - } catch (IOException e) { - MsgUtils.warn("文件读取出错: &4" + e.getMessage()); + } catch (IOException ignored) { + } finally { + IOUtils.closeQuietly(bin); + IOUtils.closeQuietly(fin); } return null; } @@ -213,82 +208,80 @@ public class FileUtils { /** * 通过 URL 读取文本 * - * @param url - * @param size - * @return + * @param url 地址 + * @param def 默认值 + * @return 文本 */ - public static String getStringFromURL(String url, int size) { - try { - URLConnection conn = new URL(url).openConnection(); - BufferedInputStream bin = new BufferedInputStream(conn.getInputStream()); - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - - byte[] b = new byte[size]; - int i = 0; - - while ((i = bin.read(b)) > 0) { - bos.write(b, 0, i); - } - - bos.close(); - bin.close(); - return new String(bos.toByteArray(), conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding()); - } catch (IOException e) { - MsgUtils.warn("网络访问出错: &4" + e.getMessage()); - } - return null; - } - public static String getStringFromURL(String url, String def) { String s = getStringFromURL(url, 1024); return s == null ? def : s; } + /** + * 通过 URL 读取文本 + * + * @param url 地址 + * @param size 大小 + * @return 文本 + */ + public static String getStringFromURL(String url, int size) { + URLConnection conn = null; + BufferedInputStream bin = null; + try { + conn = new URL(url).openConnection(); + bin = new BufferedInputStream(conn.getInputStream()); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] b = new byte[size]; + int i; + while ((i = bin.read(b)) > 0) { + bos.write(b, 0, i); + } + return new String(bos.toByteArray(), conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding()); + } catch (IOException ignored) { + } finally { + IOUtils.close(conn); + IOUtils.closeQuietly(bin); + } + return null; + } + /** * 下载文件 * - * @param urlStr - * @param filename - * @param saveDir + * @param downloadURL 下载地址 + * @param file 保存位置 */ - public static void download(String urlStr, String filename, File saveDir) { + public static void download(String downloadURL, File file) { + HttpURLConnection conn = null; + InputStream inputStream = null; + FileOutputStream fos = null; try { - URL url = new URL(urlStr); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - - // 超时时间 + URL url = new URL(downloadURL); + conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5 * 1000); - // 防止屏蔽程序抓取而返回 403 错误 conn.setRequestProperty("User-Agent", "Mozilla/31.0 (compatible; MSIE 10.0; Windows NT; DigExt)"); - // 得到输入流 - InputStream inputStream = conn.getInputStream(); - // 获取数组 + inputStream = conn.getInputStream(); byte[] data = read(inputStream); - // 创建文件夹 - if (!saveDir.exists()) { - saveDir.mkdirs(); - } - - // 保存文件 - File file = new File(saveDir, filename); - FileOutputStream fos = new FileOutputStream(file); - - // 写入文件 + fos = new FileOutputStream(createNewFile(file)); fos.write(data); - - // 结束 - fos.close(); - inputStream.close(); - } catch (Exception e) { - e.printStackTrace(); + } catch (Exception ignored) { + } finally { + IOUtils.close(conn); + IOUtils.closeQuietly(fos); + IOUtils.closeQuietly(inputStream); } } + @Deprecated + public static void download(String downloadURL, String filename, File saveDir) { + download(downloadURL, new File(saveDir, filename)); + } + public static byte[] read(InputStream in) { byte[] buffer = new byte[1024]; - int len = 0; + int len; ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { while ((len = in.read(buffer)) != -1) { diff --git a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java b/src/main/java/me/skymc/taboolib/inventory/DropUtils.java index 538eb06..1ff941f 100644 --- a/src/main/java/me/skymc/taboolib/inventory/DropUtils.java +++ b/src/main/java/me/skymc/taboolib/inventory/DropUtils.java @@ -7,27 +7,24 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import java.util.stream.IntStream; + public class DropUtils { public static Item drop(Player player, ItemStack itemStack, double bulletSpread, double radius) { Location location = player.getLocation(); location.setY(location.getY() + 1.5); - Item item = player.getWorld().dropItem(location, itemStack); double yaw = Math.toRadians(-player.getLocation().getYaw() - 90.0F); double pitch = Math.toRadians(-player.getLocation().getPitch()); - - double x = 0; - double y = 0; - double z = 0; + double x; + double y; + double z; if (bulletSpread > 0) { double[] spread = {1.0D, 1.0D, 1.0D}; - for (int t = 0; t < 3; t++) { - spread[t] = ((NumberUtils.getRand().nextDouble() - NumberUtils.getRand().nextDouble()) * bulletSpread * 0.1D); - } - + IntStream.range(0, 3).forEach(t -> spread[t] = ((NumberUtils.getRandom().nextDouble() - NumberUtils.getRandom().nextDouble()) * bulletSpread * 0.1D)); x = Math.cos(pitch) * Math.cos(yaw) + spread[0]; y = Math.sin(pitch) + spread[1]; z = -Math.sin(yaw) * Math.cos(pitch) + spread[2]; @@ -36,9 +33,9 @@ public class DropUtils { y = Math.sin(pitch); z = -Math.sin(yaw) * Math.cos(pitch); } + Vector dirVel = new Vector(x, y, z); dirVel.normalize().multiply(radius); - item.setVelocity(dirVel); return item; } diff --git a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java index 997be6c..f3d02e9 100644 --- a/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java +++ b/src/main/java/me/skymc/taboolib/inventory/ItemUtils.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.inventory; +import com.ilummc.tlib.resources.TLocale; import me.clip.placeholderapi.PlaceholderAPI; import me.skymc.taboolib.Main; import me.skymc.taboolib.TabooLib; @@ -97,7 +98,7 @@ public class ItemUtils { reloadItemCache(); itemdir = YamlConfiguration.loadConfiguration(new File(Main.getInst().getConfig().getString("DATAURL.ITEMDIR"))); } catch (Exception e) { - MsgUtils.warn("物品库载入失败: &4" + e.getMessage()); + TLocale.Logger.error("ITEM-UTILS.FALL-LOAD-ITEMS", e.toString()); } } @@ -105,7 +106,7 @@ public class ItemUtils { FileConfiguration conf = ConfigUtils.load(Main.getInst(), file); for (String name : conf.getConfigurationSection("").getKeys(false)) { if (isExists(name)) { - MsgUtils.warn("无法载入载入物品 &4" + name + "&c, 因为它已经存在了"); + TLocale.Logger.error("ITEM-UTILS.FALL-LOAD-ITEMS", name); } else if (finalFile) { itemCachesFinal.put(name, loadItem(conf, name)); } else { @@ -124,19 +125,15 @@ public class ItemUtils { finalItemsFolder.mkdir(); } // 检查固定物品库中的物品 - for (File file : Objects.requireNonNull(finalItemsFolder.listFiles())) { - loadItemsFile(file, true); - } - MsgUtils.send("载入 " + (itemCaches.size() + itemCachesFinal.size()) + " 项缓存物品"); + Arrays.stream(Objects.requireNonNull(finalItemsFolder.listFiles())).forEach(file -> loadItemsFile(file, true)); + TLocale.Logger.info("ITEM-UTILS.SUCCESS-LOAD-CACHES", String.valueOf(itemCaches.size() + itemCachesFinal.size())); } public static void reloadItemName() { FileConfiguration conf = new Language("ITEM_NAME", Main.getInst(), true).getConfiguration(); itemlib.clear(); - for (String a : conf.getConfigurationSection("").getKeys(false)) { - itemlib.put(a, conf.getString(a)); - } - MsgUtils.send("载入 " + itemlib.size() + " 项物品名称"); + conf.getConfigurationSection("").getKeys(false).forEach(a -> itemlib.put(a, conf.getString(a))); + TLocale.Logger.info("ITEM-UTILS.SUCCESS-LOAD-NAMES", String.valueOf(itemlib.size())); } public static File getItemCacheFile() { @@ -149,7 +146,7 @@ public class ItemUtils { public static String getCustomName(ItemStack item) { if (item == null || item.getType().equals(Material.AIR)) { - return "空"; + return TLocale.asString("ITEM-UTILS.EMPTY-ITEM"); } int data = item.getType().getMaxDurability() == 0 ? item.getDurability() : 0; return item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : itemlib.get(item.getType() + ":" + data) == null ? item.getType().toString() : itemlib.get(item.getType() + ":" + data); @@ -424,8 +421,7 @@ public class ItemUtils { if (enchant != null) { meta.addEnchant(enchant, section.getInt("enchants." + preEnchant), true); } else { - MsgUtils.warn("&8" + preEnchant + " &c不是一个有效的附魔名称"); - MsgUtils.warn("&c输入 &4/taboolib enchants&c 查看所有附魔"); + TLocale.Logger.error("ITEM-UTILS.FALL-LOAD-ENCHANTS", preEnchant); } } } @@ -436,8 +432,7 @@ public class ItemUtils { if (flag != null) { meta.addItemFlags(flag); } else { - MsgUtils.warn("&8" + preFlag + " &c不是一个有效的标签名称"); - MsgUtils.warn("&c输入 &4/taboolib flags&c 查看所有标签"); + TLocale.Logger.error("ITEM-UTILS.FALL-LOAD-FLAG", preFlag); } } } @@ -456,8 +451,7 @@ public class ItemUtils { NumberUtils.getInteger(section.getString("potions." + prePotionName).split("-")[0]), NumberUtils.getInteger(section.getString("potions." + prePotionName).split("-")[1]) - 1), true); } else { - MsgUtils.warn("&8" + prePotionName + " &c不是一个有效的药水名称"); - MsgUtils.warn("&c输入 &4/taboolib potions&c 查看所有药水"); + TLocale.Logger.error("ITEM-UTILS.FALL-LOAD-POTION", prePotionName); } } } @@ -499,18 +493,16 @@ public class ItemUtils { _attr.setInteger("Operation", 0); } _attr.setString("AttributeName", asAttribute(name)); - _attr.setInteger("UUIDMost", NumberUtils.getRand().nextInt(Integer.MAX_VALUE)); - _attr.setInteger("UUIDLeast", NumberUtils.getRand().nextInt(Integer.MAX_VALUE)); + _attr.setInteger("UUIDMost", NumberUtils.getRandom().nextInt(Integer.MAX_VALUE)); + _attr.setInteger("UUIDLeast", NumberUtils.getRandom().nextInt(Integer.MAX_VALUE)); _attr.setString("Name", asAttribute(name)); if (!hand.equals("all")) { _attr.setString("Slot", hand); } - } catch (Exception e) { - MsgUtils.warn("&8" + name + " &c属性载入失败: &8" + e.getMessage()); + } catch (Exception ignored) { } } else { - MsgUtils.warn("&8" + name + " &c不是一个有效的属性名称"); - MsgUtils.warn("&c输入 &4/taboolib attributes&c 查看所有属性"); + TLocale.Logger.error("ITEM-UTILS.FALL-LOAD-POTION", name); } } } @@ -540,18 +532,16 @@ public class ItemUtils { _attr.setInteger("Operation", 0); } _attr.setString("AttributeName", asAttribute(name)); - _attr.setInteger("UUIDMost", NumberUtils.getRand().nextInt(Integer.MAX_VALUE)); - _attr.setInteger("UUIDLeast", NumberUtils.getRand().nextInt(Integer.MAX_VALUE)); + _attr.setInteger("UUIDMost", NumberUtils.getRandom().nextInt(Integer.MAX_VALUE)); + _attr.setInteger("UUIDLeast", NumberUtils.getRandom().nextInt(Integer.MAX_VALUE)); _attr.setString("Name", asAttribute(name)); if (!hand.equals("all")) { _attr.setString("Slot", hand); } - } catch (Exception e) { - MsgUtils.warn("&8" + name + " &c属性载入失败: &8" + e.getMessage()); + } catch (NumberFormatException ignored) { } } else { - MsgUtils.warn("&8" + name + " &c不是一个有效的属性名称"); - MsgUtils.warn("&c输入 &4/taboolib attributes&c 查看所有属性"); + TLocale.Logger.error("ITEM-UTILS.FALL-LOAD-POTION", name); } return nbt; } diff --git a/src/main/java/me/skymc/taboolib/object/WeightCategory.java b/src/main/java/me/skymc/taboolib/object/WeightCategory.java index b386767..98d8ca3 100644 --- a/src/main/java/me/skymc/taboolib/object/WeightCategory.java +++ b/src/main/java/me/skymc/taboolib/object/WeightCategory.java @@ -1,5 +1,6 @@ package me.skymc.taboolib.object; +@Deprecated public class WeightCategory { private String category; diff --git a/src/main/java/me/skymc/taboolib/object/WeightCollection.java b/src/main/java/me/skymc/taboolib/object/WeightCollection.java new file mode 100644 index 0000000..cb6d491 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/object/WeightCollection.java @@ -0,0 +1,99 @@ +package me.skymc.taboolib.object; + +import me.skymc.taboolib.other.NumberUtils; + +import javax.annotation.Nullable; +import javax.annotation.concurrent.ThreadSafe; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.CopyOnWriteArrayList; + +/** + * @Author sky + * @Since 2018-05-07 16:18 + */ +@ThreadSafe +public class WeightCollection { + + private final List weightList = new CopyOnWriteArrayList<>(); + + public int size() { + return weightList.size(); + } + + public List getWeightList() { + return weightList; + } + + public void add(int weightNumber, A weightObject) { + weightList.add(new WeightObject(weightNumber, weightObject)); + } + + public void remove(WeightObject weightObject) { + weightList.remove(weightObject); + } + + @Nullable + public WeightObject getWeight() { + int weightSum = weightList.stream().mapToInt(WeightObject::getWeightNumber).sum(); + if (weightSum > 0) { + Integer m = 0, n = NumberUtils.getRandom().nextInt(weightSum); + for (WeightObject weightObject : weightList) { + if (m <= n && n < m + weightObject.getWeightNumber()) { + return weightObject; + } + m += weightObject.getWeightNumber(); + } + } + return null; + } + + class WeightObject { + + private int weightNumber; + private B weightObject; + + public WeightObject(int weightNumber, B weightObject) { + this.weightNumber = weightNumber; + this.weightObject = weightObject; + } + + public int getWeightNumber() { + return weightNumber; + } + + public void setWeightNumber(int weightNumber) { + this.weightNumber = weightNumber; + } + + public B getWeightObject() { + return weightObject; + } + + public void setWeightObject(B weightObject) { + this.weightObject = weightObject; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof WeightObject)) { + return false; + } + WeightObject that = (WeightObject) o; + return getWeightNumber() == that.getWeightNumber() && Objects.equals(getWeightObject(), that.getWeightObject()); + } + + @Override + public int hashCode() { + return Objects.hash(getWeightNumber(), getWeightObject()); + } + + @Override + public String toString() { + return "weightNumber=" + "WeightObject{" + weightNumber + ", weightObject=" + weightObject + '}'; + } + } +} diff --git a/src/main/java/me/skymc/taboolib/other/NumberUtils.java b/src/main/java/me/skymc/taboolib/other/NumberUtils.java index a469276..988dd4c 100644 --- a/src/main/java/me/skymc/taboolib/other/NumberUtils.java +++ b/src/main/java/me/skymc/taboolib/other/NumberUtils.java @@ -5,38 +5,27 @@ import java.util.Random; public class NumberUtils { - private static Random rand = new Random(); + private static Random random = new Random(); private static DecimalFormat doubleFormat = new DecimalFormat("#.##"); - public static Random getRand() { - return rand; + public static Random getRandom() { + return random; } public static Double format(Double num) { return Double.valueOf(doubleFormat.format(num)); } - @Deprecated - public static int getRandom() { - return rand.nextInt(100); + public static int getRandomInteger(Number num1, Number num2) { + int min = Math.min(num1.intValue(), num2.intValue()); + int max = Math.max(num1.intValue(), num2.intValue()); + return (int) (random.nextDouble() * (max - min) + min); } - @Deprecated - public static boolean getChance(int a) { - return getRandom() <= a; - } - - public static int getRandomInteger(Number l, Number u) { - Integer ll = Math.min(l.intValue(), u.intValue()); - Integer uu = Math.max(l.intValue(), u.intValue()); - return rand.nextInt(uu) % (uu - ll + 1) + ll; - } - - public static double getRandomDouble(Number l, Number u) { - double ll = Math.min(l.doubleValue(), u.doubleValue()); - double uu = Math.max(l.doubleValue(), u.doubleValue()); - double d = ll + rand.nextDouble() * (uu - ll); - return Double.valueOf(doubleFormat.format(d)); + public static double getRandomDouble(Number num1, Number num2) { + double min = Math.min(num1.doubleValue(), num2.doubleValue()); + double max = Math.max(num1.doubleValue(), num2.doubleValue()); + return random.nextDouble() * (max - min) + min; } public static int getInteger(String s) { @@ -62,4 +51,14 @@ public class NumberUtils { return false; } } + + @Deprecated + public static Random getRand() { + return random; + } + + @Deprecated + public static boolean getChance(int a) { + return getRandom().nextInt(100) <= a; + } } diff --git a/src/main/java/me/skymc/taboolib/other/WeightUtils.java b/src/main/java/me/skymc/taboolib/other/WeightUtils.java index 78bcd9b..0ac7f43 100644 --- a/src/main/java/me/skymc/taboolib/other/WeightUtils.java +++ b/src/main/java/me/skymc/taboolib/other/WeightUtils.java @@ -4,6 +4,7 @@ import me.skymc.taboolib.object.WeightCategory; import java.util.List; +@Deprecated public class WeightUtils { public static String getStringByWeight(List categorys) { @@ -17,7 +18,7 @@ public class WeightUtils { return null; } - Integer n = NumberUtils.getRand().nextInt(weightSum); + Integer n = NumberUtils.getRandom().nextInt(weightSum); Integer m = 0; for (WeightCategory wc : categorys) { diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index f470690..eda38d2 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -11,7 +11,7 @@ DEPENDENCY: DOWNLOAD-SUCCESS: ' 下载 {0} 完成' DOWNLOAD-FAILED: - ' 下载 {0} 失败' - - ' 请手动下载 {1} 并重命名为 {2} 后放在 /TabooLib/libs 文件夹内' + - ' 请手动下载 {1} 并重命名为 {2} 后放在 /{0}/libs 文件夹内' PLUGIN-AUTOLOAD-FAIL: '{0} 所依赖的插件 {1} 尝试自动加载失败,请尝试手动下载' PLUGIN-LOAD-SUCCESS: ' {0} 请求的插件 {1} 加载成功' PLUGIN-LOAD-FAIL: ' {0} 请求的插件 {1} 加载失败' @@ -38,6 +38,38 @@ LOCALE: MISC: FIELD-COPY-FAILED: '拷贝 {0} 对象失败' FIELD-COPY-ERROR: '拷贝 {0} 对象出错:{1}' + +COOLDOWNPACK: + PACK-REGISTER: '注册冷却包: {0}, 时间: {1} 秒 ({2})' + PACK-REGISTER-ANONYMOUS: '注册冷却包: {0}, 时间: {1} 秒 (匿名注册)' + PACK-UNREGISTER: '注销冷却包: {0} (主动注销)' + PACK-UNREGISTER-AUTO: '注销冷却包: {0} (自动注销)' + +GLOBAL-DATAMANAGER: + ERROR-CHECK-VARIABLE: '&4变量 &c{0} &4载入异常: &c{1}' + SUCCESS-LOADED-VARIABLE: '&7从数据库中获取 &f{0} &7个变量, 耗时: &f{1} &7(ms)' + +PLAYER-DATAMANAGER: + ERROR-STORAGE-SQL: '不允许在储存模式为数据库的情况下获取离线玩家数据' + ERROR-PLAYER-DATA: '&4玩家 &c{0} &4的数据载入出现异常: &c{1}' + SUCCESS-SAVE-DATA: '&7保存 &f{0} &7条玩家数据, 耗时: &f{1} &7(ms)' + +ENTITY-UTILS: + NOTFOUND-PROTOCOLLIB: '缺少前置插件 ProtocolLib' + +FILE-UTILS: + FALL-LOAD-CONFIGURATION: '&4配置文件载入失败!, 插件: &c{0}&4, 文件: &c{1}' + +ITEM-UTILS: + FALL-LOAD-ITEMS: '物品库载入失败: &4{0}' + FALL-LOAD-ATTRIBUTE: '&c{0} &4不是一个有效的属性名称, 输入 &c/tlib attributes&4 查看所有属性' + FALL-LOAD-ENCHANT: '&c{0} &4不是一个有效的附魔名称, 输入 &c/tlib enchants&4 查看所有附魔' + FALL-LOAD-POTION: '&c{0} &4不是一个有效的药水名称, 输入 &c/tlib potions&4 查看所有药水' + FALL-LOAD-FLAG: '&c{0} &4不是一个有效的标签名称, 输入 &c/tlib flags&4 查看所有标签' + FALL-SAVE-EXISTS: '无法载入载入物品 &4{0}&c, 因为它已经存在了' + SUCCESS-LOAD-CACHES: '&7载入 &f{0} &7项缓存物品' + SUCCESS-LOAD-NAMES: '&7载入 &f{0} &7项物品名称' + EMPTY-ITEM: '空' COMMANDS: GLOBAL: @@ -55,35 +87,35 @@ COMMANDS: - '' - '§b§l----- §3§lTaooLib Commands §b§l-----' - '' - - '&f /taboolib save §8[§7名称§8] &6- §e保存手中物品' - - '&f /taboolib item §8[§7名称§8] §8<§7玩家§8> §8<§7数量§8> &6- §e给予玩家物品' - - '&f /taboolib iteminfo &6- §e查看物品信息' - - '&f /taboolib itemlist &6- §e查看所有物品' - - '&f /taboolib itemreload &6- §e重载物品缓存' + - '&f /{0} save §8[§7名称§8] &6- §e保存手中物品' + - '&f /{0} item §8[§7名称§8] §8<§7玩家§8> §8<§7数量§8> &6- §e给予玩家物品' + - '&f /{0} iteminfo &6- §e查看物品信息' + - '&f /{0} itemlist &6- §e查看所有物品' + - '&f /{0} itemreload &6- §e重载物品缓存' - '' - - '&f /taboolib attributes &6- §e查看所有属性' - - '&f /taboolib enchants &6- §e查看所有附魔' - - '&f /taboolib potions &6- §e查看所有药水' - - '&f /taboolib flags &6- §e查看所有标签' - - '&f /taboolib slots &6- §e查看所有部位' - - '&f /taboolib sounds &6- §e查看所有音效' + - '&f /{0} attributes &6- §e查看所有属性' + - '&f /{0} enchants &6- §e查看所有附魔' + - '&f /{0} potions &6- §e查看所有药水' + - '&f /{0} flags &6- §e查看所有标签' + - '&f /{0} slots &6- §e查看所有部位' + - '&f /{0} sounds &6- §e查看所有音效' - '' - - '&f /taboolib getvariable §8[§7-s|a§8] §8[§7键§8] &6- §e查看变量' - - '&f /taboolib setvariable §8[§7-s|a§8] §8[§7键§8] §8[§7值§8] &6- §e更改变量' + - '&f /{0} getvariable §8[§7-s|a§8] §8[§7键§8] &6- §e查看变量' + - '&f /{0} setvariable §8[§7-s|a§8] §8[§7键§8] §8[§7值§8] &6- §e更改变量' - '' - - '&f /taboolib cycle list &6- §e列出所有时间检查器' - - '&f /taboolib cycle info §8[§7名称§8] &6- §e查询检查器信息' - - '&f /taboolib cycle reset §8[§7名称§8] &6- §e初始化时间检查器' - - '&f /taboolib cycle update §8[§7名称§8] &6- §e更新时间检查器' + - '&f /{0} cycle list &6- §e列出所有时间检查器' + - '&f /{0} cycle info §8[§7名称§8] &6- §e查询检查器信息' + - '&f /{0} cycle reset §8[§7名称§8] &6- §e初始化时间检查器' + - '&f /{0} cycle update §8[§7名称§8] &6- §e更新时间检查器' - '' - - '&f /taboolib shell load §8[§7名称§8] &6- §e载入某个脚本' - - '&f /taboolib shell unload §8[§7名称§8] &6- §e卸载某个脚本' + - '&f /{0} shell load §8[§7名称§8] &6- §e载入某个脚本' + - '&f /{0} shell unload §8[§7名称§8] &6- §e卸载某个脚本' - '' - - '&f /taboolib tagprefix §8[§7名称§8] §8[§7文本§8] &6- §e设置玩家头顶前缀' - - '&f /taboolib tagsuffix §8[§7名称§8] §8[§7文本§8] &6- §e设置玩家头顶后缀' - - '&f /taboolib tagdelete §8[§7名称§8] &6- §e删除玩家称号数据' + - '&f /{0} tagprefix §8[§7名称§8] §8[§7文本§8] &6- §e设置玩家头顶前缀' + - '&f /{0} tagsuffix §8[§7名称§8] §8[§7文本§8] &6- §e设置玩家头顶后缀' + - '&f /{0} tagdelete §8[§7名称§8] &6- §e删除玩家称号数据' - '' - - '&f /taboolib importdata &6- §4向数据库导入本地数据 §8(该操作将会清空数据库)' + - '&f /{0} importdata &6- §4向数据库导入本地数据 §8(该操作将会清空数据库)' - '' SAVE: INVALID-NAME: '&8[&3&lTabooLib&8] &4请输入正确的名称' @@ -116,6 +148,11 @@ COMMANDS: INVALID-SHELL: '&8[&3&lTabooLib&8] &4脚本 &c{0} &4不存在' SUCCESS-LOAD: '&8[&3&lTabooLib&8] &7脚本 &f{0} &7已载入' SUCCESS-UNLOAD: '&8[&3&lTabooLib&8] &7脚本 &f{0} &7已卸载' + PLAYERTAG: + INVALID-PLAYER: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线' + SUCCESS-PREFIX-SET: '&8[&3&lTabooLib&8] &7设置玩家 &f{0} &7的前缀为 &f{1}' + SUCCESS-SUFFIX-SET: '&8[&3&lTabooLib&8] &7设置玩家 &f{0} &7的后缀为 &f{1}' + SUCCESS-DELETE: '&8[&3&lTabooLib&8] &7删除玩家 &f{0} &7的称号数据' INFO: INVALID-ITEM: '&8[&3&lTabooLib&8] &4请手持正确的物品' ITEM-INFO: @@ -171,6 +208,32 @@ COMMANDS: sound: hover: 点击复制音效 suggest: '{0}' + TIMECYCLE: + INVALID-CYCLE: '&8[&3&lTabooLib&8] &4检查器 &c{0} &4不存在' + CYCLE-UPDATE: '&8[&3&lTabooLib&8] &7检查器 &f{0} &7已更新' + CYCLE-RESET: '&8[&3&lTabooLib&8] &7检查器 &f{0} &7初始化完成' + CYCLE-INFO: + - '' + - '§b§l----- §3§lTimeCycle Info §b§l-----' + - '' + - ' §f- §7注册周期: §f{0}' + - ' §f- §7注册插件: §f{1}' + - ' §f- §7上次刷新时间: §f{2}' + - ' §f- §7下次刷新时间: §f{3}' + LIST: + HEAD: + - '' + - '§b§l----- §3§lTimeCycle List §b§l-----' + - '' + BODY: + - ==: JSON + text: ' §7- §f{0} <&8(点击复制)@copy>' + args: + copy: + hover: '§f点击复制' + suggest: '{0}' + FOOT: + - '' ATTRIBUTES: HEAD: - '' @@ -240,12 +303,25 @@ COMMANDS: hover: '§f点击复制' suggest: '{0}' FOOT: - - '' + - '' LANGUAGE2: + INVALID-PLAYER: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线' + SUCCESS-SEND: '&8[&3&lTabooLib&8] &7信息已发送, 耗时&f: {0}' HELP: - '' - '§b§l----- §3§lLanguage2 Commands §b§l-----' - '' - - '§f /language2 send §8[§7玩家/ALL§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示' - - '§f /language2 reload §6- §e重载语言库' - - '' \ No newline at end of file + - '§f /{0} send §8[§7玩家/ALL§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示' + - '§f /{0} reload §6- §e重载语言库' + - '' + TLOCALE: + INVALID-PLAYER: '&8[&3&lTabooLib&8] &4玩家 &c{0} &4不在线' + SUCCESS-RELOAD: '&8[&3&lTabooLib&8] &7重载完成' + SUCCESS-SEND: '&8[&3&lTabooLib&8] &7信息已发送, 耗时&f: {0}' + HELP: + - '' + - '§b§l----- §3§lTabooLibLoacle Commands §b§l-----' + - '' + - '§f /{0} send §8[§7玩家/ALL§8] §8[§7语言§8] §8<§7变量§8> §6- §e发送语言提示' + - '§f /{0} reload §6- §e重载语言库' + - '' From 674e993105081575aa925dac80a13a2a1568e829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Mon, 7 May 2018 23:58:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A5=BD=E5=83=8F=E6=B2=A1=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=B9=B2=E5=87=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inspectionProfiles/profiles_settings.xml | 3 + TabooLib.iml | 7 + src/main/java/com/ilummc/tlib/TLib.java | 12 +- .../com/ilummc/tlib/config/TLibConfig.java | 37 +- src/main/java/me/skymc/taboolib/Main.java | 3 + .../commands/internal/InternalArgument.java | 28 ++ .../commands/internal/InternalCommand.java | 4 +- .../internal/InternalCommandExecutor.java | 104 +++++- .../commands/internal/InternalSubCommand.java | 18 +- .../internal/InternalSubCommandExecutor.java | 23 +- .../internal/InternalSubCommandType.java | 2 +- .../plugin/TabooLibPluginCommand.java | 210 ++++++++++- .../taboolib/nms/item/impl/_164ItemUtils.java | 2 +- .../nms/item/impl/_1710ItemUtils.java | 2 +- .../taboolib/nms/item/impl/_194ItemUtils.java | 4 +- .../skymc/taboolib/playerdata/DataUtils.java | 5 +- .../me/skymc/taboolib/plugin/PluginUtils.java | 336 ++++++++++-------- .../me/skymc/taboolib/sign/SignUtils.java | 194 +++++----- .../taboolib/sign/TabooSignChangeEvent.java | 81 ++--- .../me/skymc/taboolib/string/ArrayUtils.java | 15 +- .../me/skymc/taboolib/string/Language.java | 230 ++++++------ .../me/skymc/taboolib/string/StringUtils.java | 63 ++++ .../taboolib/string/language2/Language2.java | 6 +- .../string/language2/Language2Format.java | 8 +- .../string/language2/Language2Value.java | 9 +- .../language2/value/Language2Sound.java | 9 +- .../string/language2/value/Language2Text.java | 9 +- .../taboolib/timecycle/TimeCycleManager.java | 311 ++++++++-------- .../me/skymc/taboolib/update/UpdateTask.java | 60 ++-- src/main/java/me/skymc/tlm/TLM.java | 20 +- .../tlm/module/sub/ModuleInventorySave.java | 322 ++++++++--------- .../me/skymc/tlm/module/sub/ModuleKits.java | 307 ++++++++-------- .../skymc/tlm/module/sub/ModuleTimeCycle.java | 187 +++++----- src/main/resources/lang/zh_CN.yml | 91 ++++- src/main/resources/plugin.yml | 3 + 35 files changed, 1603 insertions(+), 1122 deletions(-) create mode 100644 src/main/java/me/skymc/taboolib/commands/internal/InternalArgument.java diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml index 6b8114c..c0f74c4 100644 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -1,5 +1,8 @@ +