summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/command/location
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/location
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/location')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java53
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java17
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java49
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java50
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java31
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java62
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java59
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java26
8 files changed, 70 insertions, 277 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java
new file mode 100644
index 0000000..5e4afb5
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/LocationUtils.java
@@ -0,0 +1,53 @@
+package net.tylermurphy.hideAndSeek.command.location;
+
+import net.tylermurphy.hideAndSeek.Main;
+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.function.Consumer;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
+/**
+ * @author bobby29831
+ */
+public class LocationUtils {
+
+ public static void setLocation(@NotNull Player player, @NotNull Locations place, String mapName, @NotNull Consumer<Map> consumer) {
+
+ if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
+ player.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
+ return;
+ }
+
+ if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
+ player.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
+ return;
+ }
+
+ Map map = null;
+ if(mapName != null) {
+ map = Maps.getMap(mapName);
+ if (map == null) {
+ player.sendMessage(errorPrefix + message("INVALID_MAP"));
+ return;
+ }
+ }
+
+ 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()));
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java
new file mode 100644
index 0000000..c1316f8
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/Locations.java
@@ -0,0 +1,17 @@
+package net.tylermurphy.hideAndSeek.command.location;
+
+/**
+ * @author bobby29831
+ */
+public enum Locations {
+
+ GAME,
+ LOBBY,
+ EXIT,
+ SEEKER;
+
+ public String message() {
+ return this + "_SPAWN";
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java
deleted file mode 100644
index 93c0d8c..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.entity.Player;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-public class SetExitLocation implements ICommand {
-
- public void execute(Player sender, String[] args) {
- LocationUtils.setLocation(sender, Locations.EXIT, vector -> {
- exitWorld = sender.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
deleted file mode 100644
index eb228f9..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.entity.Player;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-public class SetLobbyLocation implements ICommand {
-
- public void execute(Player sender, String[] args) {
- LocationUtils.setLocation(sender, Locations.LOBBY, vector -> {
- lobbyWorld = sender.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/SetSeekerLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java
deleted file mode 100644
index c6c3ccb..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSeekerLobbyLocation.java
+++ /dev/null
@@ -1,31 +0,0 @@
-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.entity.Player;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-public class SetSeekerLobbyLocation implements ICommand {
-
- public void execute(Player sender, String[] args) {
- LocationUtils.setLocation(sender, Locations.SEEKER, vector -> {
- seekerLobbyWorld = sender.getLocation().getWorld().getName();
- seekerLobbyPosition = vector;
- });
- }
-
- public String getLabel() {
- return "setseekerlobby";
- }
-
- public String getUsage() {
- return "";
- }
-
- public String getDescription() {
- return "Sets hide and seeks seeker 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
deleted file mode 100644
index 5ecfb8d..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.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(Player sender, String[] args) {
- LocationUtils.setLocation(sender, 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 (!sender.getLocation().getWorld().getName().equals(spawnWorld)) {
- Main.getInstance().getGame().getWorldLoader().unloadMap();
- Main.getInstance().getGame().getWorldLoader().setNewMap(sender.getLocation().getWorld().getName());
- }
-
- spawnWorld = sender.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
deleted file mode 100644
index 50d1776..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package net.tylermurphy.hideAndSeek.command.location.util;
-
-import net.tylermurphy.hideAndSeek.Main;
-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;
-
-/**
- * @author bobby29831
- */
-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
deleted file mode 100644
index 35f74ea..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package net.tylermurphy.hideAndSeek.command.location.util;
-
-/**
- * @author bobby29831
- */
-public enum Locations {
-
- GAME("spawns.game"),
- LOBBY("spawns.lobby"),
- EXIT("spawns.exit"),
- SEEKER("spawns.seeker");
-
- private final String path;
- Locations(String path) {
- this.path = path;
- }
-
- public String message() {
- return this + "_SPAWN";
- }
-
- public String path(String additive) {
- return path + "." + additive;
- }
-
-} \ No newline at end of file