How to get player chat command string?

Discussion in 'Plugin Development' started by avatarDr, Sep 26, 2013.

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

    avatarDr

    Subj.
    PlayerCommandPreprocessEvent.getMessage() gives string with removed spaces, i.e. /hello world will be shown as /hello world.
    I remember that in 1.5 it worked properly.

    And another little question, which event is responsible for CommandBlock triggering?
     
  2. Offline

    Janmm14

    avatarDr
    Can you explain this spaces issue detailed?
     
  3. Offline

    3ptO

    avatarDr Janmm14 I think he means getMessage() is returning the string "/hello world" as "/helloworld".
     
  4. Offline

    Janmm14

    avatarDr 3ptO Ok. I can't say anything to that.
    But for command block triggering use BlockRedstoneEvent
     
  5. Offline

    avatarDr

    Lolno. I mean that if I write "/start end" (with several spaces) they all are replaced with one.
    And I need the exact string being typed.

    Eh, I see. It trims spaces here too. So, had I explained the problem clearly now?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. Offline

    Xx_LeetGamer_xX

    As far as I know there's no way around this.
     
  7. Offline

    Pezah

    Could you paste your code in? I don't quite follow...
     
  8. Offline

    Chinwe

    You could try using AsyncPlayerChatEvent and checking if it begins with /?
    As for command blocks, ServerCommandEvent might be called (not sure), but if it is, you can check if the sender is a BlockCommandSender :)
     
  9. Offline

    avatarDr

    BlockCommandSender is not a ServerCommandSender.

    Code:java
    1. @EventHandler(priority=EventPriority.HIGHEST)
    2. private void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent ev){
    3. if(ev.isCancelled())return;
    4. ev.setCancelled(true);
    5. Util.debug(ev.getMessage()+"_"+ev.getMessage().split(" ").length);


    Somewhy editing doesn't work here.
    Code:
    String "/qwe              aze"
    results in
    "/qwe aze"
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  10. Offline

    LazyLemons

    The client automatically does that when you type a command, I believe.
     
  11. Offline

    1Achmed1

    Typically the client only automatically deletes spaces at the beginning and end of the chat string, assuming there's nothing on either end of them. In this case, the client should send those spaces, if I remember correctly.
     
  12. Offline

    avatarDr

    Yes. I had a working system using exactly the same things half a year ago. But now it doesn't work.
     
  13. Offline

    Janmm14

    avatarDr
    Try to add ProtocolLib to your server plugins folder and type
    /packets add client 3 true
    The join, type a command with many spaces between and watch the console: Are the spaces shown?
     
Thread Status:
Not open for further replies.

Share This Page