Solved Remove a entity with a specific CustomName

Discussion in 'Plugin Help/Development/Requests' started by tithibdu27, Mar 31, 2015.

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

    tithibdu27

    Hello, bukkit, Im doing a mount plugin, and when im leaving the entity, (Im using a PlayerMoveEvent check) its remove the entity (Only if the entity have my name).
    But when im leaving my pet and another Entity (This one dont have my name) is close of me, its log an error (NullPointerException). And i dont know how to solve it, im trying to solve it, but its not working.

    There is my code:
    Code:
        public void onWalk(PlayerMoveEvent e) {
            Player p = e.getPlayer();
    
            List<Entity> ets = p.getNearbyEntities(10, 10, 10);
    
            p.sendMessage(ets.toString());
    
            //Check if the player is on ground
            if(p.isOnGround()){
                if(ets != null) {
                    for(Entity en : ets){
                        //Check if the entity is a Chicken/Cow/MushroomCow/Pig/Sheep/Slime/Spider/Squid
                        //And check if the entity have the same name than the player             
                        if(en instanceof Chicken  && en.getCustomName().equals(p.getName())||
                                en instanceof Cow  && en.getCustomName().equals(p.getName())||
                                en instanceof MushroomCow  && en.getCustomName().equals(p.getName())||
                                en instanceof Pig  && en.getCustomName().equals(p.getName())||
                                en instanceof Sheep  && en.getCustomName().equals(p.getName())||
                                en instanceof Slime && en.getCustomName().equals(p.getName()) ||
                                en instanceof Spider && en.getCustomName().equals(p.getName()) ||
                                en instanceof Squid && en.getCustomName().equals(p.getName())) {
                            en.remove();
                   
                            p.sendMessage(prefix + ChatColor.YELLOW + "You left your mount");
                    
                         }
               
                    }
           
                }
       
            }
       
        }
     
    Last edited: Apr 2, 2015
  2. Offline

    tithibdu27

    Nvm, i found another way to do it.
     
Thread Status:
Not open for further replies.

Share This Page