Can't get mob's name.

Discussion in 'Plugin Development' started by CrazyGuy3000, Nov 4, 2013.

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

    CrazyGuy3000

    Hi there,
    I am currently using this code to get the mobs name but its not working even in the slightest bit.
    Code:
    public void nope(EntityDamageByEntityEvent event){
            if(event.getEntity().getType().getName().equalsIgnoreCase("Bill")){
                event.setCancelled(true);
            }
        }
    It is supposed to stop any mob with the name of Bill to not get hurt.
     
  2. Offline

    HeroWorkbrine

    its getCustomName
     
  3. Offline

    CrazyGuy3000

    HeroWorkbrine

    Well I figured out one thing I was doing wrong but im still not sure about how to get the custom name.
    Mind showing some code?
     
  4. Offline

    HeroWorkbrine

    event.getEntity().getCustomName()

    Its that easy!
     
  5. Offline

    CrazyGuy3000

    HeroWorkbrine
    Sorry, that isn't working. Are you just doing a Pseudo or are you actually trying this?
     
  6. Offline

    HeroWorkbrine

    public void nope(EntityDamageByEntityEvent event){
    if(event.getEntity().getCustomName().equalsIgnoreCase("Bill")){
    event.setCancelled(true);
    }
    }

    im actually trying this

    oh sorry, that code is a bit wrong, wait a sec

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  7. Offline

    CrazyGuy3000

    It wants me to cast
    Code:
    if(event.getEntity().getCustomName().equalsIgnoreCase("Bill")){
                event.setCancelled(true);
            }
    Or it throws a error, when I do cast it, nothing happens.

    EDIT:Sorry just saw that message you sent.
     
  8. Offline

    HeroWorkbrine

    @EventHandler
    public void nope(EntityDamageByEntityEvent event) {
    if (((LivingEntity) event.getEntity()).getCustomName().equalsIgnoreCase("Bill")) {
    event.setCancelled(true);
    }
    }
     
  9. Offline

    Chinwe

    Check it's a LivingEntity, then you can use .getCustomName()
     
  10. Offline

    HeroWorkbrine

    Chinwe
    Thats precisly what i did
     
  11. Offline

    Chinwe

    Ninjaa'd :(
     
  12. Offline

    CrazyGuy3000

Thread Status:
Not open for further replies.

Share This Page