diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/map')
13 files changed, 393 insertions, 42 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java index 55b4267..03c2a95 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/AddMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Add.java @@ -14,7 +14,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class AddMap extends Command { +public class Add extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java new file mode 100644 index 0000000..2ec0525 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Debug.java @@ -0,0 +1,130 @@ +package net.tylermurphy.hideAndSeek.command.map; + +import com.cryptomorin.xseries.XMaterial; +import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import net.tylermurphy.hideAndSeek.game.PlayerLoader; +import net.tylermurphy.hideAndSeek.game.util.Status; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Debug extends Command { + + private static final Map<Player, Map<Integer, Consumer<Player>>> debugMenuFunctions = new HashMap<>(); + + public void execute(Player sender, String[] args) { + net.tylermurphy.hideAndSeek.configuration.Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(errorPrefix + message("INVALID_MAP")); + return; + } + Inventory debugMenu = createMenu(map, sender); + sender.openInventory(debugMenu); + } + + private Inventory createMenu(net.tylermurphy.hideAndSeek.configuration.Map map, Player sender){ + Map<Integer, Consumer<Player>> functions = new HashMap<>(); + Inventory debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu"); + debugMenu.setItem(0, createOption(functions, 0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addHider(player); + PlayerLoader.loadHider(player, map); + if(Main.getInstance().getGame().getStatus() != Status.STARTING) + PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); + })); + debugMenu.setItem(1, createOption(functions, 1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addSeeker(player); + PlayerLoader.loadSeeker(player, map); + if(Main.getInstance().getGame().getStatus() != Status.STARTING) + PlayerLoader.resetPlayer(player, Main.getInstance().getBoard()); + })); + debugMenu.setItem(2, createOption(functions, 2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + Main.getInstance().getBoard().addSpectator(player); + PlayerLoader.loadSpectator(player, map); + })); + debugMenu.setItem(3, createOption(functions, 3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> { + Main.getInstance().getBoard().remove(player); + PlayerLoader.unloadPlayer(player); + player.teleport(exitPosition); + })); + debugMenu.setItem(4, createOption(functions, 4, XMaterial.BARRIER.parseMaterial(), "&cDie In Game", 2, player -> { + if((Main.getInstance().getBoard().isSeeker(player) || Main.getInstance().getBoard().isHider(player)) && Main.getInstance().getGame().getStatus() == Status.PLAYING){ + player.setHealth(0.1); + } + })); + debugMenu.setItem(6, createOption(functions, 6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> { + if(mapSaveEnabled) { + if(map.getGameSpawn().getWorld() == null) map.getWorldLoader().loadMap(); + } + player.teleport(map.getGameSpawn()); + })); + debugMenu.setItem(7, createOption(functions, 7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> { + player.teleport(map.getLobby()); + })); + debugMenu.setItem(8, createOption(functions, 8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> player.teleport(exitPosition))); + debugMenu.setItem(9, createOption(functions, 9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, player -> { + PlayerLoader.openBlockHuntPicker(player, map); + })); + debugMenu.setItem(10, createOption(functions, 10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> Main.getInstance().getDisguiser().reveal(player))); + debugMenuFunctions.put(sender, functions); + return debugMenu; + } + + private ItemStack createOption(Map<Integer, Consumer<Player>> functions, int slow, Material material, String name, int amount, Consumer<Player> callback){ + ItemStack temp = new ItemStack(material, amount); + ItemMeta meta = temp.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name)); + temp.setItemMeta(meta); + functions.put(slow, callback); + return temp; + } + + public static void handleOption(Player player, int slotId){ + Main.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> { + Consumer<Player> callback = debugMenuFunctions.get(player).get(slotId); + if(callback != null) callback.accept(player); + }, 0); + } + + public String getLabel() { + return "debug"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Run debug commands"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java index 2df5824..8e74922 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/GoTo.java @@ -1,48 +1,42 @@ package net.tylermurphy.hideAndSeek.command.map; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; -import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; +import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetMap extends Command { +public class GoTo extends Command { public void execute(Player sender, String[] args) { - - if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { - sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); - return; - } - Map map = Maps.getMap(args[0]); if(map == null) { sender.sendMessage(errorPrefix + message("INVALID_MAP")); return; } - - if(map.isNotSetup()){ - sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP")); - return; - } - - if (!Main.getInstance().getBoard().contains(sender)) { - sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); + if (map.isNotSetup()) { + sender.sendMessage(errorPrefix + message("MAP_NOT_SETUP").addAmount(map.getName())); return; } - - Main.getInstance().getGame().setCurrentMap(map); - for(Player player : Main.getInstance().getBoard().getPlayers()) { - player.teleport(map.getLobby()); + switch (args[1].toLowerCase()) { + case "spawn": + sender.teleport(map.getSpawn()); break; + case "lobby": + sender.teleport(map.getLobby()); break; + case "seekerlobby": + sender.teleport(map.getSeekerLobby()); break; + case "exit": + sender.teleport(exitPosition); break; + default: + sender.sendMessage(errorPrefix + message("COMMAND_INVALID_ARG").addAmount(args[1].toLowerCase())); } - } public String getLabel() { @@ -50,18 +44,20 @@ public class SetMap extends Command { } public String getUsage() { - return "<map>"; + return "<map> <spawn>"; } public String getDescription() { - return "Set the current lobby to another map"; + return "Get the commands for the plugin"; } public List<String> autoComplete(String parameter) { if(parameter != null && parameter.equals("map")) { - return Maps.getAllMaps().stream().filter(map -> !map.isNotSetup()).map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } else if(parameter != null && parameter.equals("spawn")) { + return Arrays.asList("spawn","lobby","seekerlobby","exit"); } return null; } -}
\ No newline at end of file +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java index 79490a7..635c011 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/ListMaps.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/List.java @@ -7,13 +7,12 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.Collection; -import java.util.List; import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class ListMaps extends Command { +public class List extends Command { public void execute(Player sender, String[] args) { Collection<Map> maps = Maps.getAllMaps(); @@ -40,7 +39,7 @@ public class ListMaps extends Command { return "List all maps in the plugin"; } - public List<String> autoComplete(String parameter) { + public java.util.List<String> autoComplete(String parameter) { return null; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java index 216cca9..45dec99 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/RemoveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Remove.java @@ -14,7 +14,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix; import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class RemoveMap extends Command { +public class Remove extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java index f3eb4d7..b93250f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SaveMap.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Save.java @@ -34,7 +34,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SaveMap extends Command { +public class Save extends Command { public static boolean runningBackup = false; @@ -60,7 +60,8 @@ public class SaveMap extends Command { sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); World world = map.getSpawn().getWorld(); if (world == null) { - throw new RuntimeException("Unable to get spawn world"); + sender.sendMessage(warningPrefix + message("MAPSAVE_FAIL_WORLD")); + return; } world.save(); BukkitRunnable runnable = new BukkitRunnable() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java index 46b41f7..29442c1 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/Setup.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/Status.java @@ -19,20 +19,18 @@ package net.tylermurphy.hideAndSeek.command.map; -import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; import net.tylermurphy.hideAndSeek.configuration.Map; import net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; -import java.io.File; import java.util.List; import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class Setup extends Command { +public class Status extends Command { public void execute(Player sender, String[] args) { @@ -76,7 +74,7 @@ public class Setup extends Command { } public String getLabel() { - return "setup"; + return "status"; } public String getUsage() { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java new file mode 100644 index 0000000..9d47390 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/blockhunt/Enabled.java @@ -0,0 +1,43 @@ +package net.tylermurphy.hideAndSeek.command.map.blockhunt; + +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class Enabled extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "enabled"; + } + + public String getUsage() { + return "<map> <bool>"; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + if(parameter != null && parameter.equals("bool")) { + return Arrays.asList("true", "false"); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java index 8362e02..92339b4 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBorder.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java @@ -17,7 +17,7 @@ * */ -package net.tylermurphy.hideAndSeek.command.map; +package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; @@ -33,7 +33,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetBorder extends Command { +public class Border extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { @@ -86,7 +86,7 @@ public class SetBorder extends Command { change ); Maps.setMap(map.getName(), map); - sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); + sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay).addAmount(change)); map.getWorldBorder().resetWorldBorder(); } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java index 92bf5a4..9896389 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/map/SetBounds.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java @@ -17,7 +17,7 @@ * */ -package net.tylermurphy.hideAndSeek.command.map; +package net.tylermurphy.hideAndSeek.command.map.set; import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.command.util.Command; @@ -32,7 +32,7 @@ import java.util.stream.Collectors; import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.message; -public class SetBounds extends Command { +public class Bounds extends Command { public void execute(Player sender, String[] args) { if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java new file mode 100644 index 0000000..c691787 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java @@ -0,0 +1,58 @@ +/* + * 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.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +public class Lobby extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "lobby"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Sets hide and seeks lobby location to current position"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java new file mode 100644 index 0000000..2521f19 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java @@ -0,0 +1,47 @@ +package net.tylermurphy.hideAndSeek.command.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class SeekerLobby extends Command { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { + if(map.isSpawnNotSetup()) { + throw new RuntimeException(message("GAME_SPAWN_NEEDED").toString()); + } + if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) { + throw new RuntimeException(message("SEEKER_LOBBY_INVALID").toString()); + } + map.setSeekerLobby(sender.getLocation()); + }); + } + + public String getLabel() { + return "seekerlobby"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Sets hide and seeks seeker lobby location to current position"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java new file mode 100644 index 0000000..3e8f77e --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java @@ -0,0 +1,79 @@ +/* + * 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.map.set; + +import net.tylermurphy.hideAndSeek.command.util.Command; +import net.tylermurphy.hideAndSeek.command.location.LocationUtils; +import net.tylermurphy.hideAndSeek.command.location.Locations; +import net.tylermurphy.hideAndSeek.configuration.Maps; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; + +public class Spawn extends Command { + + public void execute(Player sender, String[] args) { + 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!"); + } + + map.setSpawn(sender.getLocation()); + + if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().getName().equals(sender.getLocation().getWorld().getName())) { + sender.sendMessage(message("SEEKER_LOBBY_SPAWN_RESET").toString()); + map.setSeekerLobby(new Location(null, 0, 0, 0)); + } + + if (!sender.getLocation().getWorld().getName().equals(map.getSpawnName()) && mapSaveEnabled) { + map.getWorldLoader().unloadMap(); + } + }); + } + + public String getLabel() { + return "spawn"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Sets hide and seeks spawn location to current position"; + } + + public List<String> autoComplete(String parameter) { + if(parameter != null && parameter.equals("map")) { + return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList()); + } + return null; + } + +} |