Solved Method to remove specific entity?

Discussion in 'Plugin Development' started by elementalgodz11, Apr 1, 2014.

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

    elementalgodz11

    I am trying to remove all of a specific entity using a method (to make things easier):

    Here is what I have tried:
    Code:java
    1. public void removeEntityTypes(Entity entity) {
    2.  
    3. for (Entity entities : Bukkit.getServer().getWorld("world").getEntities()) {
    4.  
    5. if (entities instanceof Boat) {
    6.  
    7. entities.remove();
    8.  
    9. }
    10.  
    11. }
    12.  
    13. }


    I have tried changing boat to what the entity is in the parenthasis (entity), and have got numerous errors. I have tried using EntityType instead of Entity and directly grabbing the entity class using org.bukkit.entity.Entity without any luck.

    Any help is appreciated, thanks.
     
  2. Offline

    2MBKindiegames

    This should work:
    Code:java
    1. //You don't need to add Entity entity into your void
    2. public void removeEntityTypes() {
    3. //Just use Bukkit.getWorld
    4. for (Entity entities : Bukkit.getWorld("world").getEntities()) {
    5. //getType() is more accurate
    6. if (entities.getType() == EntityType.BOAT) {
    7. //Removing
    8. entities.remove();
    9. }
    10. }
    11. }
     
  3. 2MBKindiegames I don't think that's what he actually wanted, I think he was just using boat as an example.

    elementalgodz11 Either way, try this:

    PHP:
        public void removeEntityTypes(EntityType type) {
            for(
    Entity ent Bukkit.getWorld("world").getEntitiesByClass(type.getEntityClass())) {
                
    ent.remove();
            }
        }
       
        public 
    void removeEntityTypes(Entity entity) {
            
    removeEntityTypes(entity.getType());
        }
    Simply call the method with either the EntityType or an entity with the type you want to remove :)
     
Thread Status:
Not open for further replies.

Share This Page