Checking if a player has started typing a message or command

Discussion in 'Plugin Development' started by AoH_Ruthless, Jul 23, 2014.

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

    AoH_Ruthless

    I am trying to check if a player begins typing a command or message. In a hacky way, I could check if the player has pressed the key 't' or '/' (chat or command) but that raises a new problem: What if the player has edited one/both of those controls in their minecraft settings? Is it possible (will likely use Reflection if it is indeed possible) to check if they typed the chat or command button?
     
  2. Offline

    Traks

    Huh, I don't recall there being a packet that notifies the server the client has pressed the chat or command button. What would this 'hacky' check even be?
     
  3. Offline

    AoH_Ruthless

    Traks
    The best way I can explain this check is with code.

    Code:java
    1. private void onKeyPress(KeyEvent e) { // Listen to the KeyEvent.
    2. if (e == KeyEvent.KEY_PRESSED) { // Check if a key was pressed
    3. switch (e.getKeyCode()) { // the Key code represents an integer id for the key pressed
    4. case e.VK_SLASH:
    5. case e.VK_T:
    6. // if the key was t, or /, execute some code. Mark the player with a boolean flag, such as 'isTyping'.
    7. break;
    8. case e.VK_ENTER: // if the command or message was sent
    9. case e.VK_ESCAPE: // or if command or message was aborted
    10. // if isTyping is true, set isTyping to false.
    11. break;
    12. default:
    13. if (!isTyping) {/*Execute code; this is in the 'default', but really i would be checking for a specific key*/; break;}
    14. }
    15. }
    16.  
    17. // set isTyping to false onQuit
    18. }

    I hope you can see why it will not work. I am checking for specific keys but I have no idea what key the player may use to chat. Generally players do not edit these keys but I never can be sure.
     
  4. Offline

    Traks

    KeyEvent isn't a Bukkit event... It's a class in the java.awt.event package..
     
  5. Offline

    AoH_Ruthless

    Traks
    I know. But, can I not still use it in Bukkit Context?
     
  6. Offline

    The_Coder

    AoH_Ruthless
    This is on the server.... if it is a plugin
     
  7. Offline

    AoH_Ruthless

    The_Coder
    Can you elaborate? I think I know what you mean but I'm not sure:

    I was already under the impression that is handled client-side but if you are confirming this, thank you. However, I am wondering if and how I can retrieve this using Reflection.
     
  8. Offline

    ZanderMan9

    You have to understand that the server isn't notified every time the client presses a key... KeyEvent is something a program running client-side would hear, but unless the client tells the server everytime a key is pressed, the server has no way of knowing, so no this isn't possible :( Sorry!
     
  9. Offline

    The_Coder

    Plugins run server side.
     
  10. Offline

    AoH_Ruthless

    ZanderMan9
    Alright thank you for clarifying this :)

    The_Coder
    I am not trying to track a player moving.
     
  11. Offline

    Traks

    KeyEvent is generally used by methods in KeyListener, which in turn is used by Component s. I don't think net.minecraft.server or CraftBukkit/Bukkit classes handle them in any way...
     
  12. Offline

    Dragonphase

    AoH_Ruthless


    He means that because this is a plugin for a server, and will not affect or have any interaction with the client, you can't detect key presses this way. The only way for this to be possible is if the client was to issue a keypress event on each keystroke, which the server then picks up, which is not implemented in Bukkit.
     
  13. Offline

    AoH_Ruthless

    Dragonphase
    Yeah, I understand the post now but didn't before it was edited. Thank you still for pointing this out and thank you for the clarifying edit The_Coder
     
  14. Offline

    The_Coder

    There is a chat event but that is just about it for players typing
     
  15. Offline

    AoH_Ruthless

    The_Coder
    Yeah, but I believe both PlayerChatEvent and its asynchronous counterpart are only executed when the player sends the chat message.
     
  16. Offline

    The_Coder

  17. Offline

    Necrodoom

    You are basically trying to get the client presses by checking if the keys were presses server side.. which wont work.
    Basically theres no way to get the key presses themselves from the client by the server currently. Theres no packet for it.
     
  18. Offline

    mkezar

    The only way of doing this is on the client side. so mods is my guess
     
Thread Status:
Not open for further replies.

Share This Page