Get the actual clicks of a player

Discussion in 'Plugin Development' started by Rowinvd, Jan 4, 2016.

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

    Rowinvd

    How can I get the actual clicks of a player? PlayerInteractEvent doesn't count all the clicks. Probably something with packets or ProtocolLib?
     
  2. Offline

    Zombie_Striker

    @Rowinvd
    The reason it's not getting "all the clicks", is because the client (The player) is not sending all the packets. This has nothing to do with the server.

    One thing, PlayerInteractEvent only sends the packet when the itemstack triggers an event, not just when a player clicks. E.g. Right clicking a sword will trigger an event because that blocks the sword. Right clicking Bone might not do anything because it shouldn't do anything in the base game.
     
  3. Offline

    mine-care

    Exactly as @Zombie_Striker said. Unfortunately you cant do anything about client-side stuff unless you modify the client that goes beyond bukkit.
     
    Zombie_Striker likes this.
  4. @Zombie_Striker @mine-care
    It does send the packet though. It is for example used to detect if a player opens a container. And it is also utilized by plugins to e.g. open an inventory on click
     
  5. Offline

    Zombie_Striker

    @megamichiel
    Yes, but it's not the server that decides if the player opens a chest or not. The client checks if the player clicked on a chest, and if so, it sends the packet.

    Here's an example of what I mean:
    • The player has a bone in his hand
    • He right clicks air
    • Well, bone in "base game" does not do anything if you click air
    • No packet sent.
    But then:
    • He right clicks a chest
    • Well, if you right click a chest in "base game", it opens an inventory
    • A packet is sent,
     
    mine-care likes this.
  6. Offline

    teej107

    I'm pretty sure that's not true. How do you explain that on some servers, you right click an item in hand to open an inventory? But rather than argue about it, why not simply test it?
     
    Zombie_Striker likes this.
  7. Offline

    Konato_K

    Right clicks and left clicks do trigger events on air (otherwise there would be no use for the _AIR enums in Action)

    From what I remember, it does work different in 1.8 from 1.7, in 1.7 it didn't matter if the event was cancelled or not, in 1.8 this seems to be checked.
     
  8. Offline

    Rowinvd

    You can use protocollib or packets do do this right?
     
  9. Offline

    mythbusterma

    @Rowinvd

    Read the posts above yours, then ask a more intelligent question.
     
  10. Offline

    Zimboni

    For me it worked with a PlayerInteractEvent and an arrow which doesn't do anything normally so it shouldn't have anything to do with that.

    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e){
            Player p = e.getPlayer();
            if(p.getItemInHand().getType() == Material.ARROW){
               
                if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
                    // Do something on rightclick
                }
               
                if(e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK){
                    //do something on leftclick
                }
            }
        }
     
  11. Offline

    mythbusterma

    @Zimboni

    Think, for example, if a player left clicked on an entity. Then you would also need to listen for EntityInteractEvent.

    There are a lot of edge cases like this.
     
  12. Offline

    Zombie_Striker

    Please remember to null check when getting itemstack instances, since if the player is not holding any item, the item in their hand is null.
     
  13. Offline

    Zimboni

    @mythbusterma
    Just tested it and for me, it also triggered when left clicking on an entity

    @Zombie_Striker
    Thanks for the reminder, I'm gonna implement that
     
  14. Offline

    Rowinvd

    What about clicking on an entity?
     
  15. @Rowinvd

    I think it might be something along the lines of playerinteractentityevent?
     
Thread Status:
Not open for further replies.

Share This Page