mirror of
				https://e.coding.net/circlecloud/Yum.git
				synced 2025-11-04 05:06:02 +00:00 
			
		
		
		
	@@ -47,18 +47,27 @@ public class YumPluginLoader implements PluginLoader {
 | 
				
			|||||||
        replaceJavaPluginLoaders(yumPluginLoader);
 | 
					        replaceJavaPluginLoaders(yumPluginLoader);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void inject(final String pname) {
 | 
				
			||||||
 | 
					        injectExistingPlugin(Bukkit.getPluginManager().getPlugin(pname), yumPluginLoader);
 | 
				
			||||||
 | 
					        replaceJavaPluginLoaders(yumPluginLoader);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static void injectExistingPlugin(final Plugin p, final YumPluginLoader yumPluginLoader) {
 | 
				
			||||||
 | 
					        if (p != null && p instanceof JavaPlugin) {
 | 
				
			||||||
 | 
					            final JavaPlugin jp = (JavaPlugin) p;
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                final Field f = JavaPlugin.class.getDeclaredField("loader");
 | 
				
			||||||
 | 
					                f.setAccessible(true);
 | 
				
			||||||
 | 
					                f.set(jp, yumPluginLoader);
 | 
				
			||||||
 | 
					            } catch (final Exception e) {
 | 
				
			||||||
 | 
					                Bukkit.getServer().getLogger().log(Level.SEVERE, "Yum failed injecting " + jp.getDescription().getFullName() + " with the new PluginLoader, contact the developers on YUMC!", e);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static void injectExistingPlugins(final YumPluginLoader yumPluginLoader) {
 | 
					    private static void injectExistingPlugins(final YumPluginLoader yumPluginLoader) {
 | 
				
			||||||
        for (final org.bukkit.plugin.Plugin p : Bukkit.getPluginManager().getPlugins()) {
 | 
					        for (final org.bukkit.plugin.Plugin p : Bukkit.getPluginManager().getPlugins()) {
 | 
				
			||||||
            if (p instanceof JavaPlugin) {
 | 
					            injectExistingPlugin(p, yumPluginLoader);
 | 
				
			||||||
                final JavaPlugin jp = (JavaPlugin) p;
 | 
					 | 
				
			||||||
                try {
 | 
					 | 
				
			||||||
                    final Field f = JavaPlugin.class.getDeclaredField("loader");
 | 
					 | 
				
			||||||
                    f.setAccessible(true);
 | 
					 | 
				
			||||||
                    f.set(jp, yumPluginLoader);
 | 
					 | 
				
			||||||
                } catch (final Exception e) {
 | 
					 | 
				
			||||||
                    Bukkit.getServer().getLogger().log(Level.SEVERE, "Yum failed injecting " + jp.getDescription().getFullName() + " with the new PluginLoader, contact the developers on YUMC!", e);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -75,9 +84,7 @@ 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) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -324,40 +324,57 @@ 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 {
 | 
				
			||||||
        } catch (final InvalidDescriptionException e) {
 | 
					                try {
 | 
				
			||||||
            sender.sendMessage("§4异常: §c" + e.getMessage());
 | 
					                    final PluginDescriptionFile pluginDescriptionFile = main.getPluginLoader().getPluginDescription(pluginFile);
 | 
				
			||||||
            sender.sendMessage("§4插件: §c" + name + " 的 plugin.yml 文件存在错误!");
 | 
					                    pname = pluginDescriptionFile.getName();
 | 
				
			||||||
            return false;
 | 
					                } catch (final InvalidDescriptionException e) {
 | 
				
			||||||
        } catch (final UnsupportedClassVersionError e) {
 | 
					                    sender.sendMessage("§4异常: §c" + e.getMessage());
 | 
				
			||||||
            sender.sendMessage("§4异常: §c" + e.getMessage());
 | 
					                    sender.sendMessage("§4插件: §c" + name + " 的 plugin.yml 文件存在错误!");
 | 
				
			||||||
            sender.sendMessage("§c服务器或JAVA的版本低于插件: " + name + " 所需要的版本!!");
 | 
					                    return false;
 | 
				
			||||||
            return false;
 | 
					                }
 | 
				
			||||||
        } catch (final InvalidPluginException e) {
 | 
					                target = Bukkit.getPluginManager().loadPlugin(pluginFile);
 | 
				
			||||||
            if (!clean) {
 | 
					            } catch (final UnsupportedClassVersionError e) {
 | 
				
			||||||
                return load(sender, pluginFile, true);
 | 
					                sender.sendMessage("§4异常: §c" + e.getMessage());
 | 
				
			||||||
 | 
					                sender.sendMessage("§c服务器或JAVA的版本低于插件: " + name + " 所需要的版本!!");
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            } catch (final InvalidPluginException e) {
 | 
				
			||||||
 | 
					                if (e.getMessage().equalsIgnoreCase("Plugin already initialized!")) {
 | 
				
			||||||
 | 
					                    if (!clean) {
 | 
				
			||||||
 | 
					                        YumPluginLoader.inject(pname);
 | 
				
			||||||
 | 
					                        return load(sender, pluginFile, true);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    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注意: §cMOD服重载插件3次以上需重启服务器");
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
 | 
					            } catch (final UnknownDependencyException e) {
 | 
				
			||||||
 | 
					                sender.sendMessage("§4异常: §c服务器未安装必须依赖: " + e.getMessage());
 | 
				
			||||||
 | 
					                sender.sendMessage("§4插件: §c" + name + " 载入失败 缺少部分依赖项目!");
 | 
				
			||||||
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            sender.sendMessage("§4异常: §c" + e.getMessage());
 | 
					            if (target == null) {
 | 
				
			||||||
            sender.sendMessage("§4文件: §c" + name + " 不是一个可载入的插件!");
 | 
					                sender.sendMessage("§4异常: §c服务器类加载器载入插件失败 请查看后台信息!");
 | 
				
			||||||
            sender.sendMessage("§4注意: §cMOD服重载插件3次以上需重启服务器");
 | 
					                return false;
 | 
				
			||||||
            return false;
 | 
					            }
 | 
				
			||||||
        } catch (final UnknownDependencyException e) {
 | 
					            target.onLoad();
 | 
				
			||||||
            sender.sendMessage("§4异常: §c服务器未安装必须依赖: " + e.getMessage());
 | 
					            Bukkit.getPluginManager().enablePlugin(target);
 | 
				
			||||||
            sender.sendMessage("§4插件: §c" + name + " 载入失败 缺少部分依赖项目!");
 | 
					            sender.sendMessage("§6载入: §a插件 §b" + target.getName() + " §a版本 §d" + getVersion(target) + " §a已成功载入到服务器!");
 | 
				
			||||||
 | 
					            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;
 | 
					            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" + getVersion(target) + " §a已成功载入到服务器!");
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user