2856411594
New setting "radiusClaimFailureLimit" (default 9). If claims are unsuccessful that many times in a row during a radius claim, the task will cancel out. There is no longer a limit to the specified radius since the process should no longer cause major server stress, and due to the process canceling out after several failures as just described. Added some new methods to FLocation to quickly convert between block/chunk/region positions, and rewrote the FLocation hashCode() method to make it faster.
75 lines
1.5 KiB
Java
75 lines
1.5 KiB
Java
package com.massivecraft.factions.cmd;
|
|
|
|
import com.massivecraft.factions.Conf;
|
|
import com.massivecraft.factions.FLocation;
|
|
import com.massivecraft.factions.Faction;
|
|
import com.massivecraft.factions.struct.Permission;
|
|
import com.massivecraft.factions.util.SpiralTask;
|
|
|
|
|
|
public class CmdClaim extends FCommand
|
|
{
|
|
|
|
public CmdClaim()
|
|
{
|
|
super();
|
|
this.aliases.add("claim");
|
|
|
|
//this.requiredArgs.add("");
|
|
this.optionalArgs.put("faction", "your");
|
|
this.optionalArgs.put("radius", "1");
|
|
|
|
this.permission = Permission.CLAIM.node;
|
|
this.disableOnLock = true;
|
|
|
|
senderMustBePlayer = true;
|
|
senderMustBeMember = false;
|
|
senderMustBeOfficer = false;
|
|
senderMustBeLeader = false;
|
|
}
|
|
|
|
@Override
|
|
public void perform()
|
|
{
|
|
// 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)
|
|
{
|
|
// single chunk
|
|
fme.attemptClaim(forFaction, me.getLocation(), true);
|
|
}
|
|
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;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|