you could do this easily by using a for loop to get the all of the strings after the /command
, which all are processed as arguments. Here's an example:
String myString = ""; //we're going to store the arguments here
for(int i = 0; i < args.length; i++){ //loop threw all the arguments
String arg = args[i] + " "; //get the argument, and add a space so that the words get spaced out
myString = myString + arg; //add the argument to myString
}
Now you have your string, and you could do anything with it, like send the message to the command sender:
sender.sendMessage(myString);
A short explanation of the code above is, first, we're looping threw all of the arguments (everything that comes after the /command
, then, we're adding a space to the end of the argument, and last, we put the argument into the string, myString
... Here's an example of implementation:
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if(cmd.getName().equalsIgnoreCase("command")){
String myString = "";
for(int i = 0; i < args.length(); i++){
String arg = args[i] + " ";
myString = myString + arg;
}
sender.sendMessage(myString); //send the message to the command sender.
}
}
you could also check if the command has arguments using:
if(args.length != 0){
An example when using a command is, let's say a player types /command bar foo
. The player would then get sent the message bar foo
.