diff options
Diffstat (limited to 'src/main/java/dev/tylerm/khs/command/map/set')
5 files changed, 363 insertions, 0 deletions
diff --git a/src/main/java/dev/tylerm/khs/command/map/set/Border.java b/src/main/java/dev/tylerm/khs/command/map/set/Border.java new file mode 100644 index 0000000..7ef3bf9 --- /dev/null +++ b/src/main/java/dev/tylerm/khs/command/map/set/Border.java @@ -0,0 +1,86 @@ +package dev.tylerm.khs.command.map.set; + +import dev.tylerm.khs.Main; +import dev.tylerm.khs.command.util.ICommand; +import dev.tylerm.khs.configuration.Config; +import dev.tylerm.khs.configuration.Localization; +import dev.tylerm.khs.configuration.Map; +import dev.tylerm.khs.configuration.Maps; +import dev.tylerm.khs.game.util.Status; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class Border implements ICommand { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(Config.errorPrefix + Localization.message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(Config.errorPrefix + Localization.message("INVALID_MAP")); + return; + } + if (map.getSpawn().isNotSetup()) { + sender.sendMessage(Config.errorPrefix + Localization.message("ERROR_GAME_SPAWN")); + return; + } + + int num,delay,change; + try { num = Integer.parseInt(args[1]); } catch (Exception e) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_INVALID_INPUT").addAmount(args[0])); + return; + } + try { delay = Integer.parseInt(args[2]); } catch (Exception e) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_INVALID_INPUT").addAmount(args[1])); + return; + } + try { change = Integer.parseInt(args[3]); } catch (Exception e) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_INVALID_INPUT").addAmount(args[2])); + return; + } + if (num < 100) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_MIN_SIZE")); + return; + } + if (change < 1) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLDBORDER_CHANGE_SIZE")); + return; + } + map.setWorldBorderData( + sender.getLocation().getBlockX(), + sender.getLocation().getBlockZ(), + num, + delay, + change + ); + Maps.setMap(map.getName(), map); + sender.sendMessage(Config.messagePrefix + Localization.message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay).addAmount(change)); + map.getWorldBorder().resetWorldBorder(); + } + + public String getLabel() { + return "border"; + } + + public String getUsage() { + return "<map> <size> <delay> <move>"; + } + + public String getDescription() { + return "Sets a maps world border information"; + } + + public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { + return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList()); + } + return Collections.singletonList(parameter); + } + +} diff --git a/src/main/java/dev/tylerm/khs/command/map/set/Bounds.java b/src/main/java/dev/tylerm/khs/command/map/set/Bounds.java new file mode 100644 index 0000000..5fde50e --- /dev/null +++ b/src/main/java/dev/tylerm/khs/command/map/set/Bounds.java @@ -0,0 +1,112 @@ +package dev.tylerm.khs.command.map.set; + +import dev.tylerm.khs.Main; +import dev.tylerm.khs.command.util.ICommand; +import dev.tylerm.khs.configuration.Config; +import dev.tylerm.khs.configuration.Localization; +import dev.tylerm.khs.configuration.Map; +import dev.tylerm.khs.configuration.Maps; +import dev.tylerm.khs.game.util.Status; +import dev.tylerm.khs.util.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.stream.Collectors; + +public class Bounds implements ICommand { + + public void execute(Player sender, String[] args) { + if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { + sender.sendMessage(Config.errorPrefix + Localization.message("GAME_INPROGRESS")); + return; + } + Map map = Maps.getMap(args[0]); + if(map == null) { + sender.sendMessage(Config.errorPrefix + Localization.message("INVALID_MAP")); + return; + } + if (map.getSpawn().isNotSetup()) { + sender.sendMessage(Config.errorPrefix + Localization.message("ERROR_GAME_SPAWN")); + return; + } + if (map.getSeekerLobby().isNotSetup()) { + sender.sendMessage(Config.errorPrefix + Localization.message("ERROR_GAME_SEEKER_SPAWN")); + return; + } + if (!sender.getWorld().getName().equals(map.getSpawnName())) { + sender.sendMessage(Config.errorPrefix + Localization.message("BOUNDS_WRONG_WORLD")); + return; + } + if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) { + sender.sendMessage(Config.errorPrefix + Localization.message("NOT_AT_ZERO")); + return; + } + boolean first = true; + int bxs = map.getBoundsMin().getBlockX(); + int bzs = map.getBoundsMin().getBlockZ(); + int bxl = map.getBoundsMax().getBlockX(); + int bzl = map.getBoundsMax().getBlockZ(); + if (bxs != 0 && bzs != 0 && bxl != 0 && bzl != 0) { + bxs = bzs = bxl = bzl = 0; + } + if (bxl == 0) { + bxl = sender.getLocation().getBlockX(); + } else if (map.getBoundsMax().getX() < sender.getLocation().getBlockX()) { + first = false; + bxs = bxl; + bxl = sender.getLocation().getBlockX(); + } else { + first = false; + bxs = sender.getLocation().getBlockX(); + } + if (bzl == 0) { + bzl = sender.getLocation().getBlockZ(); + } else if (map.getBoundsMax().getZ() < sender.getLocation().getBlockZ()) { + first = false; + bzs = bzl; + bzl = sender.getLocation().getBlockZ(); + } else { + first = false; + bzs = sender.getLocation().getBlockZ(); + } + map.setBoundMin(bxs, bzs); + map.setBoundMax(bxl, bzl); + if(!map.isBoundsNotSetup()) { + if(!map.getSpawn().isNotSetup()) { + if(map.getSpawn().isNotInBounds(bxs, bxl, bzs, bzl)) { + map.setSpawn(Location.getDefault()); + sender.sendMessage(Config.warningPrefix + Localization.message("WARN_SPAWN_RESET")); + } + } + if(!map.getSeekerLobby().isNotSetup()) { + if(map.getSeekerLobby().isNotInBounds(bxs, bxl, bzs, bzl)) { + map.setSeekerLobby(Location.getDefault()); + sender.sendMessage(Config.warningPrefix + Localization.message("WARN_SEEKER_SPAWN_RESET")); + } + } + } + Maps.setMap(map.getName(), map); + sender.sendMessage(Config.messagePrefix + Localization.message("BOUNDS").addAmount(first ? 1 : 2)); + } + + public String getLabel() { + return "bounds"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Sets the map bounds for the game."; + } + + public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { + return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/dev/tylerm/khs/command/map/set/Lobby.java b/src/main/java/dev/tylerm/khs/command/map/set/Lobby.java new file mode 100644 index 0000000..a1c8036 --- /dev/null +++ b/src/main/java/dev/tylerm/khs/command/map/set/Lobby.java @@ -0,0 +1,42 @@ +package dev.tylerm.khs.command.map.set; + +import dev.tylerm.khs.command.location.LocationUtils; +import dev.tylerm.khs.command.location.Locations; +import dev.tylerm.khs.command.util.ICommand; +import dev.tylerm.khs.configuration.Map; +import dev.tylerm.khs.configuration.Maps; +import dev.tylerm.khs.util.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.stream.Collectors; + +public class Lobby implements ICommand { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.LOBBY, args[0], map -> { + map.setLobby(Location.from(sender)); + }); + } + + public String getLabel() { + return "lobby"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Sets the maps lobby location"; + } + + public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { + return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/dev/tylerm/khs/command/map/set/SeekerLobby.java b/src/main/java/dev/tylerm/khs/command/map/set/SeekerLobby.java new file mode 100644 index 0000000..7187ac9 --- /dev/null +++ b/src/main/java/dev/tylerm/khs/command/map/set/SeekerLobby.java @@ -0,0 +1,56 @@ +package dev.tylerm.khs.command.map.set; + +import dev.tylerm.khs.command.location.LocationUtils; +import dev.tylerm.khs.command.location.Locations; +import dev.tylerm.khs.command.util.ICommand; +import dev.tylerm.khs.configuration.*; +import dev.tylerm.khs.util.Location; +import dev.tylerm.khs.configuration.Maps; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + +import java.util.List;; +import java.util.stream.Collectors; + +public class SeekerLobby implements ICommand { + + public void execute(Player sender, String[] args) { + LocationUtils.setLocation(sender, Locations.SEEKER, args[0], map -> { + if(map.getSpawn().isNotSetup()) { + throw new RuntimeException(Localization.message("GAME_SPAWN_NEEDED").toString()); + } + if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) { + throw new RuntimeException(Localization.message("SEEKER_LOBBY_INVALID").toString()); + } + map.setSeekerLobby(Location.from(sender)); + if(!map.isBoundsNotSetup()) { + Vector boundsMin = map.getBoundsMin(); + Vector boundsMax = map.getBoundsMax(); + if(map.getSeekerLobby().isNotInBounds(boundsMin.getBlockX(), boundsMax.getBlockX(), boundsMin.getBlockZ(), boundsMax.getBlockZ())) { + sender.sendMessage(Config.warningPrefix + Localization.message("WARN_MAP_BOUNDS")); + } + } + }); + } + + public String getLabel() { + return "seekerlobby"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Sets the maps seeker lobby location"; + } + + public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { + return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList()); + } + return null; + } + +} diff --git a/src/main/java/dev/tylerm/khs/command/map/set/Spawn.java b/src/main/java/dev/tylerm/khs/command/map/set/Spawn.java new file mode 100644 index 0000000..6541fac --- /dev/null +++ b/src/main/java/dev/tylerm/khs/command/map/set/Spawn.java @@ -0,0 +1,67 @@ +package dev.tylerm.khs.command.map.set; + +import dev.tylerm.khs.command.location.LocationUtils; +import dev.tylerm.khs.command.location.Locations; +import dev.tylerm.khs.command.util.ICommand; +import dev.tylerm.khs.configuration.*; +import dev.tylerm.khs.util.Location; +import dev.tylerm.khs.configuration.Maps; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.stream.Collectors; + +public class Spawn implements ICommand { + + 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(Config.errorPrefix + Localization.message("WORLDBORDER_POSITION")); + throw new RuntimeException("World border not enabled or not in valid position!"); + } + + map.setSpawn(Location.from(sender)); + + if(!map.isBoundsNotSetup()) { + Vector boundsMin = map.getBoundsMin(); + Vector boundsMax = map.getBoundsMax(); + if(map.getSpawn().isNotInBounds(boundsMin.getBlockX(), boundsMax.getBlockX(), boundsMin.getBlockZ(), boundsMax.getBlockZ())) { + sender.sendMessage(Config.warningPrefix + Localization.message("WARN_MAP_BOUNDS")); + } + } + + if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().equals(sender.getLocation().getWorld().getName())) { + sender.sendMessage(Config.warningPrefix + Localization.message("SEEKER_LOBBY_SPAWN_RESET")); + map.setSeekerLobby(Location.getDefault()); + } + + if (!sender.getLocation().getWorld().getName().equals(map.getSpawnName()) && Config.mapSaveEnabled) { + map.getWorldLoader().unloadMap(); + } + }); + } + + public String getLabel() { + return "spawn"; + } + + public String getUsage() { + return "<map>"; + } + + public String getDescription() { + return "Sets the maps game spawn location"; + } + + public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) { + if(parameter.equals("map")) { + return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList()); + } + return null; + } + +} |