Command Argument

Discussion in 'Plugin Development' started by zakarls, May 28, 2014.

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

    zakarls

    How would I get the first argument of a command. I know this much so far
    Code:
    @EventHandler
    public void onCommandSend(PlayerCommandPreprocessEvent event){
    String message = event.getMessage();
    }
    Lets say the command was /help 3
    How would I get the help part from the message and that only. I want it to cut off the 3 part if thats possible. Thanks :)

    Can anyone please help. This is really urgent.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  2. Offline

    ChazSchmidt

    Code:java
    1. String[] command = event.getMessage().split(" ");

    zakarls You could try something like this

    If I'm correct then you should be able to do this: For example:
    /help 3
    command[1] should equal 3
     
    mythbusterma likes this.
  3. Offline

    AronTheGamer

    Use getCommand("help").setExecutor( CommandExecuter exec ) in your Plugin class
     
  4. Offline

    zakarls

    ChazSchmidt
    So if I wanted to get help it would be command[0]?
     
  5. Offline

    ChazSchmidt

    zakarls I'm not sure if that would return help or /help. Play with it and find out
     
  6. Offline

    zakarls

    ChazSchmidt
    It doesnt matter if it returns with the / because im just checking if it contains "help" so it would be fine. But... it would work, right?
     
  7. Offline

    ChazSchmidt

    zakarls yes it will work like you stated
     
  8. Offline

    zakarls

  9. Offline

    ChazSchmidt

    zakarls No problem, I'm glad I could help
     
Thread Status:
Not open for further replies.

Share This Page