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