mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-11 13:33:54 +00:00
Mavenized project
This commit is contained in:
@ -0,0 +1,253 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
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;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public final class AdminWorld extends CustomWorld
|
||||
{
|
||||
private static final long CACHE_CLEAR_FREQUENCY = 30L * 1000L; //30 seconds, milliseconds
|
||||
private static final long TP_COOLDOWN_TIME = 500L; //0.5 seconds, milliseconds
|
||||
private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString();
|
||||
private static final String WORLD_NAME = "adminworld";
|
||||
//
|
||||
private final Map<Player, Long> teleportCooldown = new HashMap<Player, Long>();
|
||||
private final Map<CommandSender, Boolean> accessCache = new HashMap<CommandSender, Boolean>();
|
||||
//
|
||||
private Long cacheLastCleared = null;
|
||||
private Map<Player, Player> guestList = new HashMap<Player, Player>(); // Guest, Supervisor
|
||||
private WorldWeather weather = WorldWeather.OFF;
|
||||
private WorldTime time = WorldTime.INHERIT;
|
||||
|
||||
public AdminWorld()
|
||||
{
|
||||
super("adminworld");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToWorld(Player player)
|
||||
{
|
||||
if (!canAccessWorld(player))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
super.sendToWorld(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected World generateWorld()
|
||||
{
|
||||
final WorldCreator worldCreator = new WorldCreator(getName());
|
||||
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);
|
||||
|
||||
world.setSpawnFlags(false, false);
|
||||
world.setSpawnLocation(0, 50, 0);
|
||||
|
||||
final Block welcomeSignBlock = world.getBlockAt(0, 50, 0);
|
||||
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 + "AdminWorld");
|
||||
welcomeSign.setLine(1, ChatColor.DARK_GRAY + "---");
|
||||
welcomeSign.setLine(2, ChatColor.YELLOW + "Spawn Point");
|
||||
welcomeSign.setLine(3, ChatColor.DARK_GRAY + "---");
|
||||
welcomeSign.update();
|
||||
|
||||
plugin.gr.commitGameRules();
|
||||
return world;
|
||||
}
|
||||
|
||||
public boolean addGuest(Player guest, Player supervisor)
|
||||
{
|
||||
if (guest == supervisor || plugin.al.isAdmin(guest))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (plugin.al.isAdmin(supervisor))
|
||||
{
|
||||
guestList.put(guest, supervisor);
|
||||
wipeAccessCache();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Player removeGuest(Player guest)
|
||||
{
|
||||
final Player player = guestList.remove(guest);
|
||||
wipeAccessCache();
|
||||
return player;
|
||||
}
|
||||
|
||||
public Player removeGuest(String partialName)
|
||||
{
|
||||
partialName = partialName.toLowerCase();
|
||||
final Iterator<Player> it = guestList.keySet().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Player player = it.next();
|
||||
if (player.getName().toLowerCase().contains(partialName))
|
||||
{
|
||||
removeGuest(player);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public String guestListToString()
|
||||
{
|
||||
final List<String> output = new ArrayList<String>();
|
||||
final Iterator<Map.Entry<Player, Player>> it = guestList.entrySet().iterator();
|
||||
while (it.hasNext())
|
||||
{
|
||||
final Entry<Player, Player> entry = it.next();
|
||||
final Player player = entry.getKey();
|
||||
final Player supervisor = entry.getValue();
|
||||
output.add(player.getName() + " (Supervisor: " + supervisor.getName() + ")");
|
||||
}
|
||||
return StringUtils.join(output, ", ");
|
||||
}
|
||||
|
||||
public void purgeGuestList()
|
||||
{
|
||||
guestList.clear();
|
||||
wipeAccessCache();
|
||||
}
|
||||
|
||||
public boolean validateMovement(PlayerMoveEvent event)
|
||||
{
|
||||
World world;
|
||||
try
|
||||
{
|
||||
world = getWorld();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (world == null || !event.getTo().getWorld().equals(world))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
if (canAccessWorld(player))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Long lastTP = teleportCooldown.get(player);
|
||||
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
if (lastTP == null || lastTP + TP_COOLDOWN_TIME <= currentTimeMillis)
|
||||
{
|
||||
teleportCooldown.put(player, currentTimeMillis);
|
||||
FLog.info(player.getName() + " attempted to access the AdminWorld.");
|
||||
event.setTo(Bukkit.getWorlds().get(0).getSpawnLocation());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void wipeAccessCache()
|
||||
{
|
||||
cacheLastCleared = System.currentTimeMillis();
|
||||
accessCache.clear();
|
||||
}
|
||||
|
||||
public boolean canAccessWorld(final Player player)
|
||||
{
|
||||
long currentTimeMillis = System.currentTimeMillis();
|
||||
if (cacheLastCleared == null || cacheLastCleared.longValue() + CACHE_CLEAR_FREQUENCY <= currentTimeMillis)
|
||||
{
|
||||
cacheLastCleared = currentTimeMillis;
|
||||
accessCache.clear();
|
||||
}
|
||||
|
||||
Boolean cached = accessCache.get(player);
|
||||
if (cached == null)
|
||||
{
|
||||
boolean canAccess = plugin.al.isAdmin(player);
|
||||
if (!canAccess)
|
||||
{
|
||||
Player supervisor = guestList.get(player);
|
||||
canAccess = supervisor != null && supervisor.isOnline() && plugin.al.isAdmin(supervisor);
|
||||
if (!canAccess)
|
||||
{
|
||||
guestList.remove(player);
|
||||
}
|
||||
}
|
||||
cached = canAccess;
|
||||
accessCache.put(player, cached);
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
public WorldWeather getWeatherMode()
|
||||
{
|
||||
return weather;
|
||||
}
|
||||
|
||||
public void setWeatherMode(final WorldWeather weatherMode)
|
||||
{
|
||||
this.weather = weatherMode;
|
||||
|
||||
try
|
||||
{
|
||||
weatherMode.setWorldToWeather(getWorld());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public WorldTime getTimeOfDay()
|
||||
{
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTimeOfDay(final WorldTime timeOfDay)
|
||||
{
|
||||
this.time = timeOfDay;
|
||||
|
||||
try
|
||||
{
|
||||
timeOfDay.setWorldToTime(getWorld());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Cleanroom Generator
|
||||
* Copyright (C) 2011-2012 nvx
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import java.util.Random;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CleanroomBlockPopulator extends BlockPopulator
|
||||
{
|
||||
|
||||
byte[] layerDataValues;
|
||||
|
||||
protected CleanroomBlockPopulator(byte[] layerDataValues)
|
||||
{
|
||||
this.layerDataValues = layerDataValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(World world, Random random, Chunk chunk)
|
||||
{
|
||||
if (layerDataValues != null)
|
||||
{
|
||||
int x = chunk.getX() << 4;
|
||||
int z = chunk.getZ() << 4;
|
||||
|
||||
for (int y = 0; y < layerDataValues.length; y++)
|
||||
{
|
||||
byte dataValue = layerDataValues[y];
|
||||
if (dataValue == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int xx = 0; xx < 16; xx++)
|
||||
{
|
||||
for (int zz = 0; zz < 16; zz++)
|
||||
{
|
||||
world.getBlockAt(x + xx, y, z + zz).setData(dataValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Cleanroom Generator
|
||||
* Copyright (C) 2011-2012 nvx
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import static java.lang.System.arraycopy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class CleanroomChunkGenerator extends ChunkGenerator
|
||||
{
|
||||
private static final Logger log = Bukkit.getLogger();
|
||||
private short[] layer;
|
||||
private byte[] layerDataValues;
|
||||
|
||||
public CleanroomChunkGenerator()
|
||||
{
|
||||
this("64,stone");
|
||||
}
|
||||
|
||||
public CleanroomChunkGenerator(String id)
|
||||
{
|
||||
if (id != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
int y = 0;
|
||||
|
||||
layer = new short[128]; // Default to 128, will be resized later if required
|
||||
layerDataValues = null;
|
||||
|
||||
if ((id.length() > 0) && (id.charAt(0) == '.')) // Is the first character a '.'? If so, skip bedrock generation.
|
||||
{
|
||||
id = id.substring(1); // Skip bedrock then and remove the .
|
||||
}
|
||||
else // Guess not, bedrock at layer0 it is then.
|
||||
{
|
||||
layer[y++] = (short) Material.BEDROCK.getId();
|
||||
}
|
||||
|
||||
if (id.length() > 0)
|
||||
{
|
||||
String tokens[] = id.split("[,]");
|
||||
|
||||
if ((tokens.length % 2) != 0)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
for (int i = 0; i < tokens.length; i += 2)
|
||||
{
|
||||
int height = Integer.parseInt(tokens[i]);
|
||||
if (height <= 0)
|
||||
{
|
||||
log.warning("[CleanroomGenerator] Invalid height '" + tokens[i] + "'. Using 64 instead.");
|
||||
height = 64;
|
||||
}
|
||||
|
||||
String materialTokens[] = tokens[i + 1].split("[:]", 2);
|
||||
byte dataValue = 0;
|
||||
if (materialTokens.length == 2)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Lets try to read the data value
|
||||
dataValue = Byte.parseByte(materialTokens[1]);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.warning("[CleanroomGenerator] Invalid Data Value '" + materialTokens[1] + "'. Defaulting to 0.");
|
||||
dataValue = 0;
|
||||
}
|
||||
}
|
||||
Material mat = Material.matchMaterial(materialTokens[0]);
|
||||
if (mat == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Mabe it's an integer?
|
||||
mat = Material.getMaterial(Integer.parseInt(materialTokens[0]));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Well, I guess it wasn't an integer after all... Awkward...
|
||||
}
|
||||
|
||||
if (mat == null)
|
||||
{
|
||||
log.warning("[CleanroomGenerator] Invalid Block ID '" + materialTokens[0] + "'. Defaulting to stone.");
|
||||
mat = Material.STONE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mat.isBlock())
|
||||
{
|
||||
log.warning("[CleanroomGenerator] Error, '" + materialTokens[0] + "' is not a block. Defaulting to stone.");
|
||||
mat = Material.STONE;
|
||||
}
|
||||
|
||||
if (y + height > layer.length)
|
||||
{
|
||||
short[] newLayer = new short[Math.max(y + height, layer.length * 2)];
|
||||
arraycopy(layer, 0, newLayer, 0, y);
|
||||
layer = newLayer;
|
||||
if (layerDataValues != null)
|
||||
{
|
||||
byte[] newLayerDataValues = new byte[Math.max(y + height, layerDataValues.length * 2)];
|
||||
arraycopy(layerDataValues, 0, newLayerDataValues, 0, y);
|
||||
layerDataValues = newLayerDataValues;
|
||||
}
|
||||
}
|
||||
|
||||
Arrays.fill(layer, y, y + height, (short) mat.getId());
|
||||
if (dataValue != 0)
|
||||
{
|
||||
if (layerDataValues == null)
|
||||
{
|
||||
layerDataValues = new byte[layer.length];
|
||||
}
|
||||
Arrays.fill(layerDataValues, y, y + height, dataValue);
|
||||
}
|
||||
y += height;
|
||||
}
|
||||
}
|
||||
|
||||
// Trim to size
|
||||
if (layer.length > y)
|
||||
{
|
||||
short[] newLayer = new short[y];
|
||||
arraycopy(layer, 0, newLayer, 0, y);
|
||||
layer = newLayer;
|
||||
}
|
||||
if (layerDataValues != null && layerDataValues.length > y)
|
||||
{
|
||||
byte[] newLayerDataValues = new byte[y];
|
||||
arraycopy(layerDataValues, 0, newLayerDataValues, 0, y);
|
||||
layerDataValues = newLayerDataValues;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.severe("[CleanroomGenerator] Error parsing CleanroomGenerator ID '" + id + "'. using defaults '64,1': " + e.toString());
|
||||
e.printStackTrace();
|
||||
layerDataValues = null;
|
||||
layer = new short[65];
|
||||
layer[0] = (short) Material.BEDROCK.getId();
|
||||
Arrays.fill(layer, 1, 65, (short) Material.STONE.getId());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
layerDataValues = null;
|
||||
layer = new short[65];
|
||||
layer[0] = (short) Material.BEDROCK.getId();
|
||||
Arrays.fill(layer, 1, 65, (short) Material.STONE.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public short[][] generateExtBlockSections(World world, Random random, int x, int z, BiomeGrid biomes)
|
||||
{
|
||||
int maxHeight = world.getMaxHeight();
|
||||
if (layer.length > maxHeight)
|
||||
{
|
||||
log.warning("[CleanroomGenerator] Error, chunk height " + layer.length + " is greater than the world max height (" + maxHeight + "). Trimming to world max height.");
|
||||
short[] newLayer = new short[maxHeight];
|
||||
arraycopy(layer, 0, newLayer, 0, maxHeight);
|
||||
layer = newLayer;
|
||||
}
|
||||
short[][] result = new short[maxHeight / 16][]; // 16x16x16 chunks
|
||||
for (int i = 0; i < layer.length; i += 16)
|
||||
{
|
||||
result[i >> 4] = new short[4096];
|
||||
for (int y = 0; y < Math.min(16, layer.length - i); y++)
|
||||
{
|
||||
Arrays.fill(result[i >> 4], y * 16 * 16, (y + 1) * 16 * 16, layer[i + y]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPopulator> getDefaultPopulators(World world)
|
||||
{
|
||||
if (layerDataValues != null)
|
||||
{
|
||||
return Arrays.asList((BlockPopulator) new CleanroomBlockPopulator(layerDataValues));
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is the default, but just in case default populators change to stock minecraft populators by default...
|
||||
return new ArrayList<BlockPopulator>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getFixedSpawnLocation(World world, Random random)
|
||||
{
|
||||
if (!world.isChunkLoaded(0, 0))
|
||||
{
|
||||
world.loadChunk(0, 0);
|
||||
}
|
||||
|
||||
if ((world.getHighestBlockYAt(0, 0) <= 0) && (world.getBlockAt(0, 0, 0).getType() == Material.AIR)) // SPACE!
|
||||
{
|
||||
return new Location(world, 0, 64, 0); // Lets allow people to drop a little before hitting the void then shall we?
|
||||
}
|
||||
|
||||
return new Location(world, 0, world.getHighestBlockYAt(0, 0), 0);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import net.pravian.aero.component.PluginComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class CustomWorld extends PluginComponent<TotalFreedomMod>
|
||||
{
|
||||
@Getter
|
||||
private final String name;
|
||||
//
|
||||
private World world;
|
||||
|
||||
public CustomWorld(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public final World getWorld()
|
||||
{
|
||||
if (world == null || !Bukkit.getWorlds().contains(world))
|
||||
{
|
||||
world = generateWorld();
|
||||
}
|
||||
|
||||
if (world == null)
|
||||
{
|
||||
FLog.warning("Could not load world: " + name);
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
public void sendToWorld(Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
player.teleport(getWorld().getSpawnLocation());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
player.sendMessage(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract World generateWorld();
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
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;
|
||||
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
|
||||
{
|
||||
private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString();
|
||||
|
||||
;
|
||||
|
||||
public Flatlands()
|
||||
{
|
||||
super("flatlands");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected World generateWorld()
|
||||
{
|
||||
if (!ConfigEntry.FLATLANDS_GENERATE.getBoolean())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
wipeFlatlandsIfFlagged();
|
||||
|
||||
final WorldCreator worldCreator = new WorldCreator(getName());
|
||||
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);
|
||||
|
||||
world.setSpawnFlags(false, false);
|
||||
world.setSpawnLocation(0, 50, 0);
|
||||
|
||||
final Block welcomeSignBlock = world.getBlockAt(0, 50, 0);
|
||||
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();
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
public void wipeFlatlandsIfFlagged()
|
||||
{
|
||||
boolean doFlatlandsWipe = false;
|
||||
try
|
||||
{
|
||||
doFlatlandsWipe = FUtil.getSavedFlag("do_wipe_flatlands");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
if (doFlatlandsWipe)
|
||||
{
|
||||
if (Bukkit.getServer().getWorld("flatlands") == null)
|
||||
{
|
||||
FLog.info("Wiping flatlands.");
|
||||
FUtil.setSavedFlag("do_wipe_flatlands", false);
|
||||
FileUtils.deleteQuietly(new File("./flatlands"));
|
||||
}
|
||||
else
|
||||
{
|
||||
FLog.severe("Can't wipe flatlands, it is already loaded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,132 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.player.FPlayer;
|
||||
import net.pravian.aero.component.service.AbstractService;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.weather.ThunderChangeEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
|
||||
public class WorldManager extends AbstractService<TotalFreedomMod>
|
||||
{
|
||||
|
||||
public Flatlands flatlands;
|
||||
public AdminWorld adminworld;
|
||||
|
||||
public WorldManager(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
this.flatlands = new Flatlands();
|
||||
this.adminworld = new AdminWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
flatlands.getWorld();
|
||||
adminworld.getWorld();
|
||||
|
||||
// Disable weather
|
||||
if (ConfigEntry.DISABLE_WEATHER.getBoolean())
|
||||
{
|
||||
for (World world : server.getWorlds())
|
||||
{
|
||||
world.setThundering(false);
|
||||
world.setStorm(false);
|
||||
world.setThunderDuration(0);
|
||||
world.setWeatherDuration(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
flatlands.getWorld().save();
|
||||
adminworld.getWorld().save();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event)
|
||||
{
|
||||
final Player player = event.getPlayer();
|
||||
final FPlayer fPlayer = plugin.pl.getPlayer(player);
|
||||
|
||||
if (!plugin.al.isAdmin(player) && fPlayer.getFreezeData().isFrozen())
|
||||
{
|
||||
return; // Don't process adminworld validation
|
||||
}
|
||||
|
||||
adminworld.validateMovement(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event)
|
||||
{
|
||||
final Location from = event.getFrom();
|
||||
final Location to = event.getTo();
|
||||
|
||||
try
|
||||
{
|
||||
if (from.getWorld() == to.getWorld() && from.distanceSquared(to) < (0.0002 * 0.0002))
|
||||
{
|
||||
// If player just rotated, but didn't move, don't process this event.
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
}
|
||||
|
||||
adminworld.validateMovement(event);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onThunderChange(ThunderChangeEvent event)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (event.getWorld().equals(adminworld.getWorld()) && adminworld.getWeatherMode() != WorldWeather.OFF)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
if (ConfigEntry.DISABLE_WEATHER.getBoolean() && event.toThunderState())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onWeatherChange(WeatherChangeEvent event)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (event.getWorld().equals(adminworld.getWorld()) && adminworld.getWeatherMode() != WorldWeather.OFF)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
if (ConfigEntry.DISABLE_WEATHER.getBoolean() && event.toWeatherState())
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.World;
|
||||
|
||||
public enum WorldTime
|
||||
{
|
||||
INHERIT(),
|
||||
SUNRISE("sunrise,morning", 0),
|
||||
NOON("noon,midday,day", 6000),
|
||||
SUNSET("sunset,evening", 12000),
|
||||
MIDNIGHT("midnight,night", 18000);
|
||||
//
|
||||
private final int timeTicks;
|
||||
private final List<String> aliases;
|
||||
|
||||
private WorldTime()
|
||||
{
|
||||
this.timeTicks = 0;
|
||||
this.aliases = null;
|
||||
}
|
||||
|
||||
private WorldTime(String aliases, int timeTicks)
|
||||
{
|
||||
this.timeTicks = timeTicks;
|
||||
this.aliases = Arrays.asList(StringUtils.split(aliases, ","));
|
||||
}
|
||||
|
||||
public int getTimeTicks()
|
||||
{
|
||||
return timeTicks;
|
||||
}
|
||||
|
||||
public void setWorldToTime(World world)
|
||||
{
|
||||
long time = world.getTime();
|
||||
time -= time % 24000;
|
||||
world.setTime(time + 24000 + getTimeTicks());
|
||||
}
|
||||
|
||||
public static WorldTime getByAlias(String needle)
|
||||
{
|
||||
needle = needle.toLowerCase();
|
||||
for (WorldTime time : values())
|
||||
{
|
||||
if (time.aliases != null && time.aliases.contains(needle))
|
||||
{
|
||||
return time;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package me.totalfreedom.totalfreedommod.world;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.World;
|
||||
|
||||
public enum WorldWeather
|
||||
{
|
||||
OFF("off"),
|
||||
RAIN("rain"),
|
||||
STORM("storm,thunderstorm");
|
||||
//
|
||||
private final List<String> aliases;
|
||||
|
||||
private WorldWeather(String aliases)
|
||||
{
|
||||
this.aliases = Arrays.asList(StringUtils.split(aliases, ","));
|
||||
}
|
||||
|
||||
public void setWorldToWeather(World world)
|
||||
{
|
||||
world.setStorm(this == RAIN || this == STORM);
|
||||
world.setWeatherDuration(this == RAIN || this == STORM ? 20 * 60 * 5 : 0);
|
||||
|
||||
world.setThundering(this == STORM);
|
||||
world.setThunderDuration(this == STORM ? 20 * 60 * 5 : 0);
|
||||
}
|
||||
|
||||
public static WorldWeather getByAlias(String needle)
|
||||
{
|
||||
needle = needle.toLowerCase();
|
||||
for (WorldWeather mode : values())
|
||||
{
|
||||
if (mode.aliases.contains(needle))
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user