diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/location')
5 files changed, 38 insertions, 47 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java index 93c0d8c..a616297 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -28,9 +28,14 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetExitLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.EXIT, vector -> { + LocationUtils.setLocation(sender, Locations.EXIT, args[0], map -> { + addToConfig("exit.x", sender.getLocation().getBlockX()); + addToConfig("exit.y", sender.getLocation().getBlockY()); + addToConfig("exit.z", sender.getLocation().getBlockZ()); + addToConfig("exit.world", sender.getLocation().getWorld().getName()); + exitPosition = sender.getLocation(); exitWorld = sender.getLocation().getWorld().getName(); - exitPosition = vector; + saveConfig(); }); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java index eb228f9..4eb5462 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -29,9 +29,8 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetLobbyLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.LOBBY, vector -> { - lobbyWorld = sender.getLocation().getWorld().getName(); - lobbyPosition = vector; + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); }); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java index c6c3ccb..59bec64 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java @@ -10,9 +10,8 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*; public class SetSeekerLobbyLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.SEEKER, vector -> { - seekerLobbyWorld = sender.getLocation().getWorld().getName(); - seekerLobbyPosition = vector; + LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { + map.setSeekerLobby(sender.getLocation()); }); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java index 5ecfb8d..12ac232 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -19,11 +19,11 @@ package net.tylermurphy.hideAndSeek.command.location; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.ICommand; import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils; import net.tylermurphy.hideAndSeek.command.location.util.Locations; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; @@ -31,19 +31,19 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetSpawnLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.GAME, vector -> { - if (worldBorderEnabled && vector.distance(worldBorderPosition) > 100) { + LocationUtils.setLocation(sender, Locations.GAME, args[0], map -> { + + if (map.isWorldBorderEnabled() && + new Vector(sender.getLocation().getX(), 0, sender.getLocation().getZ()).distance(map.getWorldBorderPos()) > 100) { sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); throw new RuntimeException("World border not enabled or not in valid position!"); } - if (!sender.getLocation().getWorld().getName().equals(spawnWorld)) { - Main.getInstance().getGame().getWorldLoader().unloadMap(); - Main.getInstance().getGame().getWorldLoader().setNewMap(sender.getLocation().getWorld().getName()); - } + map.setSpawn(sender.getLocation()); - spawnWorld = sender.getLocation().getWorld().getName(); - spawnPosition = vector; + if (!sender.getLocation().getWorld().getName().equals(map.getSpawn().getWorld().getName()) && mapSaveEnabled) { + map.getWorldLoader().unloadMap(); + } }); } @@ -52,7 +52,7 @@ public class SetSpawnLocation implements ICommand { } public String getUsage() { - return ""; + return "<map>"; } public String getDescription() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java index 50d1776..2655805 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java @@ -1,12 +1,11 @@ package net.tylermurphy.hideAndSeek.command.location.util; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Map; +import net.tylermurphy.hideAndSeek.configuration.Maps; import net.tylermurphy.hideAndSeek.game.util.Status; -import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; @@ -18,42 +17,31 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message; */ public class LocationUtils { - /** - * Provides a vector for a player - * @param player the player to create the vector for - * @return the vector - */ - private static @Nullable Vector vector(Player player) { + public static void setLocation(@NotNull Player player, @NotNull Locations place, String mapName, @NotNull Consumer<Map> consumer) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return null; + return; } if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); - return null; + return; } - Location loc = player.getLocation(); - return new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); - } - - public static void setLocation(Player player, Locations place, @Nullable Consumer<Vector> consumer) { - Vector vec = vector(player); - - World world = player.getLocation().getWorld(); - if(world == null) { - throw new RuntimeException("Unable to get world: " + spawnWorld); + Map map = null; + if(mapName != null) { + map = Maps.getMap(mapName); + if (map == null) { + player.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } } - consumer.accept(vec); - + consumer.accept(map); + if(map != null) + Maps.setMap(mapName, map); player.sendMessage(messagePrefix + message(place.message())); - addToConfig(place.path("x"), vec.getX()); - addToConfig(place.path("y"), vec.getY()); - addToConfig(place.path("z"), vec.getZ()); - addToConfig(place.path("world"), player.getLocation().getWorld().getName()); - saveConfig(); } }
\ No newline at end of file |