Factions3/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java

82 lines
1.9 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.task.SpiralTask;
2013-04-16 11:05:49 +02:00
import com.massivecraft.mcore.cmd.arg.ARInteger;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
2013-04-11 11:18:04 +02:00
import com.massivecraft.mcore.ps.PS;
2013-04-10 13:12:22 +02:00
public class CmdFactionsClaim extends FCommand
{
2013-04-10 13:12:22 +02:00
public CmdFactionsClaim()
{
2013-04-16 10:11:59 +02:00
this.addAliases("claim");
this.addOptionalArg("faction", "you");
this.addOptionalArg("radius", "1");
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.CLAIM.node));
this.addRequirements(ReqIsPlayer.get());
}
@Override
public void perform()
{
2013-04-22 13:03:21 +02:00
final Faction forFaction = this.arg(0, ARFaction.get(me));
2013-04-16 11:05:49 +02:00
if (forFaction == null) return;
Integer radius = this.arg(1, ARInteger.get(), 1);
if (radius == null) return;
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
2013-04-19 14:24:35 +02:00
fme.attemptClaim(forFaction, PS.valueOf(me), true);
2013-04-16 11:05:49 +02:00
return;
2011-11-27 22:47:40 +01:00
}
2013-04-16 11:05:49 +02:00
// radius claim
if (! Perm.CLAIM_RADIUS.has(sender, false))
{
2013-04-16 11:05:49 +02:00
msg("<b>You do not have permission to claim in a radius.");
return;
}
2013-04-16 11:05:49 +02:00
// TODO: I do not beleive in the spiral-task. Get rid of this. The failcount can be precalculated.
new SpiralTask(PS.valueOf(me), radius)
{
private int failCount = 0;
private final int limit = UConf.get(me).radiusClaimFailureLimit - 1;
2013-04-16 11:05:49 +02:00
@Override
public boolean work()
{
2013-04-19 14:24:35 +02:00
boolean success = fme.attemptClaim(forFaction, PS.valueOf(this.currentLocation()), true);
2013-04-16 11:05:49 +02:00
if (success)
failCount = 0;
else if ( ! success && failCount++ >= limit)
{
2013-04-16 11:05:49 +02:00
this.stop();
return false;
}
2013-04-16 11:05:49 +02:00
return true;
}
};
}
}