Solved Command.

Discussion in 'Plugin Development' started by sensus12, Sep 28, 2012.

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

    sensus12

    Hey. How can i do command, like this:

    if player type: command name it do something.

    but i can't do it.

    I must do commandname and in plugin.yml commandname then it work, but if i try command name(space beetwen command name) and in plugin.yml command name it doesn't work.
     
  2. Offline

    brord

  3. Offline

    sensus12

    Ahh i know how to do command but:
    Code:
    if(commandLabel.equalsIgnoreCase("command name")
    {
    //code
    }
    
    and in plugin.yml:
    Code:
    commands:
        command name:
            description: description
    
    IT DOESN't WORKS.
    but:
    Code:
    if(commandLabel.equalsIgnoreCase("commandname"){
    //code
    }
    
    and in plugin.yml:
    Code:
    commands:
        commandname:
            description: description
    
    IT WORKS!!
     
  4. Offline

    HouseMD

    Yeah you can only specify one words for a command start.
    Then if you want for example "gg start", then you check args



    Code:
    {
                    if (args.length == 0) {
                        p.sendMessage("ERROR");
                    } else if (args.length == 1) {
                        dostuff(p, args[0]);
                    } else
                        p.sendMessage("ERROR");
                }
    args[0] is the argument after "gg args[0]",
    then args[1] would be after "gg args[0] args[1]"

    hope you get it.
    also i showed how you can pass that arg string to a method too :p
    and to check the amount of args after "gg".
     
  5. Offline

    brord

    Whats this with all these new guys with CommandLabel :/ why not jsut use cmd
     
  6. Offline

    HouseMD

    c&p
     
  7. Offline

    brord

    Yes, and that means?
     
  8. Offline

    sensus12

    i used cmd.getName().equalsIgnoreCase("reload it");

    and if i type /reload it it don't work.

    I will try now HouseMD

    It still doesn't work.

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]){
            Player player = (Player) sender;
            if(sender instanceof Player == true){
                if(commandLabel.equalsIgnoreCase("reload it") && player.hasPermission("reloadit.plg")){
                    if(args.length == 0) {
                        player.sendMessage(ChatColor.BLUE + "ERROR.");
                    }else if (args.length == 1){
                this.reloadConfig();
               
                return true;
                }
                   
                }
            }
                return false;
           
        }
    OKAY IT WORKS!! Thanks all.
     
  9. Offline

    brord

    /reload is a default bukkit command, and if you add /reload it, it wont trigger because of the standard /reload

    try reversing it /it reload
    or make it one: /reloadit
     
Thread Status:
Not open for further replies.

Share This Page