diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/location')
5 files changed, 257 insertions, 0 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 new file mode 100644 index 0000000..abe6f69 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -0,0 +1,53 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +package net.tylermurphy.hideAndSeek.command.location; + +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.command.CommandSender; +import org.bukkit.entity.Player; +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class SetExitLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) return; + Player player = (Player) sender; + + LocationUtils.setLocation(player, Locations.EXIT, vector -> { + exitWorld = player.getLocation().getWorld().getName(); + exitPosition = vector; + }); + } + + public String getLabel() { + return "setexit"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks exit location to current position and world"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java new file mode 100644 index 0000000..fab7076 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -0,0 +1,54 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +package net.tylermurphy.hideAndSeek.command.location; + +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.command.CommandSender; +import org.bukkit.entity.Player; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; + +public class SetLobbyLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) return; + Player player = (Player) sender; + + LocationUtils.setLocation(player, Locations.LOBBY, vector -> { + lobbyWorld = player.getLocation().getWorld().getName(); + lobbyPosition = vector; + }); + } + + public String getLabel() { + return "setlobby"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java new file mode 100644 index 0000000..d96252d --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -0,0 +1,66 @@ +/* + * This file is part of Kenshins Hide and Seek + * + * Copyright (c) 2021 Tyler Murphy. + * + * Kenshins Hide and Seek free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * he Free Software Foundation version 3. + * + * Kenshins Hide and Seek 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +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.command.CommandSender; +import org.bukkit.entity.Player; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SetSpawnLocation implements ICommand { + + public void execute(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) return; + Player player = (Player) sender; + + LocationUtils.setLocation(player, Locations.GAME, vector -> { + if (worldborderEnabled && vector.distance(worldborderPosition) > 100) { + sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); + throw new RuntimeException("World border not enabled or not in valid position!"); + } + + if (!player.getLocation().getWorld().getName().equals(spawnWorld)) { + Main.getInstance().getGame().getWorldLoader().unloadMap(); + Main.getInstance().getGame().getWorldLoader().setNewMap(player.getLocation().getWorld().getName()); + } + + spawnWorld = player.getLocation().getWorld().getName(); + spawnPosition = vector; + }); + } + + public String getLabel() { + return "setspawn"; + } + + public String getUsage() { + return ""; + } + + public String getDescription() { + return "Sets hide and seeks spawn location to current position"; + } + +} 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 new file mode 100644 index 0000000..e0fc033 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java @@ -0,0 +1,57 @@ +package net.tylermurphy.hideAndSeek.command.location.util; + +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.game.Game; +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 java.util.function.Consumer; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +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) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + player.sendMessage(errorPrefix + message("GAME_INPROGRESS")); + return null; + } + + if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){ + player.sendMessage(errorPrefix + message("NOT_AT_ZERO")); + return null; + } + + 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); + } + + consumer.accept(vec); + + 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 diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java new file mode 100644 index 0000000..bde5456 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java @@ -0,0 +1,27 @@ +package net.tylermurphy.hideAndSeek.command.location.util; + +public enum Locations { + + GAME("spawns.game", "GAME_SPAWN"), + LOBBY("spawns.lobby", "LOBBY_SPAWN"), + EXIT("spawns.exit", "EXIT_SPAWN"); + + private final String path, message; + Locations(String path, String message) { + this.path = path; + this.message = message; + } + + public String message() { + return message; + } + + public String path() { + return path; + } + + public String path(String additive) { + return path + "." + additive; + } + +}
\ No newline at end of file |