Added a radius to safe claim

This commit is contained in:
Olof Larsson 2011-04-08 21:01:46 +02:00
parent b0e659e534
commit 3820b53d29
4 changed files with 66 additions and 5 deletions

View File

@ -1,8 +1,11 @@
package org.mcteam.factions; package org.mcteam.factions;
import java.util.HashSet;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.mcteam.factions.util.MiscUtil;
public class FLocation { public class FLocation {
@ -80,13 +83,25 @@ public class FLocation {
} }
//----------------------------------------------// //----------------------------------------------//
// Misc // 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 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;
}
//----------------------------------------------// //----------------------------------------------//
// Comparison // Comparison
//----------------------------------------------// //----------------------------------------------//

View File

@ -52,6 +52,7 @@ import org.mcteam.factions.gson.GsonBuilder;
import org.mcteam.factions.listeners.FactionsBlockListener; import org.mcteam.factions.listeners.FactionsBlockListener;
import org.mcteam.factions.listeners.FactionsEntityListener; import org.mcteam.factions.listeners.FactionsEntityListener;
import org.mcteam.factions.listeners.FactionsPlayerListener; import org.mcteam.factions.listeners.FactionsPlayerListener;
import org.mcteam.factions.util.MiscUtil;
import com.nijiko.permissions.PermissionHandler; import com.nijiko.permissions.PermissionHandler;
@ -94,6 +95,8 @@ public class Factions extends JavaPlugin {
log("=== INIT START ==="); log("=== INIT START ===");
long timeInitStart = System.currentTimeMillis(); long timeInitStart = System.currentTimeMillis();
log("asdfasdas"+MiscUtil.range(-1, 1));
// Add the commands // Add the commands
commands.add(new FCommandHelp()); commands.add(new FCommandHelp());
commands.add(new FCommandAdmin()); commands.add(new FCommandAdmin());

View File

@ -6,13 +6,14 @@ import org.mcteam.factions.FLocation;
import org.mcteam.factions.Faction; import org.mcteam.factions.Faction;
import org.mcteam.factions.Factions; import org.mcteam.factions.Factions;
public class FCommandSafeclaim extends FBaseCommand { public class FCommandSafeclaim extends FBaseCommand {
public FCommandSafeclaim() { public FCommandSafeclaim() {
aliases.add("safeclaim"); aliases.add("safeclaim");
aliases.add("safe"); aliases.add("safe");
optionalParameters.add("radius");
helpDescription = "Claim land for the safezone"; helpDescription = "Claim land for the safezone";
} }
@ -22,9 +23,26 @@ public class FCommandSafeclaim extends FBaseCommand {
} }
public void perform() { public void perform() {
FLocation flocation = new FLocation(me); // The current location of the player
Board.setFactionAt(Faction.getSafeZone(), flocation); FLocation playerFlocation = new FLocation(me);
sendMessage("This land is now a safe zone");
// Was a radius set?
if (parameters.size() > 0) {
int radius = Integer.parseInt(parameters.get(0));
FLocation from = playerFlocation.getRelative(radius, radius);
FLocation to = playerFlocation.getRelative(-radius, -radius);
for (FLocation locToClaim : FLocation.getArea(from, to)) {
Board.setFactionAt(Faction.getSafeZone(), locToClaim);
}
sendMessage("You claimed "+(1+radius*2)*(1+radius*2)+" chunks for the safe zone.");
} else {
Board.setFactionAt(Faction.getSafeZone(), playerFlocation);
sendMessage("This land is now a safe zone");
}
} }
} }

View File

@ -0,0 +1,25 @@
package org.mcteam.factions.util;
public class MiscUtil {
// Inclusive range
public static long[] range(long start, long end) {
long[] values = new long[(int) Math.abs(end - start) + 1];
if (end < start) {
long oldstart = start;
start = end;
end = oldstart;
}
for (long i = start; i <= end; i++) {
values[(int) (i - start)] = i;
}
return values;
}
}