Multiple Commands to One Plugin

Discussion in 'Plugin Development' started by kookie2100, Nov 30, 2013.

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

    kookie2100

    Hello , i am new to this whole plugin creating stuffs. and i have this problem that i have no idea how to fix and that is when i make a couple commands; for example ,

    if(args[0].equalsIgnoreCase("c")){
    player.setGameMode(GameMode.CREATIVE);
    player.sendMessage(ChatColor.GOLD + "[Gamemode]" + ChatColor.AQUA + " Creative");
    return true;
    }

    if(args[0].equalsIgnoreCase("on")){
    player.setAllowFlight(true);
    player.setFlying(true);
    player.setFlySpeed(.2f);
    player.sendMessage(ChatColor.GOLD + "[Fly]" + ChatColor.DARK_GREEN + " Enabled.");
    return true;
    }
    So, i have those 2 commands in the same plugin but when i go into the plugin.yml and add the commands |
    fly: | "on"
    gm: | "c"

    The commands seem to trigger even if i use the not intended command, for example if i were to type in /gm on , flying would activate and vice versa for the other command.

    Can someone helps me?
     
  2. Offline

    Darq

    Correct way to check what command is being used:
    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args)  {
        if (command.getName().equals("on")) {
            // sender typed "/on ..."
        } else if (command.getName().equals("c")) {
            // sender typed "/c ..."
        }
    }
    
     
  3. Offline

    kookie2100

    Thanks for the reply,

    Ill be testing it and replying if it works.
     
Thread Status:
Not open for further replies.

Share This Page