[short] PlayerCommandPreprocessEvent and the arguments

Discussion in 'Plugin Development' started by TheA13X, Jul 6, 2013.

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


    Just a short question this time.
    what's the getMessage() command in the Preprocess Event?
    Does it return just the commands or does it return the arguments too?
    Or rather, how I can get the arguments of my commands?
  2. Offline


    getMessage() returns the entire line entered
    lets say a user uses the command /tp herp derp
    the getMessage method would return a String that equals "/tp herp derp"
    So if you wantyed to grab args from that i'd just split it by a space.
  3. Offline


    Just from Apidocs (here):
    It returns whole command with its arguments.

    So, if you want to get arguments from command catched by this event, you can use something like this:
    2. String[] splitted = event.getMessage().split(" "); // Splits whole command by space
    3. String[] args = Arrays.copyOfRange(splitted,1, splitted.length);
    4. // One of many ways to get only arguments by removing first element from array (it's the command)
Thread Status:
Not open for further replies.

Share This Page