summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/command/map/set
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2023-02-05 19:02:59 +0000
committertylermurphy534 <tylermurphy534@gmail.com>2023-02-05 19:02:59 +0000
commit8fdd3461c14a70dd69b34ba7bb44130e3f3a8ef0 (patch)
treeb82610c3a320bdcb8dd45197f7db309d7a3a7aa3 /src/main/java/net/tylermurphy/hideAndSeek/command/map/set
parentUpdate 'README.md' (diff)
parent1.7.0 rc3 (diff)
downloadkenshinshideandseek-8fdd3461c14a70dd69b34ba7bb44130e3f3a8ef0.tar.gz
kenshinshideandseek-8fdd3461c14a70dd69b34ba7bb44130e3f3a8ef0.tar.bz2
kenshinshideandseek-8fdd3461c14a70dd69b34ba7bb44130e3f3a8ef0.zip
Merge pull request '1.7.0 - Multi Map Support' (#4) from dev into main
Reviewed-on: https://g.tylerm.dev/tylermurphy534/KenshinsHideAndSeek/pulls/4
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/map/set')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java94
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java113
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java41
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java58
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java69
5 files changed, 375 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java
new file mode 100644
index 0000000..64bf5d4
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Border.java
@@ -0,0 +1,94 @@
+package net.tylermurphy.hideAndSeek.command.map.set;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+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 org.jetbrains.annotations.NotNull;
+
+import java.util.Collections;
+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 Border implements ICommand {
+
+ 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.getSpawn().isNotSetup()) {
+ sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
+ return;
+ }
+ if (args.length < 4) {
+ map.setWorldBorderData(0, 0, 0, 0, 0);
+ addToConfig("worldBorder.enabled",false);
+ saveConfig();
+ sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE"));
+ Main.getInstance().getGame().getCurrentMap().getWorldBorder().resetWorldBorder();
+ return;
+ }
+ int num,delay,change;
+ try { num = Integer.parseInt(args[1]); } catch (Exception e) {
+ sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
+ return;
+ }
+ try { delay = Integer.parseInt(args[2]); } catch (Exception e) {
+ sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[1]));
+ return;
+ }
+ try { change = Integer.parseInt(args[3]); } catch (Exception e) {
+ sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2]));
+ return;
+ }
+ if (num < 100) {
+ sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE"));
+ return;
+ }
+ if (change < 1) {
+ sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE"));
+ return;
+ }
+ map.setWorldBorderData(
+ sender.getLocation().getBlockX(),
+ sender.getLocation().getBlockZ(),
+ num,
+ delay,
+ change
+ );
+ Maps.setMap(map.getName(), map);
+ sender.sendMessage(messagePrefix + 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(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
+ }
+ return Collections.singletonList(parameter);
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java
new file mode 100644
index 0000000..3d1f036
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Bounds.java
@@ -0,0 +1,113 @@
+package net.tylermurphy.hideAndSeek.command.map.set;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.configuration.Map;
+import net.tylermurphy.hideAndSeek.configuration.Maps;
+import net.tylermurphy.hideAndSeek.game.util.Status;
+import net.tylermurphy.hideAndSeek.util.Location;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+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 Bounds implements ICommand {
+
+ 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.getSpawn().isNotSetup()) {
+ sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
+ return;
+ }
+ if (map.getSeekerLobby().isNotSetup()) {
+ sender.sendMessage(errorPrefix + message("ERROR_GAME_SEEKER_SPAWN"));
+ return;
+ }
+ if (!sender.getWorld().getName().equals(map.getSpawnName())) {
+ sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD"));
+ return;
+ }
+ if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) {
+ sender.sendMessage(errorPrefix + 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(warningPrefix + message("WARN_SPAWN_RESET"));
+ }
+ }
+ if(!map.getSeekerLobby().isNotSetup()) {
+ if(map.getSeekerLobby().isNotInBounds(bxs, bxl, bzs, bzl)) {
+ map.setSeekerLobby(Location.getDefault());
+ sender.sendMessage(warningPrefix + message("WARN_SEEKER_SPAWN_RESET"));
+ }
+ }
+ }
+ Maps.setMap(map.getName(), map);
+ sender.sendMessage(messagePrefix + 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(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
+ }
+ return null;
+ }
+
+}
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..6690ae9
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Lobby.java
@@ -0,0 +1,41 @@
+package net.tylermurphy.hideAndSeek.command.map.set;
+
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
+import net.tylermurphy.hideAndSeek.command.location.Locations;
+import net.tylermurphy.hideAndSeek.configuration.Maps;
+import net.tylermurphy.hideAndSeek.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(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..b6c5cf0
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/SeekerLobby.java
@@ -0,0 +1,58 @@
+package net.tylermurphy.hideAndSeek.command.map.set;
+
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
+import net.tylermurphy.hideAndSeek.command.location.Locations;
+import net.tylermurphy.hideAndSeek.configuration.Maps;
+import net.tylermurphy.hideAndSeek.util.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;;
+import java.util.stream.Collectors;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.warningPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
+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(message("GAME_SPAWN_NEEDED").toString());
+ }
+ if(!map.getSpawnName().equals(sender.getLocation().getWorld().getName())) {
+ throw new RuntimeException(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(warningPrefix + 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(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..0baf55e
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/map/set/Spawn.java
@@ -0,0 +1,69 @@
+package net.tylermurphy.hideAndSeek.command.map.set;
+
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.command.location.LocationUtils;
+import net.tylermurphy.hideAndSeek.command.location.Locations;
+import net.tylermurphy.hideAndSeek.configuration.Maps;
+import net.tylermurphy.hideAndSeek.util.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+
+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 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(errorPrefix + 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(warningPrefix + message("WARN_MAP_BOUNDS"));
+ }
+ }
+
+ if(map.getSeekerLobby().getWorld() != null && !map.getSeekerLobby().getWorld().equals(sender.getLocation().getWorld().getName())) {
+ sender.sendMessage(warningPrefix + message("SEEKER_LOBBY_SPAWN_RESET"));
+ map.setSeekerLobby(Location.getDefault());
+ }
+
+ 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 the maps game spawn location";
+ }
+
+ public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
+ if(parameter.equals("map")) {
+ return Maps.getAllMaps().stream().map(net.tylermurphy.hideAndSeek.configuration.Map::getName).collect(Collectors.toList());
+ }
+ return null;
+ }
+
+}