Added radius claim

This commit is contained in:
Olof Larsson
2011-11-27 22:47:40 +01:00
parent bf2ff7f0ed
commit 5db20e9625
2 changed files with 68 additions and 2 deletions

View File

@ -1,8 +1,12 @@
package com.massivecraft.factions;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
@ -64,6 +68,11 @@ public class FLocation
{
return worldName;
}
public World getWorld()
{
return Bukkit.getWorld(worldName);
}
public void setWorldName(String worldName)
{
@ -104,10 +113,46 @@ public class FLocation
// Misc Geometry
//----------------------------------------------//
public FLocation getRelative(int dx, int dz) {
public FLocation getRelative(int dx, int dz)
{
return new FLocation(this.worldName, this.x + dx, this.z + dz);
}
public double getDistanceTo(FLocation that)
{
double dx = that.x - this.x;
double dz = that.z - this.z;
return Math.sqrt(dx*dx+dz*dz);
}
//----------------------------------------------//
// Some Geometry
//----------------------------------------------//
public Set<FLocation> getCircle(double radius)
{
Set<FLocation> ret = new LinkedHashSet<FLocation>();
if (radius <= 0) return ret;
int xfrom = (int) Math.floor(this.x - radius);
int xto = (int) Math.ceil(this.x + radius);
int zfrom = (int) Math.floor(this.z - radius);
int zto = (int) Math.ceil(this.z + radius);
for (int x=xfrom; x<=xto; x++)
{
for (int z=zfrom; z<=zto; z++)
{
FLocation potential = new FLocation(this.worldName, x, z);
if (this.getDistanceTo(potential) <= radius)
{
ret.add(potential);
}
}
}
return ret;
}
public static HashSet<FLocation> getArea(FLocation from, FLocation to)
{
HashSet<FLocation> ret = new HashSet<FLocation>();