Can't get my simple command to work

Discussion in 'Plugin Development' started by Balaklava0, Nov 22, 2019.

  1. Offline


    Hello! Recently i've been getting back into plugin development. But when i tried to make a command that would open a GUI menu i couldn't get it to function at all. When i execute the command in-game all it does is output the command name in chat (even though i'm just returning true). To see if i could get any command to work i tried making a simple hello-world command. But the same thing happens. I've tried everything and still can't get it to work.

    Here is the code in my commands class (ignore the "modes" command):
    package me.baklava.expandedsurvival;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    public class Commands implements Listener, CommandExecutor {
        guis gs = new guis();
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (label.equalsIgnoreCase("modes")) {
                if (sender instanceof Player) {
                    if (args.length == 0) {
                    Player p = (Player) sender;
                    return true;
                    } else {sender.sendMessage(ChatColor.RED + "Too many arguments! Correct usage: /modes.");}
                    return true;
                } else {
                    sender.sendMessage("Only players can execute this command!");
                    return true;
            if (label.equalsIgnoreCase("test")) {
                return true;
            return true;
    Here is the code in the mainclass:
    package me.baklava.expandedsurvival;
    public final class Mainclass extends JavaPlugin{
        public Boolean Agony;
        public void onEnable() {
            this.getServer().getPluginManager().registerEvents(new Blockbreakevent(), this);
            this.getServer().getPluginManager().registerEvents(new Invenclickevent(), this);
            getCommand("modes").setExecutor(new Commands());
            getCommand("test").setExecutor(new Commands());
    Here is the plugin.yml:

    name: expandedsurvival
    version: 1.0
    main: me.baklava.expandedsurvival.Mainclass
    usage: /modes
    description: opens up a menu where you can enable modes
    usage: /test
    description: issa test

    and here is the error message im greeted with in the console:

    [20:37:26] [Server thread/ERROR]: Error occurred while enabling expandedsurvival v1.0 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
            at ~[server.jar:git-Spigot-9de398a-9c887d4]
            at<init>( ~[server.jar:git-Spigot-9de398a-9c887d4]
            at me.baklava.expandedsurvival.Mainclass.<init>( ~[?:?]
            at me.baklava.expandedsurvival.Invenclickevent.<init>( ~[?:?]
            at me.baklava.expandedsurvival.Mainclass.onEnable( ~[?:?]
            at ~[server.jar:git-Spigot-9de398a-9c887d4]
            at [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.Bukkit.reload( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.command.defaults.ReloadCommand.execute( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.command.SimpleCommandMap.dispatch( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand( [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand( [server.jar:git-Spigot-9de398a-9c887d4]
            at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue( [server.jar:git-Spigot-9de398a-9c887d4]
            at net.minecraft.server.v1_14_R1.DedicatedServer.b( [server.jar:git-Spigot-9de398a-9c887d4]
            at net.minecraft.server.v1_14_R1.MinecraftServer.a( [server.jar:git-Spigot-9de398a-9c887d4]
            at [server.jar:git-Spigot-9de398a-9c887d4]
            at Source) [?:1.8.0_121]
    Caused by: java.lang.IllegalStateException: Initial initialization
            at ~[server.jar:git-Spigot-9de398a-9c887d4]
            at<init>( ~[server.jar:git-Spigot-9de398a-9c887d4]
            at me.baklava.expandedsurvival.Mainclass.<init>( ~[?:?]
            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<init>( ~[server.jar:git-Spigot-9de398a-9c887d4]
            at ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin( ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins( ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.loadPlugins( ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload( ~[server.jar:git-Spigot-9de398a-9c887d4]
            ... 10 more
    [20:37:26] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    I am currently using the spigot 1.14.4 Api, both for the build path and the server. Any help would be greatly appreciated. Thanks!
  2. Offline


    Your plugin is already initialized. You're getting this error because you have more than one class extending JavaPlugin. Only your main class should extend JavaPlugin.

    Also, do not use label when checking the command, check the actual command with cmd.
  3. Offline


    Ok, will try. Thanks!

    EDIT: Couldn’t find any other class that extends javaPlugin. Perhaps the build is outdated/bugged?
    Last edited: Nov 23, 2019
  4. Offline


    Try removing the final tag in your main class declaration.

Share This Page