Can't get my simple command to work

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

  1. Offline

    Balaklava0

    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):
    Code:
    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();
    
        @Override
        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;
                   
                    gs.guimenu(p);
                   
                    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")) {
               
                sender.sendMessage("lalalal");
               
                return true;
               
            }   
           
            return true;
           
        }
    
    }
    
    Here is the code in the mainclass:
    Code:
    package me.baklava.expandedsurvival;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public final class Mainclass extends JavaPlugin{
       
        public Boolean Agony;
       
        @Override
        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
    commands:
    modes:
    usage: /modes
    description: opens up a menu where you can enable modes
    test:
    usage: /test
    description: issa test

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

    Code:
    [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 org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:167) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at me.baklava.expandedsurvival.Mainclass.<init>(Mainclass.java:5) ~[?:?]
            at me.baklava.expandedsurvival.Invenclickevent.<init>(Invenclickevent.java:13) ~[?:?]
            at me.baklava.expandedsurvival.Mainclass.onEnable(Mainclass.java:13) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:461) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:375) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload(CraftServer.java:810) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.Bukkit.reload(Bukkit.java:576) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) [server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand(CraftServer.java:695) [server.jar:git-Spigot-9de398a-9c887d4]
            at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:433) [server.jar:git-Spigot-9de398a-9c887d4]
            at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:397) [server.jar:git-Spigot-9de398a-9c887d4]
            at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:971) [server.jar:git-Spigot-9de398a-9c887d4]
            at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:816) [server.jar:git-Spigot-9de398a-9c887d4]
            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:170) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:52) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at me.baklava.expandedsurvival.Mainclass.<init>(Mainclass.java:5) ~[?:?]
            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:71) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:334) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:253) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.loadPlugins(CraftServer.java:350) ~[server.jar:git-Spigot-9de398a-9c887d4]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload(CraftServer.java:808) ~[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

    yPedx

    @Balaklava0
    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

    Balaklava0

    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

    yPedx

    Try removing the final tag in your main class declaration.
     

Share This Page