UnloadWorld-Bugfix
Dieser Commit ist enthalten in:
Ursprung
8c0e9de3f0
Commit
a8eb4c84c8
@ -5,11 +5,9 @@ import de.warking.hunjy.MySQL.Bauwelt;
|
||||
import de.warking.hunjy.MySQL.BauweltMember;
|
||||
import de.warking.hunjy.MySQL.WarkingUser;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -25,17 +23,15 @@ public class BauWorld {
|
||||
|
||||
File w = new File("plugins/BauSystem/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));
|
||||
}
|
||||
|
||||
if (w.exists() && w.isDirectory()) {
|
||||
world = Bukkit.createWorld(new WorldCreator(owner.toString()));
|
||||
} else {
|
||||
if (!w.exists() || !w.isDirectory())
|
||||
FileUtils.copyDirectory(new File(BauSystem.getInstance().config.backupDir), new File("plugins/BauSystem/worlds/" + owner.toString()));
|
||||
|
||||
world = Bukkit.createWorld(new WorldCreator(owner.toString()));
|
||||
}
|
||||
Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), new LagDetectorRunnable(world, owner), 20, 20);
|
||||
LagDetectorRunnable detector = new LagDetectorRunnable(world, owner);
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), detector, 20, 20);
|
||||
detector.setTask(task);
|
||||
}
|
||||
|
||||
public static void unloadWorld(UUID owner) {
|
||||
@ -44,15 +40,15 @@ public class BauWorld {
|
||||
if (world != null) {
|
||||
for (Player p : world.getPlayers()) {
|
||||
p.teleport(BauSystem.getInstance().config.spawn);
|
||||
p.setGameMode(GameMode.ADVENTURE);
|
||||
}
|
||||
|
||||
world.save();
|
||||
|
||||
for (Chunk c : world.getLoadedChunks()) {
|
||||
c.unload();
|
||||
}
|
||||
|
||||
Bukkit.unloadWorld(world, true);
|
||||
if(!Bukkit.unloadWorld(world, true))
|
||||
System.out.println("Unloading world failed!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import de.warking.bausystem.BauSystem;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -12,6 +13,7 @@ class LagDetectorRunnable implements Runnable {
|
||||
private final World world;
|
||||
private final UUID worldOwner;
|
||||
private long timerstart = 0;
|
||||
private BukkitTask task;
|
||||
|
||||
public LagDetectorRunnable(World w, UUID owner) {
|
||||
world = w;
|
||||
@ -21,6 +23,7 @@ class LagDetectorRunnable implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
if (world == null) {
|
||||
task.cancel();
|
||||
return;
|
||||
}
|
||||
world.setStorm(false);
|
||||
@ -44,6 +47,7 @@ class LagDetectorRunnable implements Runnable {
|
||||
}else{
|
||||
if (System.currentTimeMillis() - timerstart > 60000) {
|
||||
BauWorld.unloadWorld(worldOwner);
|
||||
task.cancel();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -59,4 +63,7 @@ class LagDetectorRunnable implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void setTask(BukkitTask task) {
|
||||
this.task = task;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren