java - Combine args into a sentence in Bukkit? -


i having trouble seems simple. how sentence command?

if user entered : /command want spaces minus command , pressed enter, need :

mystring = "i want spaces minus command";

how this? loop? , the fastest, efficient way this?

thanks. have far:

public boolean oncommand(commandsender sender, command cmd, string label, string[] args) {     if (cmd.getname().equalsignorecase("command"))     {            if(args.length > 0)         {             sender.sendmessage(chatcolor.red + "/command <message>");         }         else         {             if (!(sender instanceof player)) {                 sender.sendmessage("this command can run player.");             }              else              {                 player player = (player) sender;                 // check make sure nothing null or empty                 if(args[0].equals(" ") || args[0].equals("") || args[0] == null)                 {                     // command !!                 }                 else                 {                     player.sendmessage(chatcolor.red + "please enter <message>");                 }             }         }         return true;     }     return false; } 

you using loop of strings after /command, processed arguments. here's example:

string mystring = ""; //we're going store arguments here      for(int = 0; < args.length; i++){ //loop threw arguments     string arg = args[i] + " "; //get argument, , add space words spaced out     mystring = mystring + arg; //add argument mystring } 

now have string, , it, send message command sender:

sender.sendmessage(mystring); 

a short explanation of code above is, first, we're looping threw of arguments (everything comes after /command, then, we're adding space end of argument, , last, put argument string, mystring... here's example of implementation:

public boolean oncommand(commandsender sender, command cmd, string label, string[] args) {            if(cmd.getname().equalsignorecase("command")){         string mystring = "";          for(int = 0; < args.length(); i++){             string arg = args[i] + " ";             mystring = mystring + arg;         }          sender.sendmessage(mystring); //send message command sender.     } } 

you check if command has arguments using:

if(args.length != 0){ 

an example when using command is, let's player types /command bar foo. player sent message bar foo.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -