简体   繁体   English

如何首先启用bukkit插件?

[英]How to enable a bukkit plugin first?

I have an interesting problem where I want to enable a specific Bukkit plugin first before any other plugins are enabled. 我有一个有趣的问题,我想在启用任何其他插件之前先启用特定的Bukkit插件。 This has proven a difficult task. 事实证明,这是一项艰巨的任务。 I can't use the plugin.yml dependancy options because those assume I know what plugins are installed on any given server. 我不能使用plugin.yml依赖选项,因为那些假设我知道在任何给定服务器上安装了哪些插件。 I don't care if it doesn't load first, but I do need it to enable first. 我不在乎是否不首先加载,但是我确实需要先启用它。

I have tried several methods to accomplish this but with no luck: 我尝试了几种方法来完成此任务,但是没有运气:

Attempt 1: 尝试1:

static{

    try {
        Bukkit.getPluginManager().loadPlugin(plug);
        Bukkit.getPluginManager().enablePlugin(plugin);
    } catch (UnknownDependencyException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidPluginException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidDescriptionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

Allow me to explain. 请允许我解释一下。 The static seems to run before most anything, including plugin loadups. 静态函数似乎先于大多数东西运行,包括插件加载。 This means I also have to define when it loads as well. 这意味着我还必须定义何时加载。 This normally wouldn't be a problem, except non static API like getDataFolder() for the file Path doesn't work. 这通常不会有问题,除非文件Path的非静态API(如getDataFolder()不起作用。

public static File plug = new File("/plugins/Debugger");

So unless I'm doing my Paths wrong, I have no clue why this throws an Exception. 因此,除非我的路径错误,否则我不知道为什么会引发异常。

NOTE: Yes, I have tried multiple different paths such as "plugins/Debugger" or "Debugger.jar" and ECT. 注意:是的,我尝试了多个不同的路径,例如"plugins/Debugger"或“ Debugger.jar”和ECT。

Method 2: 方法2:

public void onLoad(){
        Bukkit.getPluginManager().enablePlugin(plugin);
        console.info("[Debugger] loaded first!");
    }

This seemed too good to be true and this method actually seemed to get me closer to solving my problem. 这似乎太不可思议了,实际上,这种方法似乎使我更接近解决自己的问题。 This Method is called whenever the plugin loads, so by enabling the plugin within the onLoad Method, it actually caused the plugin to enable first; 每当插件加载时都会调用此方法,因此通过在onLoad方法中启用插件,实际上使插件首先启用。 But there were issues when loading: 但是加载时存在问题:

[00:15:08] [Server thread/ERROR]: null initializing Debugger v1.0.0 (Is it up to date?)
java.lang.NullPointerException
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:396) ~[craftbukkit.jar:git-Bukkit-0ebb9c7]
    at me.doublehelix457.Debugger.Debugger.onLoad(Debugger.java:20) ~[?:?]
    at org.bukkit.craftbukkit.v1_10_R1.CraftServer.loadPlugins(CraftServer.java:299) [craftbukkit.jar:git-Bukkit-0ebb9c7]
    at org.bukkit.craftbukkit.v1_10_R1.CraftServer.reload(CraftServer.java:723) [craftbukkit.jar:git-Bukkit-0ebb9c7]
    at org.bukkit.Bukkit.reload(Bukkit.java:548) [craftbukkit.jar:git-Bukkit-0ebb9c7]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [craftbukkit.jar:git-Bukkit-0ebb9c7]

Somehow despite the weird null initializing Debugger (Debugger is the test plugin name) the plugin still managed to enable first? 以某种方式,尽管null initializing Debugger奇怪的null initializing Debugger (Debugger是测试插件名称),但插件仍然设法首先启用?

So the line it is referring to is Bukkit.getPluginManager().enablePlugin(plugin); 因此它所指的行是Bukkit.getPluginManager().enablePlugin(plugin);

Doing some research online I noticed certain API like getServer() was not working within that Method and I believe that maybe this means that Bukkit or PluginManager may not exist yet. 在线进行一些研究时,我注意到诸如getServer()类的某些API在该方法中无法正常工作,我相信这可能意味着BukkitPluginManager可能还不存在。

If that's the case, then is there a workaround to this? 如果是这样,那么是否有解决方法?

That said, I'm willing to take improvements on my current attempts or even try new ones, whatever gets the job done. 就是说,无论完成什么工作,我都愿意对我目前的尝试进行改进,甚至尝试新的尝试。 Please do not ask "Why do you need to enable the plugin first?" 请不要问“为什么首先需要启用插件?” I should mention that this version of bukkit is on 1.10. 我应该提到这个版本的bukkit在1.10上。

Any HELPFUL advice would be much appreciated. 任何有益的建议将不胜感激。

So now I feel really stupid. 所以现在我真的很傻。 Turns out all I had to do was make my plugin variable non-static and define it. 原来我要做的就是让我的plugin变量为非静态变量并对其进行定义。 All that trouble just to change public static Debugger plugin; 所有这些麻烦只是为了更改public static Debugger plugin; to public Debugger plugin = this; public Debugger plugin = this;

This change works with Method 2. 此更改适用于方法2。

Well. 好。 I hope that this benefits someone as to how they can enable a plugin first. 我希望这对某人有益,他们可以先启用插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM