mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
feat: 调整载入插件的异常判断
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
4a4cb932d7
commit
56131b1274
@ -47,9 +47,13 @@ public class YumPluginLoader implements PluginLoader {
|
|||||||
replaceJavaPluginLoaders(yumPluginLoader);
|
replaceJavaPluginLoaders(yumPluginLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void injectExistingPlugins(final YumPluginLoader yumPluginLoader) {
|
public static void inject(final String pname) {
|
||||||
for (final org.bukkit.plugin.Plugin p : Bukkit.getPluginManager().getPlugins()) {
|
injectExistingPlugin(Bukkit.getPluginManager().getPlugin(pname), yumPluginLoader);
|
||||||
if (p instanceof JavaPlugin) {
|
replaceJavaPluginLoaders(yumPluginLoader);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void injectExistingPlugin(final Plugin p, final YumPluginLoader yumPluginLoader) {
|
||||||
|
if (p != null && p instanceof JavaPlugin) {
|
||||||
final JavaPlugin jp = (JavaPlugin) p;
|
final JavaPlugin jp = (JavaPlugin) p;
|
||||||
try {
|
try {
|
||||||
final Field f = JavaPlugin.class.getDeclaredField("loader");
|
final Field f = JavaPlugin.class.getDeclaredField("loader");
|
||||||
@ -60,6 +64,11 @@ public class YumPluginLoader implements PluginLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void injectExistingPlugins(final YumPluginLoader yumPluginLoader) {
|
||||||
|
for (final org.bukkit.plugin.Plugin p : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
injectExistingPlugin(p, yumPluginLoader);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void replaceJavaPluginLoaders(final YumPluginLoader yumPluginLoader) {
|
private static void replaceJavaPluginLoaders(final YumPluginLoader yumPluginLoader) {
|
||||||
@ -75,10 +84,8 @@ public class YumPluginLoader implements PluginLoader {
|
|||||||
final Iterator<Map.Entry<Pattern, PluginLoader>> iter = map.entrySet().iterator();
|
final Iterator<Map.Entry<Pattern, PluginLoader>> iter = map.entrySet().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
final Entry<Pattern, PluginLoader> entry = iter.next();
|
final Entry<Pattern, PluginLoader> entry = iter.next();
|
||||||
if (entry.getValue() instanceof JavaPluginLoader) {
|
|
||||||
entry.setValue(yumPluginLoader);
|
entry.setValue(yumPluginLoader);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
field.set(spm, map);
|
field.set(spm, map);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
Bukkit.getServer().getLogger().log(Level.SEVERE, "Yum failed replacing the existing PluginLoader, contact the developers on YUMC!", e);
|
Bukkit.getServer().getLogger().log(Level.SEVERE, "Yum failed replacing the existing PluginLoader, contact the developers on YUMC!", e);
|
||||||
|
@ -324,24 +324,34 @@ public class PluginsManager {
|
|||||||
public boolean load(final CommandSender sender, final File pluginFile, final boolean clean) {
|
public boolean load(final CommandSender sender, final File pluginFile, final boolean clean) {
|
||||||
Plugin target = null;
|
Plugin target = null;
|
||||||
final String name = pluginFile.getName();
|
final String name = pluginFile.getName();
|
||||||
if (clean) {
|
String pname = name;
|
||||||
YumPluginLoader.inject();
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
target = Bukkit.getPluginManager().loadPlugin(pluginFile);
|
try {
|
||||||
|
try {
|
||||||
|
final PluginDescriptionFile pluginDescriptionFile = main.getPluginLoader().getPluginDescription(pluginFile);
|
||||||
|
pname = pluginDescriptionFile.getName();
|
||||||
} catch (final InvalidDescriptionException e) {
|
} catch (final InvalidDescriptionException e) {
|
||||||
sender.sendMessage("§4异常: §c" + e.getMessage());
|
sender.sendMessage("§4异常: §c" + e.getMessage());
|
||||||
sender.sendMessage("§4插件: §c" + name + " 的 plugin.yml 文件存在错误!");
|
sender.sendMessage("§4插件: §c" + name + " 的 plugin.yml 文件存在错误!");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
target = Bukkit.getPluginManager().loadPlugin(pluginFile);
|
||||||
} catch (final UnsupportedClassVersionError e) {
|
} catch (final UnsupportedClassVersionError e) {
|
||||||
sender.sendMessage("§4异常: §c" + e.getMessage());
|
sender.sendMessage("§4异常: §c" + e.getMessage());
|
||||||
sender.sendMessage("§c服务器或JAVA的版本低于插件: " + name + " 所需要的版本!!");
|
sender.sendMessage("§c服务器或JAVA的版本低于插件: " + name + " 所需要的版本!!");
|
||||||
return false;
|
return false;
|
||||||
} catch (final InvalidPluginException e) {
|
} catch (final InvalidPluginException e) {
|
||||||
|
if (e.getMessage().equalsIgnoreCase("Plugin already initialized!")) {
|
||||||
if (!clean) {
|
if (!clean) {
|
||||||
|
YumPluginLoader.inject(pname);
|
||||||
return load(sender, pluginFile, true);
|
return load(sender, pluginFile, true);
|
||||||
}
|
}
|
||||||
sender.sendMessage("§4异常: §c" + e.getMessage());
|
sender.sendMessage("§4异常: §c" + e.getMessage());
|
||||||
|
sender.sendMessage("§4插件: §c" + name + " 已载入到服务器!");
|
||||||
|
sender.sendMessage("§4注意: §c当前插件无法在运行时重载 请重启服务器!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
sender.sendMessage("§4异常: §c" + e.getMessage());
|
||||||
sender.sendMessage("§4文件: §c" + name + " 不是一个可载入的插件!");
|
sender.sendMessage("§4文件: §c" + name + " 不是一个可载入的插件!");
|
||||||
sender.sendMessage("§4注意: §cMOD服重载插件3次以上需重启服务器");
|
sender.sendMessage("§4注意: §cMOD服重载插件3次以上需重启服务器");
|
||||||
return false;
|
return false;
|
||||||
@ -358,6 +368,13 @@ public class PluginsManager {
|
|||||||
Bukkit.getPluginManager().enablePlugin(target);
|
Bukkit.getPluginManager().enablePlugin(target);
|
||||||
sender.sendMessage("§6载入: §a插件 §b" + target.getName() + " §a版本 §d" + getVersion(target) + " §a已成功载入到服务器!");
|
sender.sendMessage("§6载入: §a插件 §b" + target.getName() + " §a版本 §d" + getVersion(target) + " §a已成功载入到服务器!");
|
||||||
return true;
|
return true;
|
||||||
|
} catch (final Throwable e) {
|
||||||
|
sender.sendMessage("§4错误: §c" + e.getClass().getName() + ": " + e.getMessage());
|
||||||
|
sender.sendMessage("§4异常: §c具体信息请查看后台异常堆栈!");
|
||||||
|
e.printStackTrace();
|
||||||
|
sender.sendMessage("§4载入: §c插件 §b" + target.getName() + " §c版本 §d" + getVersion(target) + " §c载入失败!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user