update(NetworkManager.java): 调整拦截提示...

dev
502647092 2016-03-29 00:12:07 +08:00
parent d46dfdf13d
commit 934c4c4be3
2 changed files with 17 additions and 29 deletions

View File

@ -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 已开启网络防护 不允许在主线程访问网络!"));
}
}
}

View File

@ -46,14 +46,14 @@ public class PluginsManager {
private final Set<String> 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<Map.Entry<String, Command>> it = knownCommands.entrySet().iterator(); it.hasNext();) {
final Map.Entry<String, Command> 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<Map.Entry<String, Command>> it = knownCommands.entrySet().iterator(); it.hasNext();) {
final Map.Entry<String, Command> 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<Entry<Pattern, PluginLoader>> filter = fileAssociations.entrySet().iterator(); filter.hasNext();) {
// final Entry<Pattern, PluginLoader> 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();
}
}