Spaces in Commands

Discussion in 'Spigot Help' started by Kadioshi, May 11, 2015.

  1. How would I add spaces in a command. Such as /minekart help

    If this is possible what would I put in the plugin.yml
     
  2. you would need to check for the arguments. and then execute different blocks based on what the arguments are.

    Code (Text):
        public boolean onCommand(CommandSender sender, Command command,
                                 String label, String[] args) {
            if(command.getName().equalsIgnoreCase("minekart")) {
               
                if(args.length < 1){
                   
                    //do stuff for just /minekart
                    return true;
                }else if(args.length > 0 && args[0].equalsIgnoreCase("help")){
                   
                    //do stuff for /minekart help
                    return true;
                   
                }
               
                return false;
               
            }

           return false;    
               
        }
     
    • Like Like x 1
  3. This needs to be moved to plugin development if you want an answer about something related to plugin development. :)
     
  4. Would you be able to do this multiple times? Because I see the elseif
    Like do
    /minekart help
    /minekart items
    /minekart kits
    etc.
     
  5. Yes that would work for each argument.
     
  6. Use thisone;

    Code (Text):
    public boolean onCommand(CommandSender sender, Command command, String parancs, String args[])    {

            if(sender instanceof Player)    {
                Player p = (Player) sender;
                if(args.length == 0)    {
                    p.sendMessage("Commands: /minekart item | /minekart help | /minekart kits");
                    return true;
                }    else    {
                    switch(args[0])    {
                        case "item":
                            //Do something
                            return true;
                        case "help":
                            //Do something
                            return true;
                        case "kits":
                            //Do something
                            return true;
                        default:
                            p.sendMessage("Commands: /minekart item | /minekart help | /minekart kits");

                            return true;
                    }
                }
            }
           
            return false;
           
        }
     
    • Agree Agree x 1
  7. While that will still work, personal preference and thought flow go against switch/case statements. Not saying you're wrong or anything. Switch case statements make me yell a lot though. It makes the code harder to follow sometimes.
     
    • Agree Agree x 1
  8. so im following your steps But how would i add permissions
     
  9. Strahan

    Benefactor

    I agree, but I'd switch on args[0].toLowerCase().

    Funny, I find switch to be the exact opposite - makes it very clear how stuff flows.