2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2012-03-13 11:54:51 +01:00
|
|
|
import com.massivecraft.factions.Conf;
|
2012-01-15 19:50:13 +01:00
|
|
|
import com.massivecraft.factions.FLocation;
|
2014-04-04 20:55:21 +02:00
|
|
|
import com.massivecraft.factions.Faction;
|
2011-10-09 14:53:38 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2012-03-13 11:54:51 +01:00
|
|
|
import com.massivecraft.factions.util.SpiralTask;
|
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
public class CmdClaim extends FCommand {
|
|
|
|
|
|
|
|
public CmdClaim() {
|
2014-07-01 22:10:18 +02:00
|
|
|
super();
|
|
|
|
this.aliases.add("claim");
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
//this.requiredArgs.add("");
|
2014-07-01 22:10:18 +02:00
|
|
|
this.optionalArgs.put("faction", "your");
|
|
|
|
this.optionalArgs.put("radius", "1");
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
this.permission = Permission.CLAIM.node;
|
|
|
|
this.disableOnLock = true;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeAdmin = false;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
|
|
|
// Read and validate input
|
2014-07-01 22:10:18 +02:00
|
|
|
final Faction forFaction = this.argAsFaction(0, myFaction);
|
|
|
|
int radius = this.argAsInt(1, 1);
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
if (radius < 1) {
|
2014-07-01 22:10:18 +02:00
|
|
|
msg("<b>If you specify a radius, it must be at least 1.");
|
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2012-01-31 17:58:25 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
if (radius < 2) {
|
|
|
|
// single chunk
|
|
|
|
fme.attemptClaim(forFaction, me.getLocation(), true);
|
2014-07-01 21:52:40 +02:00
|
|
|
} else {
|
2014-04-04 20:55:21 +02:00
|
|
|
// radius claim
|
|
|
|
if (!Permission.CLAIM_RADIUS.has(sender, false)) {
|
2014-07-01 22:10:18 +02:00
|
|
|
msg("<b>You do not have permission to claim in a radius.");
|
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2012-01-31 17:58:25 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
new SpiralTask(new FLocation(me), radius) {
|
|
|
|
private int failCount = 0;
|
|
|
|
private final int limit = Conf.radiusClaimFailureLimit - 1;
|
2013-01-30 02:21:32 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
@Override
|
|
|
|
public boolean work() {
|
|
|
|
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
|
2014-07-01 22:10:18 +02:00
|
|
|
if (success) {
|
|
|
|
failCount = 0;
|
|
|
|
} else if (!success && failCount++ >= limit) {
|
|
|
|
this.stop();
|
|
|
|
return false;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2012-01-15 19:50:13 +01:00
|
|
|
|
2014-04-04 20:55:21 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2012-03-13 11:54:51 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|