Check if mob has a name

Discussion in 'Plugin Development' started by KoolzSkillz, Dec 12, 2014.

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

    KoolzSkillz

    Hey, How would i check if the mob the player is hitting has a name WITHOUT NMS,
    ie

    player hits a zombie named George, it adds confusion to the player.
    can someone please explain how to do this, all i need is the way to check if it has a name
     
  2. Offline

    teej107

  3. Offline

    KoolzSkillz

    @teej107
    so far i can spawn the zombie and set its custom name, im not sure what event i would use tho, EntityDamageByEntityEvent?
     
  4. Offline

    teej107

  5. Offline

    KoolzSkillz

    @teej107 ok and back to my main question, how would i get the name
     
  6. Offline

    CodingAddiction

    You'll need to check if the zombie actually has a custom name to avoid null pointers, check if the custom name is visible, and then checking if the custom name it has is George. I tried to do it without NMS but it messed up.

    @EventHandler
    public void onHit(EntityDamageByEntityEvent event) {

    if (event.getDamager() instanceof Player && event.getEntity() instanceof EntityZombie) {

    Player player = (Player) event.getDamager();
    EntityZombie zombie = (EntityZombie) event.getEntity();

    if (zombie.hasCustomName()) {
    if (zombie.getCustomNameVisible() && zombie.getCustomName().equalsIgnoreCase("George"))
    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, ticks, level));
    }
    }
    }
     
  7. Offline

    KoolzSkillz

    @CodingAddiction
    ok ive run into an additional problem

    where im registering the events of the class it asks for a world name, the (null)
    this.getServer().getPluginManager().registerEvents(new ZombieBoss(null), this);
     
  8. Offline

    Skionz

    @KoolzSkillz What does you constructor look like? Did you even write the code your using?
     
  9. Offline

    teej107

    Read the JavaDocs! My first post was a link to the JavaDocs.
     
Thread Status:
Not open for further replies.

Share This Page