diff --git a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java index 596e55b..fff49a2 100644 --- a/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/PluginsManager.java @@ -14,8 +14,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -325,6 +323,10 @@ public class PluginsManager { sender.sendMessage("§4插件: §c" + name + " 载入失败 缺少部分依赖项目!"); return false; } + if (target == null) { + sender.sendMessage("§4异常: §c服务器类加载器载入插件失败!"); + return false; + } target.onLoad(); Bukkit.getPluginManager().enablePlugin(target); sender.sendMessage("§6载入: §a插件 §b" + target.getName() + " §a版本 §d" + target.getDescription().getVersion() + " §a已成功载入到服务器!"); @@ -509,7 +511,8 @@ public class PluginsManager { List plugins = null; Map lookupNames = null; Map knownCommands = null; - Map fileAssociations = null; + // ###移除类加载器后会导致插件无法载入### + // Map fileAssociations = null; if (pluginManager == null) { sender.sendMessage("§4异常: §c插件管理类反射获取失败!"); return false; @@ -531,9 +534,10 @@ public class PluginsManager { knownCommandsField.setAccessible(true); knownCommands = (Map) knownCommandsField.get(commandMap); - final Field fileAssociationsField = pluginManager.getClass().getDeclaredField("fileAssociations"); - fileAssociationsField.setAccessible(true); - fileAssociations = (Map) fileAssociationsField.get(pluginManager); + // ###移除类加载器后会导致插件无法载入### + // final Field fileAssociationsField = pluginManager.getClass().getDeclaredField("fileAssociations"); + // fileAssociationsField.setAccessible(true); + // fileAssociations = (Map) fileAssociationsField.get(pluginManager); } catch (final Exception e) { sender.sendMessage("§4异常: §c" + e.getMessage() + " 插件 §b" + name + " §c卸载失败!"); return false; @@ -571,16 +575,17 @@ public class PluginsManager { ((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的类加载器!"); - } - } - } + // ###移除类加载器后会导致插件无法载入### + // 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(); } } diff --git a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java index 3f51968..2b675da 100644 --- a/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java +++ b/src/main/java/cn/citycraft/Yum/manager/RepositoryManager.java @@ -13,8 +13,6 @@ import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; -import com.google.gson.JsonSyntaxException; - import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.jsonresult.JsonHandler; import cn.citycraft.PluginHelper.utils.IOUtil; @@ -174,7 +172,7 @@ public class RepositoryManager { public PackageInfo jsonToPackage(final String json) { try { return JsonHandler.fromJson(json, PackageInfo.class); - } catch (final JsonSyntaxException e) { + } catch (final Exception e) { return null; } }