Catching /me + any commands

Discussion in 'Plugin Development' started by AinSophAur, Sep 9, 2011.

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

    AinSophAur

    I want to know how I can pick up on the /me command in game. For example, when someone does "/me is cool" in game, I want to do log.info("someone used /me is cool in game") for generic purposes right now so I can manipulate it to my own needs later.

    Also I would like to know if its possible to pick on ANY command a player uses. For example, someone uses /asefsonef and even if it is not an existing command, I want to pick up on it and output it like log.info("someone used /asefsonef command and failed").
     
  2. Offline

    nisovin

    There is an event called PlayerCommandPreprocessEvent. All player commands pass through that event before being sent to plugins or processed by the server.
     
  3. Offline

    AinSophAur

    Here is what I have under the onPlayerCommandPreprocess:

    Code:
    Player player = event.getPlayer();
    String[] args = event.getMessage().split(" ");
    int y = args.length;
    StringBuilder s = new StringBuilder();
    for (int x = 1; x <= y; x++) {
      s.append(args[x] + " ");
    }
    if (args[0].equalsIgnoreCase("/me")) {
      plugin.log.info("Caught the /me " + s);
    }
    Yet it fails to trigger
     
  4. Offline

    nisovin

    Did you register the event?
     
  5. Offline

    AinSophAur

    Of course..

    pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this.playerListener, Event.Priority.Normal, this);
     
  6. remove the / maybe?
     
  7. Offline

    AinSophAur

    What /?
     
  8. Offline

    nisovin

    Maybe you should do some debugging? Throw some println's in there? See what's going wrong?
     
  9. Offline

    AinSophAur

    I tried but it seems like the event never gets triggered..
     
  10. Offline

    nisovin

    Did you spell the method wrong? It's hard to say without seeing all of your code.
     
  11. +1
     
  12. Offline

    AinSophAur

    Yes I spelled it right and I have other methods + events registered that work from the playerlistener class. I'm pretty sure the error isn't a mistake that I've made since the logic itself is right. I don't know if you guys tried out the method and it works for you...but if you did and it worked it would be cool if you posted whatever worked for you.
     
  13. Offline

    nisovin

    I've used that event many times, and it works fine. If it's not working for you, it means you did something wrong. If you'd like help, please post your code. Are you getting no console errors? I'll point out that your code has an array index out of bounds error.
     
  14. Offline

    AinSophAur

    Nvm I figured it out..
     
Thread Status:
Not open for further replies.

Share This Page