2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-24 13:26:59 +02:00
|
|
|
import com.massivecraft.factions.FPerm;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-16 11:05:49 +02:00
|
|
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
2013-04-25 13:25:15 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2013-04-24 20:17:20 +02:00
|
|
|
import com.massivecraft.factions.entity.MConf;
|
2013-04-18 12:29:56 +02:00
|
|
|
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;
|
2013-04-16 09:48:57 +02:00
|
|
|
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
2013-04-11 11:18:04 +02:00
|
|
|
import com.massivecraft.mcore.ps.PS;
|
2012-03-13 11:54:48 +01:00
|
|
|
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsClaim extends FCommand
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsClaim()
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("claim");
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2013-04-16 10:30:21 +02:00
|
|
|
this.addOptionalArg("radius", "1");
|
2013-04-24 20:17:20 +02:00
|
|
|
this.addOptionalArg("faction", "you");
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2013-04-25 13:25:15 +02:00
|
|
|
this.addRequirements(ReqFactionsEnabled.get());
|
2013-04-16 09:48:57 +02:00
|
|
|
this.addRequirements(ReqIsPlayer.get());
|
2013-04-25 17:00:22 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.CLAIM.node));
|
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()
|
2013-04-25 13:25:15 +02:00
|
|
|
{
|
2013-04-24 13:26:59 +02:00
|
|
|
// Args
|
2013-04-24 20:17:20 +02:00
|
|
|
Integer radius = this.arg(0, ARInteger.get(), 1);
|
2013-04-16 11:05:49 +02:00
|
|
|
if (radius == null) return;
|
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
final Faction forFaction = this.arg(1, ARFaction.get(me), usenderFaction);
|
2013-04-24 20:17:20 +02:00
|
|
|
if (forFaction == null) return;
|
|
|
|
|
2013-04-24 13:26:59 +02:00
|
|
|
// FPerm
|
2013-04-29 12:48:11 +02:00
|
|
|
if (forFaction.isNormal() && !FPerm.TERRITORY.has(usender, forFaction, true)) return;
|
2013-04-24 13:26:59 +02:00
|
|
|
|
|
|
|
// Validate
|
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;
|
|
|
|
}
|
2013-04-24 20:17:20 +02:00
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
if (radius > MConf.get().radiusClaimRadiusLimit && !usender.isUsingAdminMode())
|
2013-04-24 20:17:20 +02:00
|
|
|
{
|
|
|
|
msg("<b>The maximum radius allowed is <h>%s<b>.", MConf.get().radiusClaimRadiusLimit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-24 13:26:59 +02:00
|
|
|
// Apply
|
|
|
|
|
|
|
|
// single chunk
|
2012-03-13 11:54:48 +01:00
|
|
|
if (radius < 2)
|
2011-11-27 22:47:40 +01:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
usender.tryClaim(forFaction, PS.valueOf(me), true, 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
|
2013-04-24 13:26:59 +02:00
|
|
|
if (!Perm.CLAIM_RADIUS.has(sender, false))
|
2012-01-31 17:58:22 +01:00
|
|
|
{
|
2013-04-16 11:05:49 +02:00
|
|
|
msg("<b>You do not have permission to claim in a radius.");
|
|
|
|
return;
|
|
|
|
}
|
2013-01-30 02:21:33 +01:00
|
|
|
|
2013-04-24 13:26:59 +02:00
|
|
|
// TODO: There must be a better way than using a spiral task.
|
|
|
|
// TODO: Do some research to allow for claming sets of chunks in a batch with atomicity.
|
|
|
|
// This will probably result in an alteration to the owner change event.
|
|
|
|
// It would possibly contain a set of chunks instead of a single chunk.
|
|
|
|
|
2013-04-16 11:05:49 +02:00
|
|
|
new SpiralTask(PS.valueOf(me), radius)
|
|
|
|
{
|
|
|
|
private int failCount = 0;
|
2013-04-24 20:17:20 +02:00
|
|
|
private final int limit = MConf.get().radiusClaimFailureLimit - 1;
|
2012-03-13 11:54:48 +01:00
|
|
|
|
2013-04-16 11:05:49 +02:00
|
|
|
@Override
|
|
|
|
public boolean work()
|
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
boolean success = usender.tryClaim(forFaction, PS.valueOf(this.currentLocation()), true, true);
|
2013-04-16 11:05:49 +02:00
|
|
|
if (success)
|
2013-04-24 13:26:59 +02:00
|
|
|
{
|
|
|
|
this.failCount = 0;
|
|
|
|
}
|
|
|
|
else if (this.failCount++ >= this.limit)
|
2012-03-13 11:54:48 +01:00
|
|
|
{
|
2013-04-16 11:05:49 +02:00
|
|
|
this.stop();
|
|
|
|
return false;
|
2012-03-13 11:54:48 +01:00
|
|
|
}
|
2013-04-16 11:05:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
}
|