Solved Clearing all entities from a world does not work?

Discussion in 'Plugin Development' started by IconByte, Mar 1, 2015.

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

    IconByte

    Hello, I am having problems with deleting all entities from a world. Any help?

    I am using this:
    Code:
                        for (Entity e : Bukkit.getWorld("Arena").getEntities()) {
                            e.remove();
                        }
     
  2. Offline

    TheMintyMate

    @IconByte
    How are you then testing to see if the entities are gone, and have you checked that the world "Arena" is loaded/exists?
    - Minty
     
  3. Offline

    IconByte

    Umm, the world should be loaded:
    Code:
        public void startingTimer() {
            startCountdownIsRunning = true;
            startTime = this.getConfig().getInt("start-time");
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                public void run() {
                    startTime--;
                    if (getConfig().getString("server-version").equals("1.7")) {
                        for (Player onlinePlayers : Bukkit.getOnlinePlayers()) {
                            onlinePlayers.setExp(0);
                            onlinePlayers.setLevel(startTime);
                        }
                    }
                    if (getConfig().getString("server-version").equals("1.8")) {
                        ActionAPI.sendServerAnnouncement("§a" + _("STARTING_IN") + ": §f" + startTime);
                    }
                    if (startTime == 5) {
                        Bukkit.broadcastMessage("§a" + _("LOADING_MAP") + "...");
                        MapRollback mrb = new MapRollback(getLogger(), getDataFolder());
                        mrb.loadMap("Arena");
                    }
                    if (startTime == 3) {
                        WorldCreator wc = new WorldCreator("Arena");
                        wc.generator(new VoidGenerator());
                        Bukkit.createWorld(wc);
                    }
                    if (startTime == 1) {
                        for (Entity e : Bukkit.getWorld("Arena").getEntities()) {
                            e.remove();
                        }
                    }
                    if (startTime <= 0) {
                        Bukkit.getServer().getScheduler().cancelAllTasks();
                        startCountdownIsRunning = false;
                        gamingTimer();
                        particleTimer();
                        Bukkit.broadcastMessage("§9" + _("GAME_STARTED") + "!");
                    }
                }
            }, 0L, 1*20L);
        }
    //EDIT: It worked, when I was in the world, but then it removed me (Player)... :/
     
    TheMintyMate likes this.
  4. Offline

    Skionz

    @IconByte A Player is an Entity. A simple check will solve that issue.
     
    IconByte and TheMintyMate like this.
  5. Offline

    TheMintyMate

    @IconByte
    Just do a simple check in your for statement:
    Code:
    if (!(e instanceof Player)){ /* if not a player*/
    e.remove();
    }
    
    - Minty
     
    IconByte likes this.
  6. Offline

    IconByte

    Thanks! Got it fixed. :)
     
Thread Status:
Not open for further replies.

Share This Page