Minecraft bukkit api 插件在启用时崩溃

Minecraft bukkit api plugin crash while enabling

我是 Bukkit 的新手 API,不久前我学会了 java。我正在开发一个迷你游戏插件。

虽然 Eclipse 没有给我任何错误,但它似乎来自我的主 class。 Minecraft 确实启动了,但控制台记录插件无法启动,当我执行命令时它会重复回来。

这是我的主要内容class

package me.jobisingh;

import java.util.HashSet;

import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditOperation;
import com.sk89q.worldedit.bukkit.WorldEditAPI;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
import com.sk89q.worldedit.bukkit.selections.Selection;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.bukkit.commands.WorldGuardCommands;
import com.sk89q.worldguard.bukkit.listener.WorldGuardBlockListener;
import com.sk89q.worldguard.bukkit.listener.WorldGuardCommandBookListener;

import org.bukkit.plugin.Plugin;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;

// Color Code Here §

import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.java.JavaPlugin;

import me.jobisingh.handlers.Game;

public class MainClass extends JavaPlugin {

    @Override
    public void onEnable() {
        new ListenerClass(this);
        new Game();
    }

    @Override
    public void onDisable() {

    }

    private WorldGuardPlugin getWorldGuard() {
        Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");

        // WorldGuard may not be loaded
        if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
            return null; // Maybe you want throw an exception instead
        }

        return (WorldGuardPlugin) plugin;
    }

    public WorldEditPlugin getWorldEdit() {

        Plugin p = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
        if(p instanceof WorldEditPlugin) return (WorldEditPlugin) p;
        else return null;
    }



    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

        if (cmd.getName().equalsIgnoreCase("setteam1spawn") && sender instanceof Player) {

            Player player = (Player) sender;

            Block getBlock = player.getTargetBlock((HashSet<Byte>)null, 100);

            int x = getBlock.getX();
            int y = getBlock.getY();
            int z = getBlock.getZ();

            player.sendMessage("Team 1 Spawn Set At " + x + " " + y + " " + z);

            return true;

        }

        return false;   

    }

    public boolean onCommand1(CommandSender sender, Command cmd, String label, String[] args) {

        if (cmd.getName().equalsIgnoreCase("lobbyCreate") && sender instanceof Player) {

            Player player = (Player) sender;

            Selection selection = getWorldEdit().getSelection(player);
            Location LocA = selection.getMaximumPoint();
            Location LocB = selection.getMinimumPoint();
            World world = player.getWorld();
            CuboidSelection lobby = new CuboidSelection(world, LocA, LocB);

            return true;

        }

        return false;   

    }
    public Location lobbyLocation;
    public boolean onCommand2(CommandSender sender, Command cmd, String label, String[] args) {

        if (cmd.getName().equalsIgnoreCase("lobbySetSpawn") && sender instanceof Player) {

            Player player = (Player) sender;

            Location lobbyLocation = player.getLocation();

            return true;

        }

        return false;   

    }


}

这是我得到的错误

Error occurred while enabling MiniGame v1.0 (Is it up to date?)
java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at me.jobisingh.MainClass.<init>(MainClass.java:36) ~[?:?]
        at me.jobisingh.ListenerClass.<init>(ListenerClass.java:16) ~[?:?]
        at me.jobisingh.MainClass.onEnable(MainClass.java:40) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:356) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:316) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:524) [spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_51]
Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at me.jobisingh.MainClass.<init>(MainClass.java:36) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_51]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_51]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_51]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_51]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_51]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:291) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) ~[spigot-1.8.7-R0.1-SNAPSHOT-latest.jar:git-Spigot-b2c2c63-a3cb1bc]
        ... 2 more

启用 MiniGame v1.0 时出错(是最新的吗?) java.lang.IllegalArgumentException: 插件已经初始化!

无法加载您的插件,因为它已经加载,我认为这是创建重复的注册侦听器或插件的任何其他部分的问题。

所以我查看了你说的link,问题与link中的问题非常接近。为了修复它,我只是从我的侦听器 class 中删除了 MainClass 导入,然后我以不同的方式导入了 MainClass。