From e364e973c7625001e2071e9da9028a7eea658a4e Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Mon, 27 Dec 2010 02:11:52 +0000 Subject: [PATCH] Added Location By: Dinnerbone --- paper-api/src/org/bukkit/Location.java | 124 +++++++++++++++++++++++++ paper-api/src/org/bukkit/Player.java | 14 +++ paper-api/src/org/bukkit/Server.java | 7 ++ 3 files changed, 145 insertions(+) create mode 100644 paper-api/src/org/bukkit/Location.java diff --git a/paper-api/src/org/bukkit/Location.java b/paper-api/src/org/bukkit/Location.java new file mode 100644 index 0000000000..4da77ad18a --- /dev/null +++ b/paper-api/src/org/bukkit/Location.java @@ -0,0 +1,124 @@ + +package org.bukkit; + +/** + * Represents a 3-dimensional position in a world + */ +public class Location { + private World world; + private double x; + private double y; + private double z; + + public Location(final World world, final double x, final double y, final double z) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Sets the world that this location resides in + * + * @param world New world that this location resides in + */ + public void setWorld(World world) { + this.world = world; + } + + /** + * Gets the world that this location resides in + * + * @return World that contains this location + */ + public World getWorld() { + return world; + } + + /** + * Sets the x-coordinate of this location + * + * @param x X-coordinate + */ + public void setX(double x) { + this.x = x; + } + + /** + * Gets the x-coordinate of this location + * + * @return x-coordinate + */ + public double getX() { + return x; + } + + /** + * Sets the y-coordinate of this location + * + * @param y y-coordinate + */ + public void setY(double y) { + this.y = y; + } + + /** + * Gets the y-coordinate of this location + * + * @return y-coordinate + */ + public double getY() { + return y; + } + + /** + * Sets the z-coordinate of this location + * + * @param z z-coordinate + */ + public void setZ(double z) { + this.z = z; + } + + /** + * Gets the z-coordinate of this location + * + * @return z-coordinate + */ + public double getZ() { + return z; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Location other = (Location) obj; + if (this.world != other.world && (this.world == null || !this.world.equals(other.world))) { + return false; + } + if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) { + return false; + } + if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) { + return false; + } + if (Double.doubleToLongBits(this.z) != Double.doubleToLongBits(other.z)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 23 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32)); + hash = 23 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32)); + hash = 23 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32)); + return hash; + } +} diff --git a/paper-api/src/org/bukkit/Player.java b/paper-api/src/org/bukkit/Player.java index 3d14384998..f12efa0837 100644 --- a/paper-api/src/org/bukkit/Player.java +++ b/paper-api/src/org/bukkit/Player.java @@ -19,4 +19,18 @@ public interface Player { * @return true if they are online */ public boolean isOnline(); + + /** + * Gets the players current position in the world + * + * @return Location of this player + */ + public Location getLocation(); + + /** + * Gets the current world this player is on + * + * @return World + */ + public World getWorld(); } diff --git a/paper-api/src/org/bukkit/Server.java b/paper-api/src/org/bukkit/Server.java index 2c2fae84e0..1019423f6c 100644 --- a/paper-api/src/org/bukkit/Server.java +++ b/paper-api/src/org/bukkit/Server.java @@ -34,4 +34,11 @@ public interface Server { * @return PluginManager for this Server instance */ public PluginManager getPluginManager(); + + /** + * Gets a list of all worlds on this server + * + * @return An array of worlds + */ + public World[] getWorlds(); }