2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.world;
|
2013-08-22 00:07:14 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2014-11-29 19:16:00 +00:00
|
|
|
import org.apache.commons.io.FileUtils;
|
2013-08-22 00:07:14 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.WorldCreator;
|
|
|
|
import org.bukkit.WorldType;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
public class Flatlands extends CustomWorld
|
2013-08-22 00:07:14 +00:00
|
|
|
{
|
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString();
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
public Flatlands()
|
2013-08-22 00:07:14 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
super("flatlands");
|
2013-08-22 00:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected World generateWorld()
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
if (!ConfigEntry.FLATLANDS_GENERATE.getBoolean())
|
2013-08-22 00:07:14 +00:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
wipeFlatlandsIfFlagged();
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
final WorldCreator worldCreator = new WorldCreator(getName());
|
2013-08-22 00:07:14 +00:00
|
|
|
worldCreator.generateStructures(false);
|
|
|
|
worldCreator.type(WorldType.NORMAL);
|
|
|
|
worldCreator.environment(World.Environment.NORMAL);
|
|
|
|
worldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS));
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
final World world = Bukkit.getServer().createWorld(worldCreator);
|
2013-08-22 00:07:14 +00:00
|
|
|
|
|
|
|
world.setSpawnFlags(false, false);
|
|
|
|
world.setSpawnLocation(0, 50, 0);
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
final Block welcomeSignBlock = world.getBlockAt(0, 50, 0);
|
2013-08-22 00:07:14 +00:00
|
|
|
welcomeSignBlock.setType(Material.SIGN_POST);
|
|
|
|
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign) welcomeSignBlock.getState();
|
|
|
|
|
|
|
|
org.bukkit.material.Sign signData = (org.bukkit.material.Sign) welcomeSign.getData();
|
|
|
|
signData.setFacingDirection(BlockFace.NORTH);
|
|
|
|
|
|
|
|
welcomeSign.setLine(0, ChatColor.GREEN + "Flatlands");
|
|
|
|
welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---");
|
|
|
|
welcomeSign.setLine(2, ChatColor.YELLOW + "Spawn Point");
|
|
|
|
welcomeSign.setLine(3, ChatColor.DARK_GRAY + "---");
|
|
|
|
welcomeSign.update();
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.gr.commitGameRules();
|
2013-08-22 00:07:14 +00:00
|
|
|
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public void wipeFlatlandsIfFlagged()
|
2013-08-22 00:07:14 +00:00
|
|
|
{
|
|
|
|
boolean doFlatlandsWipe = false;
|
|
|
|
try
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
doFlatlandsWipe = FUtil.getSavedFlag("do_wipe_flatlands");
|
2013-08-22 00:07:14 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doFlatlandsWipe)
|
|
|
|
{
|
|
|
|
if (Bukkit.getServer().getWorld("flatlands") == null)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.info("Wiping flatlands.");
|
|
|
|
FUtil.setSavedFlag("do_wipe_flatlands", false);
|
2013-08-22 00:07:14 +00:00
|
|
|
FileUtils.deleteQuietly(new File("./flatlands"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe("Can't wipe flatlands, it is already loaded.");
|
2013-08-22 00:07:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|