How to check if player is holding down left click?

Discussion in 'Spigot Plugin Development' started by IronMan_59, Jun 13, 2017.

  1. I want to check if the player is holding down left click for my block break packets but I'm not sure how to check.
     
  2. I Found Something Here, this may help you.
     
    • Optimistic Optimistic x 1
  3. That won't work as a plugin ( server side )
     
  4. that involves running something client side. so no, it wont help
     
  5. you can't actually check if a client is holding the left button.
    But you could check a similar thing by using the PlayerInteractEvent ( Action.LEFT_CLICK_?? )
    And you just check xyz ms later if the client has not catched the event again.
     
  6. I don't think you can, since when you press and hold left click it only fires once, then that's it. You can pretty reliably check for holding down of right click though, that gets fired repeatedly in a certain delay after the initial click.
     
  7. I saw a thread and it said the au boolean in EntityPlayer returns if they are breaking a block. I need to know how to cast Player to EntityPlayer.
     
  8. Code (Text):
    EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    This casts the Bukkit Player to the CraftBukkit implementation of Player and gets the NMS EntityPlayer.
     
  9. Maybe you could use a PlayerInteractEvent, as if I remember correctly, it is called when the user presses or holds left or right click. Now, I'll show some pesudo code
    Code (Text):
    private void Interact(PlayerInteractEvent e) {
    if((e.getAction() == Action.LEFT_CLICK_BLOCK) || (e.getAction() == Action.LEFT_CLICK_AIR))) {
    //Do something
    Now, this will be called every tick the player presses or holds the button. So, I hope you have a good idea or method on for lag control.
     
  10. Hm, well after testing and doing a bit of decompiling, in 1.8 the boolean au returns if the player is in a vehicle but in 1.9+ it is for block breaking. Does anybody know a method that does what EntityPlayer#au does in 1.9+ in 1.8?