2011-04-08 15:51:07 +02:00
|
|
|
package org.mcteam.factions;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
2011-04-08 21:01:46 +02:00
|
|
|
import java.util.HashSet;
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-04-08 21:01:46 +02:00
|
|
|
import org.mcteam.factions.util.MiscUtil;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
|
|
|
public class FLocation {
|
|
|
|
|
|
|
|
private String worldName = "world";
|
2011-03-22 17:20:21 +01:00
|
|
|
private int x = 0;
|
|
|
|
private int z = 0;
|
2011-03-19 13:00:03 +01:00
|
|
|
|
|
|
|
private final static transient double cellSize = 16;
|
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// Constructors
|
|
|
|
//----------------------------------------------//
|
|
|
|
|
|
|
|
public FLocation() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
public FLocation(String worldName, int x, int z) {
|
2011-03-19 13:00:03 +01:00
|
|
|
this.worldName = worldName;
|
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FLocation(Location location) {
|
2011-03-22 17:20:21 +01:00
|
|
|
this(location.getWorld().getName(), (int) Math.floor(location.getX() / cellSize) , (int) Math.floor(location.getZ() / cellSize));
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public FLocation(Player player) {
|
|
|
|
this(player.getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
public FLocation(FPlayer fplayer) {
|
|
|
|
this(fplayer.getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public FLocation(Block block) {
|
|
|
|
this(block.getLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------//
|
|
|
|
// Getters and Setters
|
|
|
|
//----------------------------------------------//
|
|
|
|
|
|
|
|
public String getWorldName() {
|
|
|
|
return worldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWorldName(String worldName) {
|
|
|
|
this.worldName = worldName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getX() {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
public void setX(int x) {
|
2011-03-19 13:00:03 +01:00
|
|
|
this.x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getZ() {
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
public void setZ(int z) {
|
2011-03-19 13:00:03 +01:00
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getCoordString() {
|
|
|
|
return ""+x+","+z;
|
|
|
|
}
|
2011-03-23 12:45:21 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "["+this.getWorldName()+","+this.getCoordString()+"]";
|
|
|
|
}
|
2011-03-19 13:00:03 +01:00
|
|
|
|
|
|
|
//----------------------------------------------//
|
2011-04-08 21:01:46 +02:00
|
|
|
// Misc Geometry
|
2011-03-19 13:00:03 +01:00
|
|
|
//----------------------------------------------//
|
|
|
|
|
|
|
|
public FLocation getRelative(int dx, int dz) {
|
|
|
|
return new FLocation(this.worldName, this.x + dx, this.z + dz);
|
|
|
|
}
|
|
|
|
|
2011-04-08 21:01:46 +02:00
|
|
|
public static HashSet<FLocation> getArea(FLocation from, FLocation to) {
|
|
|
|
HashSet<FLocation> ret = new HashSet<FLocation>();
|
|
|
|
|
|
|
|
for (long x : MiscUtil.range(from.getX(), to.getX())) {
|
|
|
|
for (long z : MiscUtil.range(from.getZ(), to.getZ())) {
|
|
|
|
ret.add(new FLocation(from.getWorldName(), (int)x, (int)z));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
//----------------------------------------------//
|
|
|
|
// Comparison
|
|
|
|
//----------------------------------------------//
|
|
|
|
|
2011-03-23 12:00:38 +01:00
|
|
|
public int hashCode() {
|
|
|
|
int hash = 3;
|
|
|
|
hash = 19 * hash + (this.worldName != null ? this.worldName.hashCode() : 0);
|
|
|
|
hash = 19 * hash + this.x;
|
|
|
|
hash = 19 * hash + this.z;
|
|
|
|
return hash;
|
|
|
|
};
|
|
|
|
|
2011-03-19 13:00:03 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (obj == this)
|
|
|
|
return true;
|
|
|
|
if (!(obj instanceof FLocation))
|
|
|
|
return false;
|
|
|
|
|
2011-03-23 12:00:38 +01:00
|
|
|
FLocation that = (FLocation) obj;
|
|
|
|
return this.x == that.x && this.z == that.z && ( this.worldName==null ? that.worldName==null : this.worldName.equals(that.worldName) );
|
2011-03-19 13:00:03 +01:00
|
|
|
}
|
|
|
|
}
|