Reinit limbo world at startup
continuous-integration/drone/push Build is passing Details

In case server crashed, was stopped before all regions were cleared, and various other cases including folder size.
This commit is contained in:
Bea 2022-11-12 05:31:14 +01:00
parent 598dcd7e09
commit 4c9689af6f
1 changed files with 26 additions and 0 deletions

View File

@ -1,21 +1,47 @@
package wtf.beatrice.limbomanager.objects;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import wtf.beatrice.limbomanager.Cache;
import wtf.beatrice.limbomanager.LimboManager;
import java.io.File;
public class WorldGenerator
{
public void generateWorld()
{
// unload world
LimboManager.getInstance().getLogger().info("Force unloading world...");
Bukkit.getServer().unloadWorld(Cache.worldName, false);
// delete world files
LimboManager.getInstance().getLogger().info("Resetting world...");
String worldFolderPath = Bukkit.getServer().getWorldContainer().getAbsolutePath() + File.separator + Cache.worldName;
File worldFolder = new File(worldFolderPath);
deleteDirectory(worldFolder);
// create world
LimboManager.getInstance().getLogger().info("Creating world from scratch...");
WorldCreator worldCreator = new WorldCreator(Cache.worldName);
worldCreator.environment(World.Environment.THE_END);
worldCreator.generateStructures(false);
worldCreator.type(WorldType.FLAT);
worldCreator.generator("VoidGen");
Cache.limboWorld = worldCreator.createWorld();
LimboManager.getInstance().getLogger().info("World ready!");
}
boolean deleteDirectory(File directoryToBeDeleted) {
File[] allContents = directoryToBeDeleted.listFiles();
if (allContents != null) {
for (File file : allContents) {
deleteDirectory(file);
}
}
return directoryToBeDeleted.delete();
}
}