Get a Entity's Name

Discussion in 'Plugin Development' started by HenoLima, Mar 23, 2014.

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

    HenoLima

    Hey , so im trying to develop a pet plugin but i got some problems , first i wanna do that when a player is sneaking and right clicks his pet,in this case its a wolf and i want to remove that entity and give him a item. So this is what i got so far. Help please? :D
    Code:java
    1. @EventHandler(ignoreCancelled = true)
    2. public void onDamage(EntityDamageByEntityEvent e){
    3. if(!(e.getDamager() instanceof Player)){
    4. Player p = (Player) e.getDamager();
    5. if(p.isSneaking()){
    6. if(!(e.getEntity() instanceof Wolf)){
    7.  
    8. }
    9.  
    10. }
    11. }
    12. }
    13.  
    14.  
    15.  
    So basicly i don't know how to get the wolf's name( IT NEEDS TO HAVE THE PLAYERS NAME to do this) and i don't know how to check if he is RIGHT CLICKING the wolf :( Help please:( ?
     
  2. Offline

    2MBKindiegames

    Here you go:
    Code:java
    1. Wolf wolf = (Wolf) e.getEntity();
    2. Player owner = (Player) wolf.getOwner();
    3. if (p.getName().equalsIgnoreCase(owner.getName())) {
    4. wolf.remove();
    5. }
     
  3. Offline

    Garris0n

    Note that you have to listen to the PlayerInteractEntityEvent to get a right click, not the EntityDamageByEntityEvent.
     
  4. Offline

    2MBKindiegames

    The EntityDamageByEntityEvent will not be called when the player right clicks, you might want to switch to PlayerInteractEntityEvent
     
Thread Status:
Not open for further replies.

Share This Page