Added a radius to safe claim
This commit is contained in:
parent
b0e659e534
commit
3820b53d29
@ -1,8 +1,11 @@
|
||||
package org.mcteam.factions;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.mcteam.factions.util.MiscUtil;
|
||||
|
||||
public class FLocation {
|
||||
|
||||
@ -80,13 +83,25 @@ public class FLocation {
|
||||
}
|
||||
|
||||
//----------------------------------------------//
|
||||
// Misc
|
||||
// Misc Geometry
|
||||
//----------------------------------------------//
|
||||
|
||||
public FLocation getRelative(int dx, int 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
|
||||
//----------------------------------------------//
|
||||
|
@ -52,6 +52,7 @@ import org.mcteam.factions.gson.GsonBuilder;
|
||||
import org.mcteam.factions.listeners.FactionsBlockListener;
|
||||
import org.mcteam.factions.listeners.FactionsEntityListener;
|
||||
import org.mcteam.factions.listeners.FactionsPlayerListener;
|
||||
import org.mcteam.factions.util.MiscUtil;
|
||||
|
||||
|
||||
import com.nijiko.permissions.PermissionHandler;
|
||||
@ -94,6 +95,8 @@ public class Factions extends JavaPlugin {
|
||||
log("=== INIT START ===");
|
||||
long timeInitStart = System.currentTimeMillis();
|
||||
|
||||
log("asdfasdas"+MiscUtil.range(-1, 1));
|
||||
|
||||
// Add the commands
|
||||
commands.add(new FCommandHelp());
|
||||
commands.add(new FCommandAdmin());
|
||||
|
@ -6,13 +6,14 @@ import org.mcteam.factions.FLocation;
|
||||
import org.mcteam.factions.Faction;
|
||||
import org.mcteam.factions.Factions;
|
||||
|
||||
|
||||
public class FCommandSafeclaim extends FBaseCommand {
|
||||
|
||||
public FCommandSafeclaim() {
|
||||
aliases.add("safeclaim");
|
||||
aliases.add("safe");
|
||||
|
||||
optionalParameters.add("radius");
|
||||
|
||||
helpDescription = "Claim land for the safezone";
|
||||
}
|
||||
|
||||
@ -22,9 +23,26 @@ public class FCommandSafeclaim extends FBaseCommand {
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
FLocation flocation = new FLocation(me);
|
||||
Board.setFactionAt(Faction.getSafeZone(), flocation);
|
||||
sendMessage("This land is now a safe zone");
|
||||
// The current location of the player
|
||||
FLocation playerFlocation = new FLocation(me);
|
||||
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
25
src/org/mcteam/factions/util/MiscUtil.java
Normal file
25
src/org/mcteam/factions/util/MiscUtil.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user