Error Commands not working

Discussion in 'Plugin Development' started by bernivic135, Feb 17, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    bernivic135

    Hi,
    When I try to code a command for my plugin and I test it, it repeats itself. I doesn't give any line of error in the console, it just repeats itself.

    The code:
    Code:
    public class LobbyCommand {
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            if (cmd.getName().equalsIgnoreCase("lobby")) {
    
                if(sender instanceof Player) {
    
                    Player p = (Player) sender;
                    p.teleport(Bukkit.getWorld("lobby").getSpawnLocation());
                    return true;
                }
    
            } else {
    
                sender.sendMessage("You have to be a player to do that!");
    
            }
    
            return false;
    
        }
    
    }
    And the plugin.yml:
    Code:
    main: server.infinitykingdom.core.Core
    version: DevBuild_2016--02-17-01
    name: InfinityKingdom
    author: bernivic135
    
    commands:
       lobby:
          description: Teleport to lobby!
          usage: /<command>
     
  2. Offline

    Xerox262

    @bernivic135 The command class needs to implement CommandExecutor and you need to register it in the onEnable, also you need to fix your if statement, right now you have it set to only say "You have to be a player to do that!" If the command is not "lobby", not if the sender is not a player.


    P.S. You don't need to check the command with an if, if you're using a command executor, it will only trigger if the command is the command you register to it.
     
  3. Offline

    Lightspeed

    Unfortunly bukkit can't magically find your commands and run them for you... you have to tell it how to run.
     
  4. Offline

    bernivic135

    What do you mean by registering it in onEnable()?
     
  5. Offline

    Xerox262

    @bernivic135 In your onEnable.
    getCommand("lobby").setExecutor(new LobbyCommand());
     
  6. Offline

    bernivic135

    Thanks, command working now! My god, I was trying to use commands since the beginning and now I can!
     
Thread Status:
Not open for further replies.

Share This Page