Add claim line. Resolves #142.

This commit is contained in:
drtshock 2015-01-22 22:38:46 -06:00
parent bee36f5ba0
commit ebf00ccf0d
6 changed files with 89 additions and 0 deletions

View File

@ -131,6 +131,7 @@ public class Conf {
public static boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = true;
public static int claimsRequireMinFactionMembers = 1;
public static int claimedLandsMax = 0;
public static int lineClaimLimit = 5;
// if someone is doing a radius claim and the process fails to claim land this many times in a row, it will exit
public static int radiusClaimFailureLimit = 9;

View File

@ -0,0 +1,76 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
public class CmdClaimLine extends FCommand {
public static final BlockFace[] axis = {BlockFace.SOUTH, BlockFace.WEST, BlockFace.NORTH, BlockFace.EAST};
public CmdClaimLine() {
// Aliases
this.aliases.add("claimline");
this.aliases.add("cl");
// Args
this.optionalArgs.put("amount", "1");
this.optionalArgs.put("direction", "facing");
this.optionalArgs.put("faction", "you");
this.permission = Permission.CLAIM_LINE.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
// Args
Integer amount = this.argAsInt(0, 1); // Default to 1
if (amount > Conf.lineClaimLimit) {
fme.msg(TL.COMMAND_CLAIMLINE_ABOVEMAX, Conf.lineClaimLimit);
return;
}
String direction = this.argAsString(1);
BlockFace blockFace;
if (direction == null) {
blockFace = axis[Math.round(me.getLocation().getYaw() / 90f) & 0x3];
} else if (direction.equalsIgnoreCase("north")) {
blockFace = BlockFace.NORTH;
} else if (direction.equalsIgnoreCase("east")) {
blockFace = BlockFace.EAST;
} else if (direction.equalsIgnoreCase("south")) {
blockFace = BlockFace.SOUTH;
} else if (direction.equalsIgnoreCase("west")) {
blockFace = BlockFace.WEST;
} else {
fme.msg(TL.COMMAND_CLAIMLINE_NOTVALID, direction);
return;
}
final Faction forFaction = this.argAsFaction(2, myFaction);
Location location = me.getLocation();
// TODO: make this a task like claiming a radius?
for (int i = 0; i < amount; i++) {
fme.attemptClaim(forFaction, location, true);
location = location.add(blockFace.getModX() * 16, 0, blockFace.getModZ() * 16);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CLAIMLINE_DESCRIPTION;
}
}

View File

@ -63,6 +63,7 @@ public class FCmdRoot extends FCommand {
public CmdDelFWarp cmdDelFWarp = new CmdDelFWarp();
public CmdModifyPower cmdModifyPower = new CmdModifyPower();
public CmdLogins cmdLogins = new CmdLogins();
public CmdClaimLine cmdClaimLine = new CmdClaimLine();
public FCmdRoot() {
super();
@ -141,6 +142,7 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdDelFWarp);
this.addSubCommand(this.cmdModifyPower);
this.addSubCommand(this.cmdLogins);
this.addSubCommand(this.cmdClaimLine);
}
@Override

View File

@ -15,6 +15,7 @@ public enum Permission {
CHAT("chat"),
CHATSPY("chatspy"),
CLAIM("claim"),
CLAIM_LINE("claim.line"),
CLAIM_RADIUS("claim.radius"),
CONFIG("config"),
CREATE("create"),

View File

@ -98,6 +98,12 @@ public enum TL {
COMMAND_CLAIM_DENIED("<b>You do not have permission to claim in a radius."),
COMMAND_CLAIM_DESCRIPTION("Claim land from where you are standing"),
COMMAND_CLAIMLINE_INVALIDRADIUS("<b>If you specify a distance, it must be at least 1."),
COMMAND_CLAIMLINE_DENIED("<b>You do not have permission to claim in a line."),
COMMAND_CLAIMLINE_DESCRIPTION("Claim land in a straight line."),
COMMAND_CLAIMLINE_ABOVEMAX("<b>The maximum limit for claim line is <b>%s<b>."),
COMMAND_CLAIMLINE_NOTVALID("%s<b> is not a cardinal direction. You may use <h>north<b>, <h>east<b>, <h>south <b>or <h>west<b>."),
COMMAND_CONFIG_NOEXIST("<b>No configuration setting \"<h>%1$s<b>\" exists."),
COMMAND_CONFIG_SET_TRUE("\" option set to true (enabled)."),
COMMAND_CONFIG_SET_FALSE("\" option set to false (disabled)."),

View File

@ -59,6 +59,7 @@ permissions:
factions.autoclaim: true
factions.chat: true
factions.claim: true
factions.claim.line: true
factions.claim.radius: true
factions.deinvite: true
factions.description: true
@ -244,3 +245,5 @@ permissions:
description: modify other player's power
factions.monitorlogins:
description: monitor join and leaves of faction members
factions.claim.line:
description: claim in a line