插件已初始化

huangapple go评论83阅读模式
英文:

Plugin already initialized

问题

我正在为BungeeCord服务器之间的传送创建插件。突然间,我不知道为什么,但是开始出现错误。你能告诉我问题出在哪里吗?谢谢你的回复。

完整的堆栈跟踪:

org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:139) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:334) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:253) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.craftbukkit.v1_15_R1.CraftServer.loadPlugins(CraftServer.java:351) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:203) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at java.lang.Thread.run(Thread.java:830) [?:?]
Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:178) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at pl.piotrek.main.Main.<init>(Main.java:9) ~[?:?]
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
        at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
        at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166) ~[?:?]
        at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404) ~[?:?]
        at java.lang.Class.newInstance(Class.java:591) ~[?:?]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:72) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        ... 6 more
Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:181) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at pl.piotrek.main.Main.<init>(Main.java:9) ~[?:?]
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
        at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
        at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
        at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166) ~[?:?]
        at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404) ~[?:?]
        at java.lang.Class.newInstance(Class.java:591) ~[?:?]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:72) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
        ... 6 more

主类:

    package pl.piotrek.main;
    
    import org.bukkit.plugin.java.JavaPlugin;
    import pl.piotrek.commands.ServersCommand;
    import pl.piotrek.events.ServersGuiListener;
    import pl.piotrek.gui.Gui;
    import pl.piotrek.message.channel.PluginMessagingListener;
    import pl.piotrek.message.command.ConnectCommand;
    
    public class Main extends JavaPlugin {
        private static Main instance;
        public static Main getInstance() { return instance; }
        public void setInstance(Main instance) { Main.instance = instance; }
        public Gui gui;
        @Override
        public void onEnable() {
            System.out.println("Enabled TeleportationUtils v1.0.0");
            setInstance(this);
            registerCommands();
            registerListener();
            this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new PluginMessagingListener());
            gui = new Gui();
        }
        public void registerCommands() {
            getCommand("connect").setExecutor(new ConnectCommand());
            getCommand("servers").setExecutor(new ServersCommand());
        }
        public void registerListener() {
            this.getServer().getPluginManager().registerEvents(new ServersGuiListener(), this);
        }
    }

Plugin.yml:

    name: TeleportationUtils
    version: 1.0.0
    main: pl.piotrek.main.Main
    api-version: 1.15
    commands:
      connect:
        aliases: [cnt]
        description: Connect to another sevrer command
      servers:
        aliases: [svr]
        description: Server menu command for teleport between servers
    permissions:
      commands:
       connect:
英文:

I am doing plugin for teleport between servers in bungeecord. Suddenly, i don't know how, but error starts occur. Can you tell me, where is the problem? Thank you for your response.

Full Stacktrace:

org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:139) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:334) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:253) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.craftbukkit.v1_15_R1.CraftServer.loadPlugins(CraftServer.java:351) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:203) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:784) [spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at java.lang.Thread.run(Thread.java:830) [?:?]
Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:178) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at pl.piotrek.main.Main.<init>(Main.java:9) ~[?:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166) ~[?:?]
at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404) ~[?:?]
at java.lang.Class.newInstance(Class.java:591) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:72) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
... 6 more
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:181) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at pl.piotrek.main.Main.<init>(Main.java:9) ~[?:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166) ~[?:?]
at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404) ~[?:?]
at java.lang.Class.newInstance(Class.java:591) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:72) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.15.2.jar:git-Spigot-800b93f-8160e29]
... 6 more

Main class:

package pl.piotrek.main;
import org.bukkit.plugin.java.JavaPlugin;
import pl.piotrek.commands.ServersCommand;
import pl.piotrek.events.ServersGuiListener;
import pl.piotrek.gui.Gui;
import pl.piotrek.message.channel.PluginMessagingListener;
import pl.piotrek.message.command.ConnectCommand;
public class Main extends JavaPlugin {
private static Main instance;
public static Main getInstance() { return instance; }
public void setInstance(Main instance) { Main.instance = instance; }
public Gui gui;
@Override
public void onEnable() {
System.out.println(&quot;Enabled TeleportationUtils v1.0.0&quot;);
setInstance(this);
registerCommands();
registerListener();
this.getServer().getMessenger().registerOutgoingPluginChannel(this, &quot;BungeeCord&quot;);
this.getServer().getMessenger().registerIncomingPluginChannel(this, &quot;BungeeCord&quot;, new PluginMessagingListener());
gui = new Gui();
}
public void registerCommands() {
getCommand(&quot;connect&quot;).setExecutor(new ConnectCommand());
getCommand(&quot;servers&quot;).setExecutor(new ServersCommand());
}
public void registerListener() {
this.getServer().getPluginManager().registerEvents(new ServersGuiListener(), this);
}
}

Plugin.yml:

name: TeleportationUtils
version: 1.0.0
main: pl.piotrek.main.Main
api-version: 1.15
commands:
connect:
aliases: [cnt]
description: Connect to another sevrer command
servers:
aliases: [svr]
description: Server menu command for teleport between servers
permissions:
commands:
connect:

答案1

得分: 2

你的堆栈跟踪显示你的插件最初在 pl.piotrek.main.Main.java 的第 9 行进行了初始化,然后它尝试在同一点再次初始化。很有可能在你的插件文件夹中有两次相同的插件,可能是以不同的名称存在。

浏览一下你服务器的插件文件夹,找出重复的部分。

英文:

Your stack trace shows that your plugin is initially initialized at pl.piotrek.main.Main.&lt;init&gt;(Main.java:9) and then it's trying to be initialized again at the same point. It is very likely that you have the same plugin twice in your plugins folder, probably under a different name.

Have a look through your server's plugin folder and find the duplicate.

答案2

得分: 0

你很可能在两个类中都有"extends JavaPlugin"。你只能在主类中使用这个。你应该在其他类中使用以下方式:

private final Main plugin;
public className(Main plugin) {
    this.plugin = plugin;
}

然后在其他类中使用 plugin.whatever 来访问通常只能在主类中访问的内容。

另外,在你的 plugin.yml 文件中,你有以下内容:

permissions:
  commands:
   connect:

这不符合 Bukkit 的权限标准,你可以在这里找到标准。

另外,当命名你的包时,最好将插件名称包含在内,例如 pl.piotrek.TeleportationUtils.main.Main,这样如果服务器中有多个插件,就不会引发问题。

英文:

you most likely have "extends JavaPlugin" in 2 classes. you can only have this in your Main class. What you should do instead is

    private final Main plugin;
public className(Main plugin) {
this.plugin = plugin;
}

in your other classes, and use plugin.whatever to access things you normally only could in your Main class.

Also in your plugin.yml, you have

permissions:
commands:
connect:

this does not follow Bukkit's permission standards which can be found here.

And when naming your packages, its best to put the plugin name in there. something like pl.piotrek.TeleportationUtils.main.Main so if you have more then one of your plugins in the server, it won't cause issues.

huangapple
  • 本文由 发表于 2020年5月29日 21:19:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/62086947.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定