diff --git a/src/com/massivecraft/factions/FLocation.java b/src/com/massivecraft/factions/FLocation.java index 2e1ba5eb..b9c481a5 100644 --- a/src/com/massivecraft/factions/FLocation.java +++ b/src/com/massivecraft/factions/FLocation.java @@ -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) { this.worldName = worldName; @@ -103,10 +112,44 @@ 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 getCircle(double radius) + { + Set ret = new LinkedHashSet(); + 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 getArea(FLocation from, FLocation to) { HashSet ret = new HashSet(); diff --git a/src/com/massivecraft/factions/cmd/CmdClaim.java b/src/com/massivecraft/factions/cmd/CmdClaim.java index 4d4cd9ce..aeb18086 100644 --- a/src/com/massivecraft/factions/cmd/CmdClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdClaim.java @@ -1,6 +1,11 @@ package com.massivecraft.factions.cmd; +import java.util.Set; + +import org.bukkit.Location; + import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FLocation; import com.massivecraft.factions.struct.Permission; public class CmdClaim extends FCommand @@ -13,6 +18,7 @@ public class CmdClaim extends FCommand //this.requiredArgs.add(""); this.optionalArgs.put("faction", "your"); + this.optionalArgs.put("radius", "1"); this.permission = Permission.CLAIM.node; this.disableOnLock = true; @@ -28,8 +34,23 @@ public class CmdClaim extends FCommand @Override public void perform() { + // Read and validate input Faction forFaction = this.argAsFaction(0, myFaction); - fme.attemptClaim(forFaction, me.getLocation(), true); + double radius = this.argAsDouble(1, 1d); + radius -= 0.5; + if (radius <= 0) + { + msg("That radius is to small."); + return; + } + + // Get the FLocations + Set flocs = new FLocation(me).getCircle(radius); + p.log(flocs); + for (FLocation floc : flocs) + { + fme.attemptClaim(forFaction, new Location(floc.getWorld(), floc.getX()*16, 1, floc.getZ()*16), true); + } } }