TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/world/Flatlands.java

94 lines
2.7 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.world;
2013-08-22 00:07:14 +00:00
import java.io.File;
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
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;
public class Flatlands extends CustomWorld
2013-08-22 00:07:14 +00:00
{
private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString();
2013-08-22 00:07:14 +00:00
;
public Flatlands()
2013-08-22 00:07:14 +00:00
{
super("flatlands");
2013-08-22 00:07:14 +00:00
}
@Override
protected World generateWorld()
{
if (!ConfigEntry.FLATLANDS_GENERATE.getBoolean())
2013-08-22 00:07:14 +00:00
{
return null;
}
wipeFlatlandsIfFlagged();
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));
final World world = Bukkit.getServer().createWorld(worldCreator);
2013-08-22 00:07:14 +00:00
world.setSpawnFlags(false, false);
world.setSpawnLocation(0, 50, 0);
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();
plugin.gr.commitGameRules();
2013-08-22 00:07:14 +00:00
return world;
}
public void wipeFlatlandsIfFlagged()
2013-08-22 00:07:14 +00:00
{
boolean doFlatlandsWipe = false;
try
{
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)
{
FLog.info("Wiping flatlands.");
FUtil.setSavedFlag("do_wipe_flatlands", false);
2013-08-22 00:07:14 +00:00
FileUtils.deleteQuietly(new File("./flatlands"));
}
else
{
FLog.severe("Can't wipe flatlands, it is already loaded.");
2013-08-22 00:07:14 +00:00
}
}
}
}