#506 Refactor WorldUnloadTask

This commit is contained in:
Daniel Saukel 2019-02-21 19:00:04 +01:00
parent 7bc16b9aff
commit 8c117c8e2b

View File

@ -17,7 +17,7 @@
package de.erethon.dungeonsxl.world; package de.erethon.dungeonsxl.world;
import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.player.DGamePlayer; import java.util.Set;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
/** /**
@ -33,20 +33,12 @@ public class WorldUnloadTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
for (DGameWorld gameWorld : plugin.getDWorldCache().getGameWorlds()) { Set<DInstanceWorld> instances = plugin.getDWorldCache().getInstances();
if (gameWorld.exists()) { System.out.println(instances);
if (gameWorld.getWorld().getPlayers().isEmpty()) { for (DInstanceWorld instance : instances.toArray(new DInstanceWorld[instances.size()])) {
if (DGamePlayer.getByWorld(gameWorld.getWorld()).isEmpty()) { if (instance.exists()) {
gameWorld.delete(); if (instance.getWorld().getPlayers().isEmpty()) {
} instance.delete();
}
}
}
for (DEditWorld editWorld : plugin.getDWorldCache().getEditWorlds()) {
if (editWorld.exists()) {
if (editWorld.getWorld().getPlayers().isEmpty()) {
editWorld.delete(true);
} }
} }
} }