当我测试我的插件时,会抛出以下异常:java.lang.IllegalArgumentException: Plugin already initialized!
该插件可以运行,但事件" AdventureMode"不,这是代码:
package net.battleheroes.spigot.spacepvp;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import net.battleheroes.spigot.spacepvp.cmd.Feed;
import net.battleheroes.spigot.spacepvp.cmd.Fly;
import net.battleheroes.spigot.spacepvp.cmd.Heal;
import net.battleheroes.spigot.spacepvp.cmd.Kits;
import net.battleheroes.spigot.spacepvp.cmd.Spacepvp;
import net.battleheroes.spigot.spacepvp.cmd.gamemode;
import net.battleheroes.spigot.spacepvp.util.AdventureMode;
import net.battleheroes.spigot.spacepvp.util.ChatFormatting;
import net.battleheroes.spigot.spacepvp.util.Messages;
public class MainClass extends JavaPlugin implements ChatFormatting, Messages{
public void onEnable() {
Bukkit.getServer().getLogger().info(tag + green + enabled + orange + brand);
registerCommands();
registerEvents();
}
public void onDisable() {
Bukkit.getServer().getLogger().info(tag + red + disabled + orange + brand);
}
public void registerCommands() {
getCommand("spacepvp").setExecutor(new Spacepvp());
getCommand("kit").setExecutor(new Kits());
getCommand("heal").setExecutor(new Heal());
getCommand("feed").setExecutor(new Feed());
getCommand("fly").setExecutor(new Fly());
getCommand("gamemode").setExecutor(new gamemode());
}
public void registerEvents() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new AdventureMode(), this);
}
}
我没有任何其他具有相同类的插件,并且测试服务器目录为空。
错误
[07:41:11 ERROR]: Error occurred while enabling SpacePVP v0.4 (Is it up to date?)
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.battleheroes.spigot.spacepvp.cmd.Fly.<init>(Fly.java:10) ~[?:?]
at net.battleheroes.spigot.spacepvp.MainClass.registerCommands(MainClass.java:40) ~[?:?]
at net.battleheroes.spigot.spacepvp.MainClass.onEnable(MainClass.java:24) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:271) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugin(CraftServer.java:376) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugins(CraftServer.java:326) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.MinecraftServer.t(MinecraftServer.java:421) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.MinecraftServer.l(MinecraftServer.java:382) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.MinecraftServer.a(MinecraftServer.java:337) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.battleheroes.spigot.spacepvp.MainClass.<init>(MainClass.java:18) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_121]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_121]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_121]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_121]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_121]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:301) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:204) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
... 2 more
答案 0 :(得分:0)
在构造Fly
实例期间会出现此问题,如以下堆栈跟踪摘录中所示。
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
---> at net.battleheroes.spigot.spacepvp.cmd.Fly.<init>(Fly.java:10) ~[?:?]
at net.battleheroes.spigot.spacepvp.MainClass.registerCommands(MainClass.java:40) ~[?:?]
at net.battleheroes.spigot.spacepvp.MainClass.onEnable(MainClass.java:24) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:271) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
唉,这就是我无需额外的源代码即可告诉你的全部内容。检查Fly
的构造函数和/或其超类的构造函数,确保没有尝试创建JavaPlugin
派生类的另一个实例。从Fly
或MainClass
开始JavaPlugin
扩展,我会猜测。