mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
移除类加载器问题...
This commit is contained in:
parent
8887c6e291
commit
5cae6bd373
@ -14,8 +14,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -325,6 +323,10 @@ public class PluginsManager {
|
|||||||
sender.sendMessage("§4插件: §c" + name + " 载入失败 缺少部分依赖项目!");
|
sender.sendMessage("§4插件: §c" + name + " 载入失败 缺少部分依赖项目!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (target == null) {
|
||||||
|
sender.sendMessage("§4异常: §c服务器类加载器载入插件失败!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
target.onLoad();
|
target.onLoad();
|
||||||
Bukkit.getPluginManager().enablePlugin(target);
|
Bukkit.getPluginManager().enablePlugin(target);
|
||||||
sender.sendMessage("§6载入: §a插件 §b" + target.getName() + " §a版本 §d" + target.getDescription().getVersion() + " §a已成功载入到服务器!");
|
sender.sendMessage("§6载入: §a插件 §b" + target.getName() + " §a版本 §d" + target.getDescription().getVersion() + " §a已成功载入到服务器!");
|
||||||
@ -509,7 +511,8 @@ public class PluginsManager {
|
|||||||
List<Plugin> plugins = null;
|
List<Plugin> plugins = null;
|
||||||
Map<String, Plugin> lookupNames = null;
|
Map<String, Plugin> lookupNames = null;
|
||||||
Map<String, Command> knownCommands = null;
|
Map<String, Command> knownCommands = null;
|
||||||
Map<Pattern, PluginLoader> fileAssociations = null;
|
// ###移除类加载器后会导致插件无法载入###
|
||||||
|
// Map<Pattern, PluginLoader> fileAssociations = null;
|
||||||
if (pluginManager == null) {
|
if (pluginManager == null) {
|
||||||
sender.sendMessage("§4异常: §c插件管理类反射获取失败!");
|
sender.sendMessage("§4异常: §c插件管理类反射获取失败!");
|
||||||
return false;
|
return false;
|
||||||
@ -531,9 +534,10 @@ public class PluginsManager {
|
|||||||
knownCommandsField.setAccessible(true);
|
knownCommandsField.setAccessible(true);
|
||||||
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
|
knownCommands = (Map<String, Command>) knownCommandsField.get(commandMap);
|
||||||
|
|
||||||
final Field fileAssociationsField = pluginManager.getClass().getDeclaredField("fileAssociations");
|
// ###移除类加载器后会导致插件无法载入###
|
||||||
fileAssociationsField.setAccessible(true);
|
// final Field fileAssociationsField = pluginManager.getClass().getDeclaredField("fileAssociations");
|
||||||
fileAssociations = (Map<Pattern, PluginLoader>) fileAssociationsField.get(pluginManager);
|
// fileAssociationsField.setAccessible(true);
|
||||||
|
// fileAssociations = (Map<Pattern, PluginLoader>) fileAssociationsField.get(pluginManager);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
sender.sendMessage("§4异常: §c" + e.getMessage() + " 插件 §b" + name + " §c卸载失败!");
|
sender.sendMessage("§4异常: §c" + e.getMessage() + " 插件 §b" + name + " §c卸载失败!");
|
||||||
return false;
|
return false;
|
||||||
@ -571,16 +575,17 @@ public class PluginsManager {
|
|||||||
((URLClassLoader) cl).close();
|
((URLClassLoader) cl).close();
|
||||||
} catch (final IOException ex) {
|
} catch (final IOException ex) {
|
||||||
}
|
}
|
||||||
if (fileAssociations != null) {
|
// ###移除类加载器后会导致插件无法载入###
|
||||||
for (final Iterator<Entry<Pattern, PluginLoader>> filter = fileAssociations.entrySet().iterator(); filter.hasNext();) {
|
// if (fileAssociations != null) {
|
||||||
final Entry<Pattern, PluginLoader> entry = filter.next();
|
// for (final Iterator<Entry<Pattern, PluginLoader>> filter = fileAssociations.entrySet().iterator(); filter.hasNext();) {
|
||||||
final Matcher match = entry.getKey().matcher(getPluginFile(next).getName());
|
// final Entry<Pattern, PluginLoader> entry = filter.next();
|
||||||
if (match.find()) {
|
// final Matcher match = entry.getKey().matcher(getPluginFile(next).getName());
|
||||||
filter.remove();
|
// if (match.find()) {
|
||||||
sender.sendMessage("§6卸载: §a移除插件 §b" + name + " §a的类加载器!");
|
// filter.remove();
|
||||||
}
|
// sender.sendMessage("§6卸载: §a移除插件 §b" + name + " §a的类加载器!");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
System.gc();
|
System.gc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,6 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||||
import cn.citycraft.PluginHelper.jsonresult.JsonHandler;
|
import cn.citycraft.PluginHelper.jsonresult.JsonHandler;
|
||||||
import cn.citycraft.PluginHelper.utils.IOUtil;
|
import cn.citycraft.PluginHelper.utils.IOUtil;
|
||||||
@ -174,7 +172,7 @@ public class RepositoryManager {
|
|||||||
public PackageInfo jsonToPackage(final String json) {
|
public PackageInfo jsonToPackage(final String json) {
|
||||||
try {
|
try {
|
||||||
return JsonHandler.fromJson(json, PackageInfo.class);
|
return JsonHandler.fromJson(json, PackageInfo.class);
|
||||||
} catch (final JsonSyntaxException e) {
|
} catch (final Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user