Left Click event

Discussion in 'Plugin Development' started by w4rgo, Mar 12, 2011.

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

    w4rgo

    Is there the event on a Item when you press Left Click ??
    I know there is for RightClick, (PlayerItemEvent) but not on left click :S

    Thanks
     
  2. Offline

    Edward Hand

    PLAYER_ANIMATION is triggered when the player swings their arm (so for both left and right click). I'm not sure if that's any help.

    If you want to detect left clicking on a block then BLOCK_DAMAGED can be used.
     
  3. Offline

    w4rgo

    Thank you very much for your info.

    Exactly what I want is to know the Event triggered when I left click with an item(Ex. Sword) on a Player / Entity

    Thanks
     
  4. Offline

    Edward Hand

    There's no event for that specifically. If you have PvP on it will trigger the ENTITY_DAMAGED event
     
  5. Offline

    w4rgo

    Yes I know Entity_damaged event , but how I know who dealed that damage ?
    There is no method that gives me that information I think.
    :s

    thanks
     
  6. Offline

    MadMonkeyCo

    Check if it's an EntityDamageByEntityEvent, if not return, if so then continue. The EntityDamageByEntityEvent holds a getDamager() function (or method).
    Example:
    PHP:
    if(!(event instanceof EntityDamageByEntityEvent))
    {
        return;
    }
    EntityDamgeByEntityEvent edbeEvent = (EntityDamageByEntityEvent)event;
    Entity damager edbeEvent.getDamager();
     
  7. Offline

    w4rgo

    Thanks! I will check this
     
  8. Offline

    narrowtux

    Excerpt from one of my plugins:
    Code:
         
    public void onBlockDamage(BlockDamageEvent event){
    		if(event.getDamageLevel().getLevel()!=0){
    			return; //This is needed because otherwise the leftclick will fire every single moment when you damage the block.
    		}
    		BlockPosition pos = new BlockPosition(event.getBlock());
    		//Do your left-click stuff here.
    	}
    
     
    Tim Visee likes this.
  9. Offline

    Tim Visee

    Thanks again!
     
    Smallie07 likes this.
  10. Offline

    narrowtux

    This doesn't work any more since a recent update! Use PlayerInteractEvent instead.
     
  11. Offline

    Tim Visee

    That function doesn't work for all the blocks...

    I found the simple but full working solution (that's working right now too)

    Code:
    public void onBlockDamage(BlockDamageEvent event) {
         BlockPosition pos = new BlockPosition(event.getBlock());
         //Do your left-click stuff here.
    }
    
    Hope this helps... :)

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

Share This Page