Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

minecraft - java.lang.IllegalArgumentException: Plugin already initialized. What's going on?

When I'm testing my new plugin an exception keeps getting thrown: java.lang.IllegalArgumentException: Plugin already initialized! Please help! Here's the code:

package me.plugin.example;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;    


public class Main extends JavaPlugin implements Listener {

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(new Main(), this);
    }

    @EventHandler
    public void onPlayerJoinEvent(PlayerJoinEvent event) {
        Player p = event.getPlayer();
        event.setJoinMessage(ChatColor.AQUA + p.getPlayerListName() +  " has joined the game.");
        p.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Welcome to the server!");
        p.setGameMode(GameMode.ADVENTURE);

}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player player = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("example")) {
        player.sendMessage(ChatColor.BOLD + ""+ ChatColor.ITALIC + "Hello! Hope you like to be set on fire. lol :P");
        player.setFireTicks(20);
    }
    return true;

}

@Override
public void onDisable() {

}

} I know that you're only supposed to declare one JavaPlugin class per plugin, which I think I'm doing. But it keeps saying:

java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
        at me.plugin.example.Main.onEnable(Main.java:27) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_201]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_201]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_201]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
        ... 2 more

I really need to test this plugin to see if it works, and any help would be greatly appreciated! Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I would really recommend you to put your event handler in a separate class.

Try removing the below line

getServer().getPluginManager().registerEvents(new Main(), this);

and please don't ask your question several times.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...