Added Location

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2010-12-27 02:11:52 +00:00
parent a2d9b84796
commit e364e973c7
3 changed files with 145 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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();
}

View file

@ -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();
}