diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2022-11-20 23:39:55 -0500 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2022-11-20 23:39:55 -0500 |
commit | 5615fa7f325bb45762d13a704a9ffddda3efbfbb (patch) | |
tree | d75d721bc4f0098d7fe661197bd40a6be41654bb /src/main/java/net/tylermurphy/hideAndSeek/util | |
parent | 1.7.0 beta 4 (diff) | |
download | kenshinshideandseek-5615fa7f325bb45762d13a704a9ffddda3efbfbb.tar.gz kenshinshideandseek-5615fa7f325bb45762d13a704a9ffddda3efbfbb.tar.bz2 kenshinshideandseek-5615fa7f325bb45762d13a704a9ffddda3efbfbb.zip |
1.7.0 beta 5
Diffstat (limited to '')
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/util/Location.java | 111 | ||||
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java | 27 |
2 files changed, 138 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java new file mode 100644 index 0000000..2abdb9b --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Location.java @@ -0,0 +1,111 @@ +package net.tylermurphy.hideAndSeek.util; + +import net.tylermurphy.hideAndSeek.Main; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public class Location { + + private final String world; + private final double x; + private final double y; + private final double z; + + public static Location getDefault() { + return new Location( + "", + 0.0, + 0.0, + 0.0 + ); + } + + public static Location from(Player player) { + org.bukkit.Location location = player.getLocation(); + return new Location( + player.getWorld().getName(), + location.getX(), + location.getY(), + location.getZ() + ); + } + + public Location(@NotNull String world, double x, double y, double z) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + } + + public World load() { + World bukkitWorld = Bukkit.getWorld(world); + if(bukkitWorld != null) return bukkitWorld; + Bukkit.getServer().createWorld(new WorldCreator(world)); + return Bukkit.getWorld(world); + } + + private org.bukkit.Location toBukkit() { + return new org.bukkit.Location( + Bukkit.getWorld(world), + x, + y, + z + ); + } + + public void teleport(Player player) { + if(!exists()) return; + if(load() == null) return; + player.teleport(toBukkit()); + } + + public Location changeWorld(String world) { + return new Location( + world, + x, + y, + z + ); + } + + public String getWorld() { + return world; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + + public int getBlockX() { + return (int)x; + } + + public int getBlockY() { + return (int)y; + } + + public int getBlockZ() { + return (int)z; + } + + public boolean exists() { + if(world.equals("")) return false; + String path = Main.getInstance().getWorldContainer()+File.separator+world; + File destination = new File(path); + return destination.isDirectory(); + } + +} diff --git a/src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java b/src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java new file mode 100644 index 0000000..5a40ff8 --- /dev/null +++ b/src/main/java/net/tylermurphy/hideAndSeek/util/Tuple.java @@ -0,0 +1,27 @@ +package net.tylermurphy.hideAndSeek.util; + +public class Tuple<L, C, R> { + + private final L left; + private final C center; + private final R right; + + public Tuple(L left, C center, R right) { + this.left = left; + this.center = center; + this.right = right; + } + + public L getLeft() { + return left; + } + + public C getCenter() { + return center; + } + + public R getRight() { + return right; + } + +} |