From 3984c816582bcd1ecdbec086dd66c5e9b91145b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9D=8F=E9=BB=91?= Date: Sun, 18 Feb 2018 16:37:22 +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.56?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 调整:命令 /lang2 提示调整 调整:命令 /tlib 提示改为 JSON 形式 调整:命令 /tlm 需要独立的权限才能列出帮助,子命令的执行不需要列出帮助的权限 新增:命令 /taboo cycle list 列出所有已注册的时间周期 新增:命令 /taboo cycle info 查询已注册的时间周期 新增:命令 /taboo cycle reset 初始化已注册的时间周期 新增:命令 /taboo cycle update 更新已注册的时间周期 新增:Language2 工具新增 send(CommandSender) 方法 新增:PlaceholderAPI 变量 %taboolib_tlm_kit_礼包名% 用于获取礼包状态 新增:TLM 框架新增 Kits 模块,用于管理礼包的发放 新增:命令 /tlm kit reward 领取礼包 新增:命令 /tlm kit reset 刷新礼包 新增:TLM 框架新增语言文件 "language2/zh_CN.yml" --- .../skymc/taboolib/commands/MainCommands.java | 31 +--- .../commands/language/Language2Command.java | 6 +- .../taboolib/commands/sub/HelpCommand.java | 80 +++++++++ .../commands/sub/cycle/CycleCommand.java | 39 +++++ .../commands/sub/cycle/CycleInfoCommand.java | 58 +++++++ .../commands/sub/cycle/CycleListCommand.java | 47 +++++ .../commands/sub/cycle/CycleResetCommand.java | 51 ++++++ .../sub/cycle/CycleUpdateCommand.java | 50 ++++++ .../string/language2/Language2Value.java | 14 ++ .../taboolib/support/SupportPlaceholder.java | 41 ++++- .../taboolib/timecycle/TimeCycleManager.java | 2 + src/main/src/me/skymc/tlm/TLM.java | 20 ++- .../src/me/skymc/tlm/command/TLMCommands.java | 63 +++---- .../skymc/tlm/command/sub/TLMKitCommand.java | 159 +++++++++++++++++ .../skymc/tlm/command/sub/TLMListCommand.java | 32 ++++ .../tlm/command/sub/TLMReloadCommand.java | 49 ++++++ .../me/skymc/tlm/module/sub/ModuleKits.java | 160 ++++++++++++++++++ .../skymc/tlm/module/sub/ModuleTimeCycle.java | 2 +- src/resources/Language2/zh_CN.yml | 37 ++++ src/resources/TLM/Kits.yml | 30 ++++ src/resources/module.yml | 6 +- 21 files changed, 906 insertions(+), 71 deletions(-) create mode 100644 src/main/src/me/skymc/taboolib/commands/sub/HelpCommand.java create mode 100644 src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java create mode 100644 src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java create mode 100644 src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java create mode 100644 src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java create mode 100644 src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java create mode 100644 src/main/src/me/skymc/tlm/command/sub/TLMKitCommand.java create mode 100644 src/main/src/me/skymc/tlm/command/sub/TLMListCommand.java create mode 100644 src/main/src/me/skymc/tlm/command/sub/TLMReloadCommand.java create mode 100644 src/main/src/me/skymc/tlm/module/sub/ModuleKits.java create mode 100644 src/resources/Language2/zh_CN.yml create mode 100644 src/resources/TLM/Kits.yml diff --git a/src/main/src/me/skymc/taboolib/commands/MainCommands.java b/src/main/src/me/skymc/taboolib/commands/MainCommands.java index decbe7b..a944415 100644 --- a/src/main/src/me/skymc/taboolib/commands/MainCommands.java +++ b/src/main/src/me/skymc/taboolib/commands/MainCommands.java @@ -15,6 +15,7 @@ import me.skymc.taboolib.TabooLib; import me.skymc.taboolib.commands.sub.AttributesCommand; import me.skymc.taboolib.commands.sub.EnchantCommand; import me.skymc.taboolib.commands.sub.FlagCommand; +import me.skymc.taboolib.commands.sub.HelpCommand; import me.skymc.taboolib.commands.sub.ImportCommand; import me.skymc.taboolib.commands.sub.InfoCommand; import me.skymc.taboolib.commands.sub.ItemCommand; @@ -23,6 +24,7 @@ import me.skymc.taboolib.commands.sub.SaveCommand; import me.skymc.taboolib.commands.sub.SlotCommand; import me.skymc.taboolib.commands.sub.VariableGetCommand; import me.skymc.taboolib.commands.sub.VariableSetCommand; +import me.skymc.taboolib.commands.sub.cycle.CycleCommand; import me.skymc.taboolib.commands.sub.itemlist.ItemListCommand; import me.skymc.taboolib.commands.sub.shell.ShellCommand; import me.skymc.taboolib.inventory.ItemUtils; @@ -32,30 +34,8 @@ public class MainCommands implements CommandExecutor{ @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if (args.length == 0) { - sender.sendMessage("f"); - sender.sendMessage("bl----- 3lTaooLib Commands bl-----"); - sender.sendMessage("f"); - sender.sendMessage("7 /taboolib save [] f- 8Ʒ"); - sender.sendMessage("7 /taboolib item/i [Ʒ] <> <> f- 8Ʒ"); - sender.sendMessage("7 /taboolib iteminfo f- 8鿴ƷϢ"); - sender.sendMessage("7 /taboolib itemlist f- 8鿴Ʒ"); - sender.sendMessage("7 /taboolib itemreload/ireload f- 8Ʒ"); - sender.sendMessage("f"); - sender.sendMessage("7 /taboolib attributes f- 8鿴"); - sender.sendMessage("7 /taboolib enchants f- 8鿴иħ"); - sender.sendMessage("7 /taboolib potions f- 8鿴ҩˮ"); - sender.sendMessage("7 /taboolib flags f- 8鿴бǩ"); - sender.sendMessage("7 /taboolib slots f- 8鿴вλ"); - sender.sendMessage("f"); - sender.sendMessage("7 /taboolib getvariable [-s|a] [] f- 8鿴"); - sender.sendMessage("7 /taboolib setvariable [-s|a] [] [ֵ] f- 8ı"); - sender.sendMessage("f"); - sender.sendMessage("7 /taboolib shell/s load [ű] f- 8ijű"); - sender.sendMessage("7 /taboolib shell/s unload [ű] f- 8жijű"); - sender.sendMessage("f"); - sender.sendMessage("c /taboolib importdata f- 4ݿ⵼뱾 8(òݿ)"); - sender.sendMessage("f"); + if (args.length == 0 || args[0].equalsIgnoreCase("help")) { + new HelpCommand(sender, args); } else if (args[0].equalsIgnoreCase("itemreload") || args[0].equalsIgnoreCase("ireload")) { ItemUtils.reloadItemCache(); @@ -101,6 +81,9 @@ public class MainCommands implements CommandExecutor{ else if (args[0].equalsIgnoreCase("shell") || args[0].equalsIgnoreCase("s")) { new ShellCommand(sender, args); } + else if (args[0].equalsIgnoreCase("cycle") || args[0].equalsIgnoreCase("c")) { + new CycleCommand(sender, args); + } else { MsgUtils.send(sender, "&4ָ"); } 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 e02b902..d7b4589 100644 --- a/src/main/src/me/skymc/taboolib/commands/language/Language2Command.java +++ b/src/main/src/me/skymc/taboolib/commands/language/Language2Command.java @@ -21,10 +21,10 @@ public class Language2Command implements CommandExecutor { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0) { sender.sendMessage("f"); - sender.sendMessage("bl----- 3lTabooLib Commands bl-----"); + sender.sendMessage("bl----- 3lLanguage2 Commands bl-----"); sender.sendMessage("f"); - sender.sendMessage("7 /language2 reload f- 8Կ"); - sender.sendMessage("7 /language2 send [] [] <> f- 8ʾ"); + sender.sendMessage("f /language2 send 8[7ҡ8] 8[7ԡ8] 8<78> 6- eʾ"); + sender.sendMessage("f /language2 reload 6- eԿ"); sender.sendMessage("f"); } else if (args[0].equalsIgnoreCase("reload")) { diff --git a/src/main/src/me/skymc/taboolib/commands/sub/HelpCommand.java b/src/main/src/me/skymc/taboolib/commands/sub/HelpCommand.java new file mode 100644 index 0000000..feb07eb --- /dev/null +++ b/src/main/src/me/skymc/taboolib/commands/sub/HelpCommand.java @@ -0,0 +1,80 @@ +package me.skymc.taboolib.commands.sub; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemFlag; + +import me.skymc.taboolib.TabooLib; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.jsonformatter.JSONFormatter; +import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; +import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; + +public class HelpCommand extends SubCommand { + + public HelpCommand(CommandSender sender, String[] args) { + super(sender, args); + + HashMap helps = new LinkedHashMap<>(); + helps.put("/taboolib save 8[7ơ8]", "eƷ"); + helps.put("/taboolib item 8[7ơ8] 8<7ҡ8> 8<78>", "eƷ"); + helps.put("/taboolib iteminfo", "e鿴ƷϢ"); + helps.put("/taboolib itemlist", "e鿴Ʒ"); + helps.put("/taboolib itemreload", "eƷ"); + helps.put("a", null); + helps.put("/taboolib attributes", "e鿴"); + helps.put("/taboolib enchants", "e鿴иħ"); + helps.put("/taboolib potions", "e鿴ҩˮ"); + helps.put("/taboolib flags", "e鿴бǩ"); + helps.put("/taboolib slots", "e鿴вλ"); + helps.put("b", null); + helps.put("/taboolib getvariable 8[7-s|a8] 8[78]", "e鿴"); + helps.put("/taboolib setvariable 8[7-s|a8] 8[78] 8[7ֵ8]", "eı"); + helps.put("c", null); + helps.put("/taboolib cycle list", "eгʱ"); + helps.put("/taboolib cycle info 8[7ơ8]", "eѯϢ"); + helps.put("/taboolib cycle reset 8[7ơ8]", "eʼʱ"); + helps.put("/taboolib cycle update 8[7ơ8]", "eʱ"); + helps.put("d", null); + helps.put("/taboolib shell load 8[7ơ8]", "eijű"); + helps.put("/taboolib shell unload 8[7ơ8]", "eжijű"); + helps.put("e", null); + helps.put("/taboolib importdata", "4ݿ⵼뱾 8(òݿ)"); + + if (sender instanceof ConsoleCommandSender || TabooLib.getVerint() < 10800) { + sender.sendMessage("f"); + sender.sendMessage("bl----- 3lTaooLib Commands bl-----"); + sender.sendMessage("f"); + // + for (Entry entry : helps.entrySet()) { + if (entry.getValue() == null) { + sender.sendMessage("f"); + } else { + sender.sendMessage("f " + entry.getKey() + " 6- " + entry.getValue()); + } + } + sender.sendMessage("f"); + } + else if (sender instanceof Player) { + JSONFormatter json = new JSONFormatter(); + json.append("f"); json.newLine(); + json.append("bl----- 3lTaooLib Commands bl-----"); json.newLine(); + json.append("f"); json.newLine(); + // + for (Entry entry : helps.entrySet()) { + if (entry.getValue() == null) { + json.append("f"); json.newLine(); + } else { + json.appendHoverClick("f " + entry.getKey() + " 6- " + entry.getValue(), new ShowTextEvent("fָ"), new SuggestCommandEvent(entry.getKey().split("")[0])); json.newLine(); + } + } + json.append("f"); + json.send((Player) sender); + } + } +} diff --git a/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java new file mode 100644 index 0000000..c7169a0 --- /dev/null +++ b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleCommand.java @@ -0,0 +1,39 @@ +package me.skymc.taboolib.commands.sub.cycle; + +import java.io.File; + +import org.bukkit.command.CommandSender; + +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.javashell.JavaShell; +import me.skymc.taboolib.message.MsgUtils; + +public class CycleCommand extends SubCommand { + + public CycleCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length > 1) { + if (args[1].equalsIgnoreCase("list")) { + new CycleListCommand(sender, args); + } + else if (args[1].equalsIgnoreCase("info")) { + new CycleInfoCommand(sender, args); + } + else if (args[1].equalsIgnoreCase("reset")) { + new CycleResetCommand(sender, args); + } + else if (args[1].equalsIgnoreCase("update")) { + new CycleUpdateCommand(sender, args); + } + } + else { + MsgUtils.send(sender, "&4ָ"); + } + } + + @Override + public boolean command() { + return true; + } + +} diff --git a/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java new file mode 100644 index 0000000..cea4dce --- /dev/null +++ b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleInfoCommand.java @@ -0,0 +1,58 @@ +package me.skymc.taboolib.commands.sub.cycle; + +import java.util.concurrent.TimeUnit; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.database.GlobalDataManager; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.other.DateUtils; +import me.skymc.taboolib.timecycle.TimeCycle; +import me.skymc.taboolib.timecycle.TimeCycleEvent; +import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent; +import me.skymc.taboolib.timecycle.TimeCycleManager; + +public class CycleInfoCommand extends SubCommand { + + public CycleInfoCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 3) { + MsgUtils.send(sender, "&cȷļ"); + return; + } + + TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]); + if (cycle == null) { + MsgUtils.send(sender, "&c &4" + args[2] + " &c"); + return; + } + + sender.sendMessage("f"); + sender.sendMessage("bl----- 3lTimeCycle Info bl-----"); + 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"); + } + + public String asString(long seconds) { + long day = TimeUnit.SECONDS.toDays(seconds); + long hours = TimeUnit.SECONDS.toHours(seconds) - day * 24; + long minute = TimeUnit.SECONDS.toMinutes(seconds) - TimeUnit.SECONDS.toHours(seconds) * 60L; + long second = TimeUnit.SECONDS.toSeconds(seconds) - TimeUnit.SECONDS.toMinutes(seconds) * 60L; + return "f" + day + "7 , f" + hours + "7 Сʱ, f" + minute + "7 , f" + second + "7 "; + } + + @Override + public boolean command() { + return true; + } + +} diff --git a/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java new file mode 100644 index 0000000..226602b --- /dev/null +++ b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleListCommand.java @@ -0,0 +1,47 @@ +package me.skymc.taboolib.commands.sub.cycle; + +import java.io.File; +import java.util.concurrent.TimeUnit; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.javashell.JavaShell; +import me.skymc.taboolib.jsonformatter.JSONFormatter; +import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent; +import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.timecycle.TimeCycle; +import me.skymc.taboolib.timecycle.TimeCycleManager; + +public class CycleListCommand extends SubCommand { + + public CycleListCommand(CommandSender sender, String[] args) { + super(sender, args); + + sender.sendMessage("f"); + sender.sendMessage("bl----- 3lTimeCycle List bl-----"); + 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"); + } + + @Override + public boolean command() { + return true; + } + +} diff --git a/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java new file mode 100644 index 0000000..9190436 --- /dev/null +++ b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleResetCommand.java @@ -0,0 +1,51 @@ +package me.skymc.taboolib.commands.sub.cycle; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.database.GlobalDataManager; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.timecycle.TimeCycle; +import me.skymc.taboolib.timecycle.TimeCycleEvent; +import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent; +import me.skymc.taboolib.timecycle.TimeCycleManager; + +public class CycleResetCommand extends SubCommand { + + public CycleResetCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 3) { + MsgUtils.send(sender, "&cȷļ"); + return; + } + + TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]); + if (cycle == null) { + MsgUtils.send(sender, "&c &4" + args[2] + " &c"); + return; + } + + new BukkitRunnable() { + + @Override + public void run() { + long time = new TimeCycleInitializeEvent(cycle, System.currentTimeMillis()).call().getTimeline(); + // ʼ + GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(time)); + // + Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle)); + // ʾ + MsgUtils.send(sender, " &f" + args[2] + " &7ʼ"); + } + }.runTaskAsynchronously(Main.getInst()); + } + + @Override + public boolean command() { + return true; + } + +} diff --git a/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java new file mode 100644 index 0000000..48bf00b --- /dev/null +++ b/src/main/src/me/skymc/taboolib/commands/sub/cycle/CycleUpdateCommand.java @@ -0,0 +1,50 @@ +package me.skymc.taboolib.commands.sub.cycle; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.scheduler.BukkitRunnable; + +import me.skymc.taboolib.Main; +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.database.GlobalDataManager; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.timecycle.TimeCycle; +import me.skymc.taboolib.timecycle.TimeCycleEvent; +import me.skymc.taboolib.timecycle.TimeCycleInitializeEvent; +import me.skymc.taboolib.timecycle.TimeCycleManager; + +public class CycleUpdateCommand extends SubCommand { + + public CycleUpdateCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length < 3) { + MsgUtils.send(sender, "&cȷļ"); + return; + } + + TimeCycle cycle = TimeCycleManager.getTimeCycle(args[2]); + if (cycle == null) { + MsgUtils.send(sender, "&c &4" + args[2] + " &c"); + return; + } + + new BukkitRunnable() { + + @Override + public void run() { + // + GlobalDataManager.setVariable("timecycle:" + cycle.getName(), String.valueOf(System.currentTimeMillis())); + // + Bukkit.getPluginManager().callEvent(new TimeCycleEvent(cycle)); + // ʾ + MsgUtils.send(sender, " &f" + args[2] + " &7Ѹ"); + } + }.runTaskAsynchronously(Main.getInst()); + } + + @Override + public boolean command() { + return true; + } + +} 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 af5eddb..136642e 100644 --- a/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java +++ b/src/main/src/me/skymc/taboolib/string/language2/Language2Value.java @@ -185,6 +185,20 @@ public class Language2Value { } } + /** + * ָ߷Ϣ + * + * @param sender + */ + public void send(CommandSender sender) { + if (sender instanceof Player) { + send((Player) sender); + } + else { + send(Bukkit.getPlayerExact("")); + } + } + /** * ȡı * diff --git a/src/main/src/me/skymc/taboolib/support/SupportPlaceholder.java b/src/main/src/me/skymc/taboolib/support/SupportPlaceholder.java index d3c09d3..4808939 100644 --- a/src/main/src/me/skymc/taboolib/support/SupportPlaceholder.java +++ b/src/main/src/me/skymc/taboolib/support/SupportPlaceholder.java @@ -5,9 +5,12 @@ import org.bukkit.plugin.Plugin; import me.clip.placeholderapi.external.EZPlaceholderHook; import me.skymc.taboolib.database.GlobalDataManager; +import me.skymc.tlm.TLM; +import me.skymc.tlm.module.TabooLibraryModule; +import me.skymc.tlm.module.sub.ModuleKits; public class SupportPlaceholder extends EZPlaceholderHook { - + public SupportPlaceholder(Plugin plugin, String identifier) { super(plugin, identifier); } @@ -22,6 +25,42 @@ public class SupportPlaceholder extends EZPlaceholderHook { } return GlobalDataManager.getVariableAsynchronous(sb.substring(0, sb.length() - 1), ""); } + if (args.startsWith("tlm_kit_")) { + // Ƿ + if (TabooLibraryModule.getInst().valueOf("Kits") == null) { + return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.0").asString(); + } + + // ȡģ + ModuleKits moduleKits = (ModuleKits) TabooLibraryModule.getInst().valueOf("Kits"); + String kit = args.split("_")[2]; + + // + if (!moduleKits.contains(kit)) { + return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.1").asString(); + } + + // Ƿȡ + if (moduleKits.isPlayerRewared(player, kit)) { + // Ƿֻȡһ + if (moduleKits.isDisposable(kit)) { + return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.2").asString(); + } + // Ƿȴ + if (moduleKits.isPlayerCooldown(player, kit)) { + return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.4").asString(); + } + } + + // ǷȨȡ + String permission = moduleKits.getPermission(kit); + if (permission != null && !player.hasPermission(permission)) { + return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.5").asString(); + } + + // ȡ + return TLM.getInst().getLanguage().get("KIT-PLACEHOLDER.3").asString(); + } return null; } diff --git a/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java b/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java index cbf4e90..a8aed03 100644 --- a/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java +++ b/src/main/src/me/skymc/taboolib/timecycle/TimeCycleManager.java @@ -135,6 +135,8 @@ public class TimeCycleManager { return 0L; } + + public static void load() { // ע new BukkitRunnable() { diff --git a/src/main/src/me/skymc/tlm/TLM.java b/src/main/src/me/skymc/tlm/TLM.java index c4b7592..86de669 100644 --- a/src/main/src/me/skymc/tlm/TLM.java +++ b/src/main/src/me/skymc/tlm/TLM.java @@ -7,7 +7,9 @@ import lombok.Getter; import me.skymc.taboolib.Main; import me.skymc.taboolib.fileutils.ConfigUtils; import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.string.language2.Language2; import me.skymc.tlm.module.TabooLibraryModule; +import me.skymc.tlm.module.sub.ModuleKits; import me.skymc.tlm.module.sub.ModuleTimeCycle; /** @@ -21,18 +23,27 @@ public class TLM { @Getter private FileConfiguration config; + @Getter + private Language2 language; + /** * 췽 */ private TLM() { // ļ reloadConfig(); + // ģ if (isEnableModule("TimeCycle")) { TabooLibraryModule.getInst().register(new ModuleTimeCycle()); } + if (isEnableModule("Kits")) { + TabooLibraryModule.getInst().register(new ModuleKits()); + } + // ģ TabooLibraryModule.getInst().loadModules(); + // ʾ MsgUtils.send(" &f" + TabooLibraryModule.getInst().getSize() + " &7 &fTLM &7ģ"); } @@ -58,6 +69,13 @@ public class TLM { */ public void reloadConfig() { config = ConfigUtils.saveDefaultConfig(Main.getInst(), "module.yml"); + // ļ + try { + language = new Language2(config.getString("Language"), Main.getInst()); + } catch (Exception e) { + MsgUtils.warn("ļ: &4" + config.getString("Language")); + return; + } } /** @@ -66,7 +84,7 @@ public class TLM { * @param name * @return boolean */ - private boolean isEnableModule(String name) { + public boolean isEnableModule(String name) { return config.getStringList("EnableModule").contains(name); } } diff --git a/src/main/src/me/skymc/tlm/command/TLMCommands.java b/src/main/src/me/skymc/tlm/command/TLMCommands.java index 6cf9c9e..7abff81 100644 --- a/src/main/src/me/skymc/tlm/command/TLMCommands.java +++ b/src/main/src/me/skymc/tlm/command/TLMCommands.java @@ -4,11 +4,10 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -import me.skymc.taboolib.TabooLib; -import me.skymc.taboolib.message.MsgUtils; import me.skymc.tlm.TLM; -import me.skymc.tlm.module.ITabooLibraryModule; -import me.skymc.tlm.module.TabooLibraryModule; +import me.skymc.tlm.command.sub.TLMKitCommand; +import me.skymc.tlm.command.sub.TLMListCommand; +import me.skymc.tlm.command.sub.TLMReloadCommand; /** * @author sky @@ -18,48 +17,32 @@ public class TLMCommands implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) { - if (args.length == 0) { - sender.sendMessage("f"); - sender.sendMessage("bl----- 3lTaooLibraryModule Commands bl-----"); - sender.sendMessage("f"); - sender.sendMessage("7 /tlm list f- 8гģ"); - sender.sendMessage("7 /tlm reload [ģ/TLM/ALL] f- 8ļ"); - sender.sendMessage("f"); + if (args.length == 0 || args[0].equalsIgnoreCase("help")) { + if (sender.hasPermission("taboolib.admin")) { + TLM.getInst().getLanguage().get("COMMAND-HELP").send(sender); + } else { + TLM.getInst().getLanguage().get("NOPERMISSION-HELP").send(sender); + } } else if (args[0].equalsIgnoreCase("reload")) { - if (args.length != 2) { - MsgUtils.send(sender, "&4"); - } - - else if (args[1].equalsIgnoreCase("tlm")) { - TLM.getInst().reloadConfig(); - MsgUtils.send(sender, "&fTLM &7ļء"); - } - - else if (args[1].equalsIgnoreCase("all")) { - TabooLibraryModule.getInst().reloadConfig(); - MsgUtils.send(sender, "ģļء"); - } - - else { - ITabooLibraryModule module = TabooLibraryModule.getInst().valueOf(args[1]); - if (module == null) { - MsgUtils.send(sender, "&4ģ &c" + args[1] + " &4ڡ"); - } - else { - TabooLibraryModule.getInst().reloadConfig(module, true); - MsgUtils.send(sender, "ģ &f" + args[1] + " &7ļء"); - } + if (sender.hasPermission("taboolib.admin")) { + new TLMReloadCommand(sender, args); + } else { + TLM.getInst().getLanguage().get("NOPERMISSION-RELOAD").send(sender); } } else if (args[0].equalsIgnoreCase("list")) { - sender.sendMessage("f"); - sender.sendMessage("bl----- 3lTaooLibraryModule Modules bl-----"); - sender.sendMessage("f"); - for (ITabooLibraryModule module : TabooLibraryModule.getInst().keySet()) { - sender.sendMessage("f - 8" + module.getName()); + if (sender.hasPermission("taboolib.admin")) { + new TLMListCommand(sender, args); + } else { + TLM.getInst().getLanguage().get("NOPERMISSION-LIST").send(sender); } - sender.sendMessage("f"); + } + else if (args[0].equalsIgnoreCase("kit")) { + new TLMKitCommand(sender, args); + } + else { + TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender); } return true; } diff --git a/src/main/src/me/skymc/tlm/command/sub/TLMKitCommand.java b/src/main/src/me/skymc/tlm/command/sub/TLMKitCommand.java new file mode 100644 index 0000000..3dd2a35 --- /dev/null +++ b/src/main/src/me/skymc/tlm/command/sub/TLMKitCommand.java @@ -0,0 +1,159 @@ +package me.skymc.tlm.command.sub; + +import java.util.HashMap; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.tlm.TLM; +import me.skymc.tlm.module.TabooLibraryModule; +import me.skymc.tlm.module.sub.ModuleKits; + +/** + * @author sky + * @since 2018218 2:53:58 + */ +public class TLMKitCommand extends SubCommand { + + /** + * @param sender + * @param args + */ + public TLMKitCommand(CommandSender sender, String[] args) { + super(sender, args); + if (TabooLibraryModule.getInst().valueOf("Kits") == null) { + TLM.getInst().getLanguage().get("KIT-DISABLE").send(sender); + return; + } + + // ȡģ + ModuleKits moduleKits = (ModuleKits) TabooLibraryModule.getInst().valueOf("Kits"); + + // ж + if (args.length == 1) { + TLM.getInst().getLanguage().get("KIT-EMPTY").send(sender); + return; + } + + else if (args[1].equalsIgnoreCase("reward")) { + // жȨ + if (!sender.hasPermission("taboolib.kit.reward")) { + TLM.getInst().getLanguage().get("NOPERMISSION-KIT-REWARD").send(sender); + return; + } + + // + if (args.length < 3) { + TLM.getInst().getLanguage().get("KIT-NAME").send(sender); + return; + } + + // + if (!moduleKits.contains(args[2])) { + TLM.getInst().getLanguage().get("KIT-NOTFOUND").addPlaceholder("$kit", args[2]).send(sender); + return; + } + + // ȡ + Player player; + if (args.length > 3) { + player = Bukkit.getPlayerExact(args[3]); + // Ҳ + if (player == null) { + TLM.getInst().getLanguage().get("KIT-OFFLINE").addPlaceholder("$name", args[3]).send(sender); + return; + } + } else if (sender instanceof Player) { + player = (Player) sender; + } else { + TLM.getInst().getLanguage().get("KIT-CONSOLE").send(sender); + return; + } + + // Ƿȡ + if (moduleKits.isPlayerRewared(player, args[2])) { + // Ƿֻȡһ + if (moduleKits.isDisposable(args[2])) { + TLM.getInst().getLanguage().get("KIT-DISPOSABLE").addPlaceholder("$kit", args[2]).send(sender); + return; + } + // Ƿȴ + if (moduleKits.isPlayerCooldown(player, args[2])) { + TLM.getInst().getLanguage().get("KIT-COOLDOWN").addPlaceholder("$kit", args[2]).send(sender); + return; + } + } + + // ǷȨȡ + String permission = moduleKits.getPermission(args[2]); + if (permission != null && !player.hasPermission(permission)) { + // ʾϢ + player.sendMessage(moduleKits.getPermissionMessage(args[2])); + return; + } + + // + List items = moduleKits.getItems(args[2]); + for (ItemStack item : items) { + // Ʒ + HashMap result = player.getInventory().addItem(item); + // ռ䲻 + if (result.size() > 0 && moduleKits.isFullDrop(args[2])) { + // Ʒ + player.getWorld().dropItem(player.getLocation(), item); + } + } + + // ȡ + moduleKits.setPlayerReward(player, args[2], true); + + // ʾϢ + TLM.getInst().getLanguage().get("KIT-SUCCESS").addPlaceholder("$kit", args[2]).send(sender); + } + else if (args[1].equalsIgnoreCase("reset")) { + // жȨ + if (!sender.hasPermission("taboolib.kit.reset")) { + TLM.getInst().getLanguage().get("NOPERMISSION-KIT-RESET").send(sender); + return; + } + + // + if (args.length < 3) { + TLM.getInst().getLanguage().get("KIT-NAME").send(sender); + return; + } + + // + if (!moduleKits.contains(args[2])) { + TLM.getInst().getLanguage().get("KIT-NOTFOUND").addPlaceholder("$kit", args[2]).send(sender); + return; + } + + // ȡ + Player player; + if (args.length > 3) { + player = Bukkit.getPlayerExact(args[3]); + // Ҳ + if (player == null) { + TLM.getInst().getLanguage().get("KIT-OFFLINE").addPlaceholder("$name", args[3]).send(sender); + return; + } + else { + moduleKits.setPlayerReward(player, args[2], false); + TLM.getInst().getLanguage().get("KIT-RESET-PLAYER").addPlaceholder("$kit", args[2]).addPlaceholder("$player", player.getName()).send(sender); + } + } else { + moduleKits.resetKit(args[2]); + TLM.getInst().getLanguage().get("KIT-RESET-ALL").addPlaceholder("$kit", args[2]).send(sender); + } + } + else { + TLM.getInst().getLanguage().get("COMMAND-ERROR").send(sender); + } + } + +} diff --git a/src/main/src/me/skymc/tlm/command/sub/TLMListCommand.java b/src/main/src/me/skymc/tlm/command/sub/TLMListCommand.java new file mode 100644 index 0000000..430a7d6 --- /dev/null +++ b/src/main/src/me/skymc/tlm/command/sub/TLMListCommand.java @@ -0,0 +1,32 @@ +package me.skymc.tlm.command.sub; + +import org.bukkit.command.CommandSender; + +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.tlm.module.ITabooLibraryModule; +import me.skymc.tlm.module.TabooLibraryModule; + +/** + * @author sky + * @since 2018218 2:10:12 + */ +public class TLMListCommand extends SubCommand { + + /** + * @param sender + * @param args + */ + public TLMListCommand(CommandSender sender, String[] args) { + super(sender, args); + sender.sendMessage("f"); + sender.sendMessage("bl----- 3lTaooLibraryModule Modules bl-----"); + sender.sendMessage("f"); + + for (ITabooLibraryModule module : TabooLibraryModule.getInst().keySet()) { + sender.sendMessage("f - 8" + module.getName()); + } + + sender.sendMessage("f"); + } + +} diff --git a/src/main/src/me/skymc/tlm/command/sub/TLMReloadCommand.java b/src/main/src/me/skymc/tlm/command/sub/TLMReloadCommand.java new file mode 100644 index 0000000..96059e5 --- /dev/null +++ b/src/main/src/me/skymc/tlm/command/sub/TLMReloadCommand.java @@ -0,0 +1,49 @@ +package me.skymc.tlm.command.sub; + +import org.bukkit.command.CommandSender; + +import me.skymc.taboolib.commands.SubCommand; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.tlm.TLM; +import me.skymc.tlm.module.ITabooLibraryModule; +import me.skymc.tlm.module.TabooLibraryModule; + +/** + * @author sky + * @since 2018218 2:09:34 + */ +public class TLMReloadCommand extends SubCommand { + + /** + * @param sender + * @param args + */ + public TLMReloadCommand(CommandSender sender, String[] args) { + super(sender, args); + if (args.length != 2) { + MsgUtils.send(sender, "&4"); + } + + else if (args[1].equalsIgnoreCase("tlm")) { + TLM.getInst().reloadConfig(); + MsgUtils.send(sender, "&fTLM &7ļء"); + } + + else if (args[1].equalsIgnoreCase("all")) { + TabooLibraryModule.getInst().reloadConfig(); + MsgUtils.send(sender, "ģļء"); + } + + else { + ITabooLibraryModule module = TabooLibraryModule.getInst().valueOf(args[1]); + if (module == null) { + MsgUtils.send(sender, "&4ģ &c" + args[1] + " &4ڡ"); + } + else { + TabooLibraryModule.getInst().reloadConfig(module, true); + MsgUtils.send(sender, "ģ &f" + args[1] + " &7ļء"); + } + } + } + +} diff --git a/src/main/src/me/skymc/tlm/module/sub/ModuleKits.java b/src/main/src/me/skymc/tlm/module/sub/ModuleKits.java new file mode 100644 index 0000000..d255695 --- /dev/null +++ b/src/main/src/me/skymc/tlm/module/sub/ModuleKits.java @@ -0,0 +1,160 @@ +package me.skymc.tlm.module.sub; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import me.skymc.taboolib.database.PlayerDataManager; +import me.skymc.taboolib.inventory.ItemUtils; +import me.skymc.taboolib.message.MsgUtils; +import me.skymc.taboolib.other.DateUtils; +import me.skymc.taboolib.other.NumberUtils; +import me.skymc.taboolib.playerdata.DataUtils; +import me.skymc.tlm.module.ITabooLibraryModule; + +/** + * @author sky + * @since 2018218 12:13:55 + */ +public class ModuleKits implements ITabooLibraryModule { + + private FileConfiguration data; + + @Override + public String getName() { + return "Kits"; + } + + @Override + public void onEnable() { + data = DataUtils.addPluginData("ModuleKits", null); + } + + /** + * Ƿȡ + * + * @param player + */ + public void setPlayerReward(Player player, String kit, boolean reward) { + data.set(kit + "." + player.getName(), reward ? System.currentTimeMillis() : null); + } + + /** + * + * + * @param kit + */ + public void resetKit(String kit) { + data.set(kit, null); + } + + /** + * Ƿȡ + * + * @param player + * @param kit + * @return boolean + */ + public boolean isPlayerRewared(Player player, String kit) { + return data.contains(kit + "." + player.getName()); + } + + /** + * Ƿȴ + * + * @param player + * @param kit + * @return + */ + public boolean isPlayerCooldown(Player player, String kit) { + return System.currentTimeMillis() - data.getLong(kit + "." + player.getName()) < getCooldown(kit); + } + + /** + * Ƿ + * + * @param kit + * @return boolean + */ + public boolean contains(String kit) { + return getConfig().contains("Kits." + kit); + } + + /** + * ȡȴʱ + * + * @param kit + * @return long + */ + public long getCooldown(String kit) { + return DateUtils.formatDate(getConfig().getString("Kits." + kit + ".Cooldown")); + } + + /** + * ȡռ䲻ʱĴʽ + * + * @param kit + * @return boolean + */ + public Boolean isFullDrop(String kit) { + return getConfig().getBoolean("Kits." + kit + ".FullDrop"); + } + + /** + * Ƿֻȡһ + * + * @param kit + * @return boolean + */ + public boolean isDisposable(String kit) { + return getConfig().getBoolean("Kits." + kit + ".Disposable"); + } + + /** + * ȡȨ + * + * @param kit + * @return String + */ + public String getPermission(String kit) { + return getConfig().getString("Kits." + kit + ".Permission"); + } + + /** + * ȡȨʾ + * + * @param kit + * @return String + */ + public String getPermissionMessage(String kit) { + return getConfig().getString("Kits." + kit + ".Permission-message").replace("&", ""); + } + + /** + * ȡƷ + * + * @param kit + * @return {@link List} + */ + public List getItems(String kit) { + List items = new ArrayList<>(); + for (String itemStr : getConfig().getStringList("Kits." + kit + ".Items")) { + ItemStack item = ItemUtils.getCacheItem(itemStr.split(" ")[0]); + if (item != null) { + item = item.clone(); + try { + item.setAmount(NumberUtils.getInteger(itemStr.split(" ")[1])); + items.add(item); + } catch (Exception e) { + MsgUtils.warn("ģ쳣: &4Ʒ"); + MsgUtils.warn("ģ: &4Kits"); + MsgUtils.warn("λ: &4" + itemStr); + } + } + } + return items; + } +} diff --git a/src/main/src/me/skymc/tlm/module/sub/ModuleTimeCycle.java b/src/main/src/me/skymc/tlm/module/sub/ModuleTimeCycle.java index 3e440c3..71f9e69 100644 --- a/src/main/src/me/skymc/tlm/module/sub/ModuleTimeCycle.java +++ b/src/main/src/me/skymc/tlm/module/sub/ModuleTimeCycle.java @@ -64,7 +64,7 @@ public class ModuleTimeCycle implements ITabooLibraryModule, Listener { int type = (int) Calendar.class.getField(typeStr.split("=")[0]).get(Calendar.class); date.set(type, NumberUtils.getInteger(typeStr.split("=")[1])); } catch (Exception err) { - MsgUtils.warn("ģ쳣"); + MsgUtils.warn("ģ쳣: &4ʹ"); MsgUtils.warn("ģ: &4TimeCycle"); MsgUtils.warn("λ: &4" + typeStr); } diff --git a/src/resources/Language2/zh_CN.yml b/src/resources/Language2/zh_CN.yml new file mode 100644 index 0000000..95a245f --- /dev/null +++ b/src/resources/Language2/zh_CN.yml @@ -0,0 +1,37 @@ +COMMAND-ERROR: '&8[&2&lTLM&8] &4指令错误' +COMMAND-HELP: +- '' +- '&b&l----- &3&lTaooLibraryModule Commands &b&l-----' +- '' +- '&f /tlm kit reward &8[&7名称] &8<&7名称&8> &6- &e领取礼包' +- '&f /tlm kit reset &8[&7名称] &8<&7玩家&8> &6- &e刷新礼包' +- '' +- '&f /tlm list &6- &e列出所有模块' +- '' +- '&f /tlm reload &8[&7模块名|TLM|ALL&8] &6- &e列出所有模块' +- '' + +NOPERMISSION-HELP: '&8[&2&lTLM&8] &4你没有权限列出帮助命令' +NOPERMISSION-LIST: '&8[&2&lTLM&8] &4你没有权限这么做' +NOPERMISSION-RELOAD: '&8[&2&lTLM&8] &4你没有权限这么做' +NOPERMISSION-KIT-REWARD: '&8[&2&lTLM&8] &4你没有权限这么做' +NOPERMISSION-KIT-RESET: '&8[&2&lTLM&8] &4你没有权限这么做' + +KIT-EMPTY: '&8[&2&lTLM&8] &4参数错误' +KIT-NAME: '&8[&2&lTLM&8] &4请输入正确的礼包名称' +KIT-DISABLE: '&8[&2&lTLM&8] &4该模块尚未在配置文件中启用' +KIT-NOTFOUND: '&8[&2&lTLM&8] &4礼包 &c$kit &4不存在' +KIT-OFFLINE: '&8[&2&lTLM&8] &4玩家 &c$name &4不在线' +KIT-CONSOLE: '&8[&2&lTLM&8] &4后台不允许输入这个指令' +KIT-COOLDOWN: '&8[&2&lTLM&8] &4礼包 &c$kit &4正在冷却中' +KIT-DISPOSABLE: '&8[&2&lTLM&8] &4礼包 &c$kit &4只能领取一次' +KIT-RESET-ALL: '&8[&2&lTLM&8] &7礼包 &f$kit &7已刷新' +KIT-RESET-PLAYER: '&8[&2&lTLM&8] &7玩家 &f$player &7的礼包 &f$kit &7已刷新' +KIT-SUCCESS: '&8[&2&lTLM&8] &7礼包 &f$kit &7已领取' +KIT-PLACEHOLDER: + 0: '&4模块未启用' + 1: '&4礼包不存在' + 2: '&8已领取' + 3: '&a可领取' + 4: '&4冷却中' + 5: '&4无权限' \ No newline at end of file diff --git a/src/resources/TLM/Kits.yml b/src/resources/TLM/Kits.yml new file mode 100644 index 0000000..0dbfa29 --- /dev/null +++ b/src/resources/TLM/Kits.yml @@ -0,0 +1,30 @@ +# 礼包配置 +Kits: + # 礼包名 + kit_name: + # 礼包刷新时间 + # ---------- # + # 1d = 1天 + # 1h = 1小时 + # 1m = 1分钟 + # 1s = 1秒钟 + # 时间之间用 ";" 分隔, 例如 1小时30分钟 = "1h;30m" + # ---------- # + Cooldown: '1d' + + # 背包空间不足时物品是否掉落 + FullDrop: true + + # 是否只能领取一次 + Disposable: false + + # 礼包领取权限 + Permission: 'taboolib.kit.kit_name' + + # 礼包领取权限提示 + Permission-message: '&4你没有权限领取这个礼包' + + # 礼包内容 + # 空格左侧为物品名,右侧为物品数量 + Items: + - 'UnlimitSword 1' \ No newline at end of file diff --git a/src/resources/module.yml b/src/resources/module.yml index bc13058..808f5e4 100644 --- a/src/resources/module.yml +++ b/src/resources/module.yml @@ -1,4 +1,8 @@ +# 语言文件 +Language: 'zh_CN' + # 启用模块 # 该配置需要重启服务器才会生效 EnableModule: -#- 'TimeCycle' \ No newline at end of file +#- 'TimeCycle' +#- 'Kits'