From ce4e6650d74b767baecc3f980febfe1319108f9d Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 18 Jul 2016 20:36:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/Yum/commands/NetCommand.java | 59 +++++++++++++++++-- .../Yum/listeners/PluginNetworkListener.java | 2 + .../pw/yumc/Yum/managers/ConfigManager.java | 10 +++- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/main/java/pw/yumc/Yum/commands/NetCommand.java b/src/main/java/pw/yumc/Yum/commands/NetCommand.java index 9a0c6d1..cfb919b 100644 --- a/src/main/java/pw/yumc/Yum/commands/NetCommand.java +++ b/src/main/java/pw/yumc/Yum/commands/NetCommand.java @@ -1,12 +1,30 @@ package pw.yumc.Yum.commands; +import java.util.HashMap; +import java.util.Map.Entry; + +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; + import cn.citycraft.PluginHelper.commands.HandlerCommand; import cn.citycraft.PluginHelper.commands.HandlerCommands; import cn.citycraft.PluginHelper.commands.InvokeCommandEvent; import cn.citycraft.PluginHelper.commands.InvokeSubCommand; import pw.yumc.Yum.Yum; +import pw.yumc.Yum.managers.ConfigManager; public class NetCommand implements HandlerCommands { + public static HashMap netlist = new HashMap<>(); + + private final String prefix = "§6[§bYum §a网络管理§6] "; + + private final String showlist = prefix + "§a自服务器启动以来尝试联网的插件列表如下:"; + private final String listprefix = " §6插件名称 §d联网次数"; + private final String list = "§6- §b&s §d%s"; + private final String no_net = prefix + "§a尚未检测到尝试联网的插件!"; + private final String add = prefix + "§a已添加插件 §b%s §a到网络 %s §a列表!"; + + private final String p_n_f = prefix + "§c插件 §b%s §c不存在!"; public NetCommand(final Yum yum) { final InvokeSubCommand cmdhandler = new InvokeSubCommand(yum, "net"); @@ -14,18 +32,49 @@ public class NetCommand implements HandlerCommands { cmdhandler.registerCommands(PluginTabComplete.instence); } + public static void addNetCount(final String pname) { + if (netlist.containsKey(pname)) { + netlist.put(pname, netlist.get(pname) + 1); + } else { + netlist.put(pname, 1); + } + } + @HandlerCommand(name = "list", aliases = "l", permission = "", description = "列出联网的插件") public void list(final InvokeCommandEvent e) { - + final CommandSender sender = e.getSender(); + if (netlist.isEmpty()) { + sender.sendMessage(no_net); + return; + } + sender.sendMessage(showlist); + sender.sendMessage(listprefix); + for (final Entry entry : netlist.entrySet()) { + sender.sendMessage(String.format(list, entry.getKey(), entry.getValue())); + } } - @HandlerCommand(name = "off", description = "禁止插件联网", possibleArguments = "[插件名称]") + @HandlerCommand(name = "off", minimumArguments = 1, description = "禁止插件联网", possibleArguments = "[插件名称]") public void off(final InvokeCommandEvent e) { - + final String pname = e.getArgs()[0]; + final CommandSender sender = e.getSender(); + if (Bukkit.getPluginManager().getPlugin(pname) == null) { + sender.sendMessage(String.format(p_n_f, pname)); + return; + } + ConfigManager.i().network.addToStringList(ConfigManager.BLACK, pname, false).save(); + sender.sendMessage(String.format(add, pname, "§c黑名单")); } - @HandlerCommand(name = "on", description = "允许插件联网", possibleArguments = "[插件名称]") + @HandlerCommand(name = "on", minimumArguments = 1, description = "允许插件联网", possibleArguments = "[插件名称]") public void on(final InvokeCommandEvent e) { - + final String pname = e.getArgs()[0]; + final CommandSender sender = e.getSender(); + if (Bukkit.getPluginManager().getPlugin(pname) == null) { + sender.sendMessage(String.format(p_n_f, pname)); + return; + } + ConfigManager.i().network.addToStringList(ConfigManager.IGNORE, pname, false).save(); + sender.sendMessage(String.format(add, pname, "§e白名单")); } } diff --git a/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java b/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java index 015ff43..dcfda80 100644 --- a/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java +++ b/src/main/java/pw/yumc/Yum/listeners/PluginNetworkListener.java @@ -7,6 +7,7 @@ import org.bukkit.plugin.Plugin; import cn.citycraft.PluginHelper.kit.PluginKit; import pw.yumc.Yum.Yum; +import pw.yumc.Yum.commands.NetCommand; import pw.yumc.Yum.events.PluginNetworkEvent; import pw.yumc.Yum.managers.ConfigManager; @@ -36,6 +37,7 @@ public class PluginNetworkListener implements Listener { if (urlinfo.startsWith("socket")) { return; } + NetCommand.addNetCount(plugin.getName()); if (ConfigManager.i().getNetworkWhiteURL().contains(e.getUrl().getHost())) { return; } diff --git a/src/main/java/pw/yumc/Yum/managers/ConfigManager.java b/src/main/java/pw/yumc/Yum/managers/ConfigManager.java index fb539e0..4db071e 100644 --- a/src/main/java/pw/yumc/Yum/managers/ConfigManager.java +++ b/src/main/java/pw/yumc/Yum/managers/ConfigManager.java @@ -8,9 +8,9 @@ import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.kit.PKit; public class ConfigManager { - private final static String ENABLE = "Enable"; - private final static String BLACK = "Black"; - private final static String IGNORE = "Ignore"; + public final static String ENABLE = "Enable"; + public final static String BLACK = "Black"; + public final static String IGNORE = "Ignore"; private final static ConfigManager i = new ConfigManager(PKit.i()); @@ -72,6 +72,10 @@ public class ConfigManager { return thread.getBoolean("MainThreadCheck", true); } + public boolean isMonitorDebug() { + return monitor.getBoolean("Debug"); + } + public boolean isMonitorEnable() { return monitor.getBoolean(ENABLE, true); }