diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2022-06-01 20:03:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-01 20:03:01 -0400 |
commit | c506030cbabe938f0afccbf3489ab72e7463e1e7 (patch) | |
tree | 0cafe99d4b314c761d2621457c4a4a824e53350e /src/main/java/net/tylermurphy/hideAndSeek/command/location/util | |
parent | move code of conduct and contributing guidelines (diff) | |
parent | Update CONTRIBUTING.md (diff) | |
download | kenshinshideandseek-c506030cbabe938f0afccbf3489ab72e7463e1e7.tar.gz kenshinshideandseek-c506030cbabe938f0afccbf3489ab72e7463e1e7.tar.bz2 kenshinshideandseek-c506030cbabe938f0afccbf3489ab72e7463e1e7.zip |
Merge pull request #68 from tylermurphy534/1.5.0
1.5.0
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/location/util')
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java | 59 | ||||
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java | 25 |
2 files changed, 84 insertions, 0 deletions
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 new file mode 100644 index 0000000..50d1776 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java @@ -0,0 +1,59 @@ +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 new file mode 100644 index 0000000..137bc69 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java @@ -0,0 +1,25 @@ +package net.tylermurphy.hideAndSeek.command.location.util; + +/** + * @author bobby29831 + */ +public enum Locations { + + GAME("spawns.game"), + LOBBY("spawns.lobby"), + EXIT("spawns.exit"); + + 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 |