2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.world;
|
2013-08-12 02:02:18 +00:00
|
|
|
|
2018-07-31 07:05:28 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2020-12-25 19:46:43 +00:00
|
|
|
import java.util.Objects;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
2018-07-31 07:05:28 +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;
|
2013-08-12 02:02:18 +00:00
|
|
|
import org.bukkit.block.Block;
|
2013-08-12 15:58:28 +00:00
|
|
|
import org.bukkit.block.BlockFace;
|
2013-08-12 02:02:18 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2013-08-12 14:03:12 +00:00
|
|
|
import org.bukkit.event.player.PlayerMoveEvent;
|
2013-08-12 02:02:18 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
public final class AdminWorld extends CustomWorld
|
2013-08-12 02:02:18 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-08-13 01:33:21 +00:00
|
|
|
private static final long CACHE_CLEAR_FREQUENCY = 30L * 1000L; //30 seconds, milliseconds
|
|
|
|
private static final long TP_COOLDOWN_TIME = 500L; //0.5 seconds, milliseconds
|
2015-10-19 17:43:46 +00:00
|
|
|
private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString();
|
2013-08-13 01:33:21 +00:00
|
|
|
//
|
2016-03-02 19:28:01 +00:00
|
|
|
private final Map<Player, Long> teleportCooldown = new HashMap<>();
|
2013-08-13 01:33:21 +00:00
|
|
|
//
|
2015-10-19 17:43:46 +00:00
|
|
|
private WorldWeather weather = WorldWeather.OFF;
|
|
|
|
private WorldTime time = WorldTime.INHERIT;
|
2013-08-12 02:02:18 +00:00
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
public AdminWorld()
|
2013-08-12 02:02:18 +00:00
|
|
|
{
|
2020-12-04 00:28:53 +00:00
|
|
|
super("adminworld");
|
2013-08-12 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 00:07:14 +00:00
|
|
|
@Override
|
|
|
|
public void sendToWorld(Player player)
|
2013-08-12 02:02:18 +00:00
|
|
|
{
|
2013-08-22 00:07:14 +00:00
|
|
|
super.sendToWorld(player);
|
|
|
|
}
|
|
|
|
|
2020-12-25 19:46:43 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2013-08-22 00:07:14 +00:00
|
|
|
@Override
|
|
|
|
protected World generateWorld()
|
|
|
|
{
|
2018-07-25 05:52:49 +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
|
|
|
|
2020-12-25 19:46:43 +00:00
|
|
|
assert world != null;
|
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);
|
2019-07-17 19:35:36 +00:00
|
|
|
welcomeSignBlock.setType(Material.OAK_SIGN);
|
2018-07-31 07:01:29 +00:00
|
|
|
org.bukkit.block.Sign welcomeSign = (org.bukkit.block.Sign)welcomeSignBlock.getState();
|
2013-08-22 00:07:14 +00:00
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
org.bukkit.material.Sign signData = (org.bukkit.material.Sign)welcomeSign.getData();
|
2013-08-22 00:07:14 +00:00
|
|
|
signData.setFacingDirection(BlockFace.NORTH);
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
welcomeSign.setLine(0, ChatColor.GREEN + "AdminWorld");
|
2013-08-22 00:07:14 +00:00
|
|
|
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;
|
2013-08-12 02:02:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-12 14:03:12 +00:00
|
|
|
public boolean validateMovement(PlayerMoveEvent event)
|
2013-08-12 02:02:18 +00:00
|
|
|
{
|
2013-08-22 00:07:14 +00:00
|
|
|
World world;
|
|
|
|
try
|
2013-08-12 02:02:18 +00:00
|
|
|
{
|
2013-08-22 00:07:14 +00:00
|
|
|
world = getWorld();
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-25 19:46:43 +00:00
|
|
|
if (world == null || !Objects.equals(Objects.requireNonNull(event.getTo()).getWorld(), world))
|
2013-08-22 00:07:14 +00:00
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Player player = event.getPlayer();
|
2013-08-12 02:02:18 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
Long lastTP = teleportCooldown.get(player);
|
|
|
|
|
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
if (lastTP == null || lastTP + TP_COOLDOWN_TIME <= currentTimeMillis)
|
|
|
|
{
|
|
|
|
teleportCooldown.put(player, currentTimeMillis);
|
2020-12-04 00:28:53 +00:00
|
|
|
FLog.info(player.getName() + " attempted to access the AdminWorld.");
|
2015-11-15 23:32:04 +00:00
|
|
|
event.setTo(Bukkit.getWorlds().get(0).getSpawnLocation());
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-12 16:38:46 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public WorldWeather getWeatherMode()
|
2013-08-24 01:22:13 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
return weather;
|
2013-08-24 01:22:13 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public void setWeatherMode(final WorldWeather weatherMode)
|
2013-08-24 01:22:13 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
this.weather = weatherMode;
|
2013-08-24 01:22:13 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
weatherMode.setWorldToWeather(getWorld());
|
|
|
|
}
|
2020-12-25 19:46:43 +00:00
|
|
|
catch (Exception ignored)
|
2013-08-24 01:22:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public WorldTime getTimeOfDay()
|
2013-08-24 01:22:13 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
return time;
|
2013-08-24 01:22:13 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public void setTimeOfDay(final WorldTime timeOfDay)
|
2013-08-24 01:22:13 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
this.time = timeOfDay;
|
2013-08-24 01:22:13 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
timeOfDay.setWorldToTime(getWorld());
|
|
|
|
}
|
2020-12-25 19:46:43 +00:00
|
|
|
catch (Exception ignored)
|
2013-08-24 01:22:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|