diff options
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/location')
5 files changed, 66 insertions, 6 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 a616297..1bb1d6f 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java @@ -22,13 +22,18 @@ 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 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.Config.*; public class SetExitLocation implements ICommand { public void execute(Player sender, String[] args) { - LocationUtils.setLocation(sender, Locations.EXIT, args[0], map -> { + LocationUtils.setLocation(sender, Locations.EXIT, null, map -> { addToConfig("exit.x", sender.getLocation().getBlockX()); addToConfig("exit.y", sender.getLocation().getBlockY()); addToConfig("exit.z", sender.getLocation().getBlockZ()); @@ -51,4 +56,8 @@ public class SetExitLocation implements ICommand { return "Sets hide and seeks exit location to current position and world"; } + public List<String> autoComplete(String parameter) { + return null; + } + } 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 4eb5462..84e1109 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java @@ -22,8 +22,12 @@ 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 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.Config.*; public class SetLobbyLocation implements ICommand { @@ -39,11 +43,18 @@ public class SetLobbyLocation implements ICommand { } public String getUsage() { - return ""; + 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/location/SetSeekerLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java index 59bec64..c6d9f93 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java @@ -3,14 +3,24 @@ 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 net.tylermurphy.hideAndSeek.configuration.Maps; import org.bukkit.entity.Player; -import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import java.util.List; +import java.util.stream.Collectors; + +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; public class SetSeekerLobbyLocation implements ICommand { 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()); }); } @@ -20,11 +30,18 @@ public class SetSeekerLobbyLocation implements ICommand { } public String getUsage() { - return ""; + 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/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java index 12ac232..50932d6 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java @@ -22,9 +22,14 @@ 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 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; @@ -41,7 +46,12 @@ public class SetSpawnLocation implements ICommand { map.setSpawn(sender.getLocation()); - if (!sender.getLocation().getWorld().getName().equals(map.getSpawn().getWorld().getName()) && mapSaveEnabled) { + 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(); } }); @@ -59,4 +69,11 @@ public class SetSpawnLocation implements ICommand { 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; + } + } 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 2655805..69d7c26 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 @@ -38,7 +38,13 @@ public class LocationUtils { } } - consumer.accept(map); + try { + consumer.accept(map); + } catch (Exception e) { + player.sendMessage(errorPrefix + e.getMessage()); + return; + } + if(map != null) Maps.setMap(mapName, map); player.sendMessage(messagePrefix + message(place.message())); |