Brord icon

bukkit cmd example

Brord | PRO | 07/28/14 10:35:14 PM UTC | 0 ⭐ | 567 👁️ | Never ⏰ | []
Java |

820 B

|

None

|

0 👍

/

0 👎

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("basic")) { // If the player typed /basic then do the following...
        //check the amount of values in the array
                if (args.length == 0){
            //no arguments
            return false;
        }
        
        //send the first value from the array
        sender.sendMessage("First argument: " + args[0]);
        return true;
    } else if (cmd.getName().equalsIgnoreCase("basic2")) {
        //command is now the same as the  one checked ^ (basic2)
        String command = cmd.getName();
 
        //for every argument, add it to the command
        for (String arg : args){
            command += " " + arg;
        }
 
        //send entire command as message
        sender.sendMessage("Entire command: " + command);
        return true;
    }
    return false;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎