Solved Remove all entities safely?

Discussion in 'Plugin Development' started by Meatiex, Nov 27, 2014.

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

    Meatiex

    When I run the code below I can't move and can't use commands... "cant send chat message" witch is a message from the client meaning that you don't exist in the server..

    How would I remove everything but player?
    Code:java
    1. for (Entity entitie: player.getWorld().getEntities()) {
    2. EntityType type = entitie.getType();
    3. if (type != EntityType.BOAT && type != EntityType.ENDER_CRYSTAL && type != EntityType.ENDER_DRAGON && type != EntityType.ITEM_FRAME
    4. && type != EntityType.LEASH_HITCH && type != EntityType.MINECART && type != EntityType.MINECART_CHEST && type != EntityType.MINECART_COMMAND
    5. && type != EntityType.MINECART_FURNACE && type != EntityType.MINECART_HOPPER && type != EntityType.MINECART_MOB_SPAWNER
    6. && type != EntityType.MINECART_TNT && type != EntityType.PAINTING && type != EntityType.PLAYER && type != EntityType.WITHER
    7. && type != EntityType.WOLF && type != EntityType.WEATHER)
    8. count++;
    9. entitie.remove();
    10. }

    This code does remove everything not listed above, but the player still glitches out like explained above...
    Any help is awesome :D
     
  2. Offline

    Skionz

    Meatiex You removed the player :p
     
  3. Offline

    Meatiex

    You'r right... The if statement does nothing because it was triggering count++; instead of entitie.remove(); :p Thanks :D
     
Thread Status:
Not open for further replies.

Share This Page