What event is used when you left click a player?

Discussion in 'Plugin Development' started by potatofarms, Aug 11, 2012.

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

    potatofarms

    I'm trying to make it in my server when you left click a player with paper, you heal them, but what is leaving me stuck is how to do this. I don't exactly know what event is thrown when you left click a player. Does anyone know how to do this?

    Thanks.
     
  2. Offline

    ZeusAllMighty11

    The event used it PlayerInteractEvent I believe

    Something like:"

    Code:
    public void onPaperHeal(PlayerInteractEvent event){
    Player clicker = event.getPlayer();
     
    if (clicker instanceof player){
        if (clicker.getItemInHand()==MATERIAL.PAPER){
            if(event.getAction()==ACTION.LEFT_CLICK_AIR){
                // check if clicked was a player Entity
                // if entity was player, get that player and set their health to X
                }
            }
        }
    }
     
     
    
     
  3. Offline

    Thumbz

    You're going to use PlayerInteractEntityEvent.

    Something along the lines of

    NOT REAL CODE
    PlayerInteractEntity(PlayerInteractEntityEvent event)
    {
    get item in hand
    get Entity

    if (entity is entity.PLAYER && item in hand == paper)
    { entity set health }
    }

    You may need to look up how to set up an event listener, how to get the id of an item in hand, and how to set health, amongst other things. If this is your first plugin, I recommend doing one based off a tutorial instead.
     
    WarmakerT likes this.
  4. Offline

    potatofarms

    I will try this out.

    This isn't my first plugin, I know how setting health and getting items and stuff works, I just wasn't sure which event is fired on a left click. :p

    Thanks for your guys help. :D

    Huh, now I seem to be stuck on how to get the player that was clicked.
    I tried doing the event.getClickedBlock() , but is that only for blocks, or could I check if it's instanceof Player, then the problem would be getting the Player object of the player that was clicked.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  5. You can't use the EntityInteractEvent nor the EntityInteractEntityEvent cause the first is for interacting with blocks while the second just detects right-clicks. You could try to use thr EntityDamageByEntity event instead but I'm not sue if this will be called if the clicked player is in creative mode, but when he is there'a no need to heal him, so that shouldn't matter anyway. ;)

    The_Coder but he wants to detect a left click...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page