Added radius claim
This commit is contained in:
@ -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>();
|
||||
|
Reference in New Issue
Block a user