Factions/src/com/massivecraft/factions/cmd/CmdClaim.java

75 lines
1.5 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
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;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.SpiralTask;
2011-10-09 20:10:19 +02:00
public class CmdClaim extends FCommand
{
2011-10-09 20:10:19 +02:00
public CmdClaim()
{
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 21:57:43 +02:00
this.permission = Permission.CLAIM.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = false;
2011-10-23 17:55:53 +02:00
senderMustBeOfficer = false;
senderMustBeLeader = false;
}
@Override
public void perform()
{
2011-11-27 22:47:40 +01:00
// Read and validate input
final Faction forFaction = this.argAsFaction(0, myFaction);
int radius = this.argAsInt(1, 1);
if (radius < 1)
{
msg("<b>If you specify a radius, it must be at least 1.");
return;
}
if (radius < 2)
2011-11-27 22:47:40 +01:00
{
// single chunk
fme.attemptClaim(forFaction, me.getLocation(), true);
2011-11-27 22:47:40 +01:00
}
else
{
// radius claim
new SpiralTask(new FLocation(me), radius)
{
private int failCount = 0;
private final int limit = Conf.radiusClaimFailureLimit - 1;
@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
}
}
}