SteamWar/BauSystem
Archiviert
13
0

UnloadWorld-Bugfix

Dieser Commit ist enthalten in:
Lixfel 2019-03-28 10:30:05 +01:00
Ursprung 8c0e9de3f0
Commit a8eb4c84c8
2 geänderte Dateien mit 52 neuen und 49 gelöschten Zeilen

Datei anzeigen

@ -5,11 +5,9 @@ import de.warking.hunjy.MySQL.Bauwelt;
import de.warking.hunjy.MySQL.BauweltMember; import de.warking.hunjy.MySQL.BauweltMember;
import de.warking.hunjy.MySQL.WarkingUser; import de.warking.hunjy.MySQL.WarkingUser;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -25,17 +23,15 @@ public class BauWorld {
File w = new File("plugins/BauSystem/worlds/" + owner); File w = new File("plugins/BauSystem/worlds/" + owner);
File region = new File("plugins/WorldGuard/worlds/" + owner); File region = new File("plugins/WorldGuard/worlds/" + owner);
if (!region.exists() || !region.isDirectory()) { if (!region.exists() || !region.isDirectory())
FileUtils.copyDirectory(new File(BauSystem.getInstance().config.regionDir), new File("plugins/WorldGuard/worlds/" + owner)); FileUtils.copyDirectory(new File(BauSystem.getInstance().config.regionDir), new File("plugins/WorldGuard/worlds/" + owner));
} if (!w.exists() || !w.isDirectory())
if (w.exists() && w.isDirectory()) {
world = Bukkit.createWorld(new WorldCreator(owner.toString()));
} else {
FileUtils.copyDirectory(new File(BauSystem.getInstance().config.backupDir), new File("plugins/BauSystem/worlds/" + owner.toString())); FileUtils.copyDirectory(new File(BauSystem.getInstance().config.backupDir), new File("plugins/BauSystem/worlds/" + owner.toString()));
world = Bukkit.createWorld(new WorldCreator(owner.toString())); world = Bukkit.createWorld(new WorldCreator(owner.toString()));
} LagDetectorRunnable detector = new LagDetectorRunnable(world, owner);
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), new LagDetectorRunnable(world, owner), 20, 20); BukkitTask task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), detector, 20, 20);
detector.setTask(task);
} }
public static void unloadWorld(UUID owner) { public static void unloadWorld(UUID owner) {
@ -44,15 +40,15 @@ public class BauWorld {
if (world != null) { if (world != null) {
for (Player p : world.getPlayers()) { for (Player p : world.getPlayers()) {
p.teleport(BauSystem.getInstance().config.spawn); p.teleport(BauSystem.getInstance().config.spawn);
p.setGameMode(GameMode.ADVENTURE);
} }
world.save();
for (Chunk c : world.getLoadedChunks()) { for (Chunk c : world.getLoadedChunks()) {
c.unload(); c.unload();
} }
Bukkit.unloadWorld(world, true); if(!Bukkit.unloadWorld(world, true))
System.out.println("Unloading world failed!");
} }
} }

Datei anzeigen

@ -4,6 +4,7 @@ import de.warking.bausystem.BauSystem;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import java.util.UUID; import java.util.UUID;
@ -12,6 +13,7 @@ class LagDetectorRunnable implements Runnable {
private final World world; private final World world;
private final UUID worldOwner; private final UUID worldOwner;
private long timerstart = 0; private long timerstart = 0;
private BukkitTask task;
public LagDetectorRunnable(World w, UUID owner) { public LagDetectorRunnable(World w, UUID owner) {
world = w; world = w;
@ -21,6 +23,7 @@ class LagDetectorRunnable implements Runnable {
@Override @Override
public void run() { public void run() {
if (world == null) { if (world == null) {
task.cancel();
return; return;
} }
world.setStorm(false); world.setStorm(false);
@ -44,6 +47,7 @@ class LagDetectorRunnable implements Runnable {
}else{ }else{
if (System.currentTimeMillis() - timerstart > 60000) { if (System.currentTimeMillis() - timerstart > 60000) {
BauWorld.unloadWorld(worldOwner); BauWorld.unloadWorld(worldOwner);
task.cancel();
return; return;
} }
} }
@ -59,4 +63,7 @@ class LagDetectorRunnable implements Runnable {
} }
} }
public void setTask(BukkitTask task) {
this.task = task;
}
} }