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("§b§l----- §3§lTaooLib Commands §b§l-----"); - 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- §8载入某个脚本"); - sender.sendMessage("§7 /taboolib shell/s unload [脚本] §f- §8卸载某个脚本"); - 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("§b§l----- §3§lTabooLib Commands §b§l-----"); + sender.sendMessage("§b§l----- §3§lLanguage2 Commands §b§l-----"); 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<§7变量§8> §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<§7数量§8>", "§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|a§8] §8[§7键§8]", "§e查看变量"); + helps.put("/taboolib setvariable §8[§7-s|a§8] §8[§7键§8] §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]", "§e载入某个脚本"); + helps.put("/taboolib shell unload §8[§7名称§8]", "§e卸载某个脚本"); + helps.put("§e", null); + helps.put("/taboolib importdata", "§4向数据库导入本地数据 §8(该操作将会清空数据库)"); + + if (sender instanceof ConsoleCommandSender || TabooLib.getVerint() < 10800) { + sender.sendMessage("§f"); + sender.sendMessage("§b§l----- §3§lTaooLib Commands §b§l-----"); + 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("§b§l----- §3§lTaooLib Commands §b§l-----"); 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("§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"); + } + + 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("§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"); + } + + @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("§b§l----- §3§lTaooLibraryModule Commands §b§l-----"); - 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("§b§l----- §3§lTaooLibraryModule Modules §b§l-----"); - 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 2018年2月18日 下午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 2018年2月18日 下午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("§b§l----- §3§lTaooLibraryModule Modules §b§l-----"); + 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 2018年2月18日 下午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 2018年2月18日 下午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姝e湪鍐峰嵈涓' +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'