Reinit limbo world at startup
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
In case server crashed, was stopped before all regions were cleared, and various other cases including folder size.
This commit is contained in:
parent
598dcd7e09
commit
4c9689af6f
@ -1,21 +1,47 @@
|
|||||||
package wtf.beatrice.limbomanager.objects;
|
package wtf.beatrice.limbomanager.objects;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
import org.bukkit.WorldType;
|
import org.bukkit.WorldType;
|
||||||
import wtf.beatrice.limbomanager.Cache;
|
import wtf.beatrice.limbomanager.Cache;
|
||||||
|
import wtf.beatrice.limbomanager.LimboManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
public class WorldGenerator
|
public class WorldGenerator
|
||||||
{
|
{
|
||||||
|
|
||||||
public void generateWorld()
|
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
|
// create world
|
||||||
|
LimboManager.getInstance().getLogger().info("Creating world from scratch...");
|
||||||
WorldCreator worldCreator = new WorldCreator(Cache.worldName);
|
WorldCreator worldCreator = new WorldCreator(Cache.worldName);
|
||||||
worldCreator.environment(World.Environment.THE_END);
|
worldCreator.environment(World.Environment.THE_END);
|
||||||
worldCreator.generateStructures(false);
|
worldCreator.generateStructures(false);
|
||||||
worldCreator.type(WorldType.FLAT);
|
worldCreator.type(WorldType.FLAT);
|
||||||
worldCreator.generator("VoidGen");
|
worldCreator.generator("VoidGen");
|
||||||
Cache.limboWorld = worldCreator.createWorld();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user