From 934c4c4be396b50ade3bf9eda1b33b983c5f508b Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 29 Mar 2016 00:12:07 +0800 Subject: [PATCH] =?UTF-8?q?update(NetworkManager.java):=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=8B=A6=E6=88=AA=E6=8F=90=E7=A4=BA...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pw/yumc/Yum/manager/NetworkManager.java | 9 +++-- .../pw/yumc/Yum/manager/PluginsManager.java | 37 ++++++------------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/main/java/pw/yumc/Yum/manager/NetworkManager.java b/src/main/java/pw/yumc/Yum/manager/NetworkManager.java index ab7553f..21a1cd5 100644 --- a/src/main/java/pw/yumc/Yum/manager/NetworkManager.java +++ b/src/main/java/pw/yumc/Yum/manager/NetworkManager.java @@ -74,14 +74,15 @@ public class NetworkManager { final Plugin plugin = this.getRequestingPlugin(); final String urlinfo = uri.toString(); if (!urlinfo.startsWith("socket") && !urlinfo.toLowerCase().contains("yumc") && !urlinfo.toLowerCase().contains("pom.xml")) { - final String str = debug ? "[NetDebug] 插件 %s 尝试访问 %s 请注意服务器网络安全!" : "[NetManager] 插件 %s 尝试在主线程访问 %s 可能会导致服务器卡顿或无响应!"; + final String str = debug ? "§6[§bNetDebug§6] §c插件 §6%s §c尝试访问 §e%s §c请注意服务器网络安全!" : "§6[§bNetManager§6] §c插件 §6%s §c尝试在主线程访问 §e%s §4可能会导致服务器卡顿或无响应!"; if (plugin == null) { - main.getLogger().warning(String.format(str, "未知(请查看堆栈)", urlinfo)); + Bukkit.getConsoleSender().sendMessage(String.format(str, "未知(请查看堆栈)", urlinfo)); Thread.dumpStack(); } else if (!plugin.getName().equalsIgnoreCase("Yum")) { - main.getLogger().warning(String.format(str, plugin.getName(), urlinfo)); + Bukkit.getConsoleSender().sendMessage(String.format(str, plugin.getName(), urlinfo)); if (!allowPrimaryThread) { - throwException(new IOException("[NetManager] 已阻止插件 " + plugin.getName() + " 在主线程访问网络!")); + Bukkit.getConsoleSender().sendMessage("§6[§bNetManager§6] §4已阻止插件 §b" + plugin.getName() + " §4在主线程访问网络!"); + throwException(new IOException("Yum 已开启网络防护 不允许在主线程访问网络!")); } } } diff --git a/src/main/java/pw/yumc/Yum/manager/PluginsManager.java b/src/main/java/pw/yumc/Yum/manager/PluginsManager.java index 823675d..cb2d485 100644 --- a/src/main/java/pw/yumc/Yum/manager/PluginsManager.java +++ b/src/main/java/pw/yumc/Yum/manager/PluginsManager.java @@ -46,14 +46,14 @@ public class PluginsManager { private final Set ignoreList = new HashSet<>(); private final Plugin main; - public PluginsManager(final Plugin plugin) { - this.main = plugin; - } - public static String getVersion(final Plugin plugin) { return StringUtils.substring(plugin.getDescription().getVersion(), 0, 15); } + public PluginsManager(final Plugin plugin) { + this.main = plugin; + } + /** * 添加到忽略列表 * @@ -582,35 +582,22 @@ public class PluginsManager { sender.sendMessage("§6卸载: §a从插件查找列表删除 §b" + name + " §a的实例!"); } - if (commandMap != null) { - for (final Iterator> it = knownCommands.entrySet().iterator(); it.hasNext();) { - final Map.Entry entry = it.next(); - if ((entry.getValue() instanceof PluginCommand)) { - final PluginCommand command = (PluginCommand) entry.getValue(); - if (command.getPlugin() == next) { - command.unregister(commandMap); - it.remove(); - } + for (final Iterator> it = knownCommands.entrySet().iterator(); it.hasNext();) { + final Map.Entry entry = it.next(); + if ((entry.getValue() instanceof PluginCommand)) { + final PluginCommand command = (PluginCommand) entry.getValue(); + if (command.getPlugin() == next) { + command.unregister(commandMap); + it.remove(); } } - sender.sendMessage("§6卸载: §a注销插件 §b" + name + " §a的所有命令!"); } + sender.sendMessage("§6卸载: §a注销插件 §b" + name + " §a的所有命令!"); final ClassLoader cl = next.getClass().getClassLoader(); try { ((URLClassLoader) cl).close(); } catch (final IOException ex) { } - // ###移除类加载器后会导致插件无法载入### - // if (fileAssociations != null) { - // for (final Iterator> filter = fileAssociations.entrySet().iterator(); filter.hasNext();) { - // final Entry entry = filter.next(); - // final Matcher match = entry.getKey().matcher(getPluginFile(next).getName()); - // if (match.find()) { - // filter.remove(); - // sender.sendMessage("§6卸载: §a移除插件 §b" + name + " §a的类加载器!"); - // } - // } - // } System.gc(); } }