Clearing Entity In Specified World

Discussion in 'Plugin Development' started by leimekiller, Jul 25, 2013.

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

    leimekiller

    Hello,

    I am trying to Clear all entities in a specified world. This is what I got so far, but I don't know what I have to do more.

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    3. {
    4. if(sender instanceof Player)
    5. {
    6. Player player = (Player)sender;
    7.  
    8. if(cmd.getName().equalsIgnoreCase("entityclear"))
    9. {
    10. (World world = Bukkit.getWorlds())
    11. for(Entity entity : world.getEntities())
    12. {
    13. Bukkit.getServer().getWorld("Factions");
    14.  
    15. if(entity instanceof Player == false)
    16. {
    17. entity.remove();
    18. }
    19. }
    20. return true;
    21. }
    22. }
    23.  
    24. return false;
     
  2. Offline

    Tomskied

    Why are you getting the world Factions for each entity?
     
  3. Offline

    leimekiller

    Because I want to clear all entities in the world ''Factions''
     
  4. Offline

    Tomskied

    Ok, try something like this instead.
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    3. {
    4. if(sender instanceof Player)
    5. {
    6. Player player = (Player)sender;
    7.  
    8. if(cmd.getName().equalsIgnoreCase("entityclear")){
    9. World world = world.getWorld("Factions");
    10. for(Entity entity : world.getEntities()){
    11. if(!(entity instanceof Player)){
    12. entity.remove();
    13. }
    14. }
    15. return true;
    16. }
    17. }
    18.  
    19. return false;
    20. }
     
  5. Offline

    leimekiller

    Thanks, but it doesn't take line 9.
     
  6. Offline

    Bammerbom

    leimekiller World world = getServer().getWorld("Factions");
     
    Tomskied likes this.
  7. Offline

    Tomskied

  8. Offline

    leimekiller

    Thanks :)
     
  9. Offline

    xmarinusx

    leimekiller
    It's nice to copy and paste it, but do you really understand what he just gave you? If not just ask.
    By copy and pasting you will never learn to code by yourself.
     
Thread Status:
Not open for further replies.

Share This Page