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; package com.massivecraft.factions;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -64,6 +68,11 @@ public class FLocation
{ {
return worldName; return worldName;
} }
public World getWorld()
{
return Bukkit.getWorld(worldName);
}
public void setWorldName(String worldName) public void setWorldName(String worldName)
{ {
@ -104,10 +113,46 @@ public class FLocation
// Misc Geometry // 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); 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) public static HashSet<FLocation> getArea(FLocation from, FLocation to)
{ {
HashSet<FLocation> ret = new HashSet<FLocation>(); HashSet<FLocation> ret = new HashSet<FLocation>();

View File

@ -1,5 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import java.util.Set;
import org.bukkit.Location;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
@ -13,6 +18,7 @@ public class CmdClaim extends FCommand
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("faction", "your");
this.optionalArgs.put("radius", "1");
this.permission = Permission.CLAIM.node; this.permission = Permission.CLAIM.node;
this.disableOnLock = true; this.disableOnLock = true;
@ -28,8 +34,23 @@ public class CmdClaim extends FCommand
@Override @Override
public void perform() public void perform()
{ {
// Read and validate input
Faction forFaction = this.argAsFaction(0, myFaction); 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("<b>That radius is to small.");
return;
}
// Get the FLocations
Set<FLocation> 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);
}
} }
} }