Fixed lag with claiming
This commit is contained in:
parent
8c6107859e
commit
135b961661
@ -3,7 +3,6 @@ package com.massivecraft.factions.cmd;
|
|||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
import com.massivecraft.factions.FLocation;
|
import com.massivecraft.factions.FLocation;
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.SavageFactions;
|
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
import com.massivecraft.factions.struct.Role;
|
import com.massivecraft.factions.struct.Role;
|
||||||
import com.massivecraft.factions.util.SpiralTask;
|
import com.massivecraft.factions.util.SpiralTask;
|
||||||
@ -14,82 +13,77 @@ import com.massivecraft.factions.zcore.util.TL;
|
|||||||
|
|
||||||
public class CmdClaim extends FCommand {
|
public class CmdClaim extends FCommand {
|
||||||
|
|
||||||
public CmdClaim() {
|
public CmdClaim() {
|
||||||
super();
|
super();
|
||||||
this.aliases.add("claim");
|
this.aliases.add("claim");
|
||||||
|
|
||||||
//this.requiredArgs.add("");
|
//this.requiredArgs.add("");
|
||||||
this.optionalArgs.put("radius", "1");
|
this.optionalArgs.put("radius", "1");
|
||||||
this.optionalArgs.put("faction", "your");
|
this.optionalArgs.put("faction", "your");
|
||||||
|
|
||||||
this.permission = Permission.CLAIM.node;
|
this.permission = Permission.CLAIM.node;
|
||||||
this.disableOnLock = true;
|
this.disableOnLock = true;
|
||||||
|
|
||||||
senderMustBePlayer = true;
|
senderMustBePlayer = true;
|
||||||
senderMustBeMember = false;
|
senderMustBeMember = false;
|
||||||
senderMustBeModerator = false;
|
senderMustBeModerator = false;
|
||||||
senderMustBeColeader = false;
|
senderMustBeColeader = false;
|
||||||
senderMustBeAdmin = false;
|
senderMustBeAdmin = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform() {
|
public void perform() {
|
||||||
// Read and validate input
|
// Read and validate input
|
||||||
int radius = this.argAsInt(0, 1); // Default to 1
|
int radius = this.argAsInt(0, 1); // Default to 1
|
||||||
final Faction forFaction = this.argAsFaction(1, myFaction); // Default to own
|
final Faction forFaction = this.argAsFaction(1, myFaction); // Default to own
|
||||||
|
|
||||||
if (!fme.isAdminBypassing()) {
|
if (!fme.isAdminBypassing()) {
|
||||||
Access access = myFaction.getAccess(fme, PermissableAction.TERRITORY);
|
Access access = myFaction.getAccess(fme, PermissableAction.CLAIM);
|
||||||
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
|
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
|
||||||
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "change faction territory");
|
fme.msg(TL.GENERIC_NOPERMISSION, "change faction territory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forFaction.isWilderness()) {
|
|
||||||
CmdUnclaim cmdUnclaim = SavageFactions.plugin.cmdBase.cmdUnclaim;
|
|
||||||
cmdUnclaim.execute(sender, args.size() > 1 ? args.subList(0, 1) : args);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radius < 1) {
|
if (radius < 1) {
|
||||||
msg(TL.COMMAND_CLAIM_INVALIDRADIUS);
|
msg(TL.COMMAND_CLAIM_INVALIDRADIUS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radius < 2) {
|
if (radius < 2) {
|
||||||
// single chunk
|
// single chunk
|
||||||
fme.attemptClaim(forFaction, me.getLocation(), true);
|
fme.attemptClaim(forFaction, me.getLocation(), true);
|
||||||
} else {
|
} else {
|
||||||
// radius claim
|
// radius claim
|
||||||
if (!Permission.CLAIM_RADIUS.has(sender, false)) {
|
if (!Permission.CLAIM_RADIUS.has(sender, false)) {
|
||||||
msg(TL.COMMAND_CLAIM_DENIED);
|
msg(TL.COMMAND_CLAIM_DENIED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new SpiralTask(new FLocation(me), radius) {
|
new SpiralTask(new FLocation(me), radius) {
|
||||||
private final int limit = Conf.radiusClaimFailureLimit - 1;
|
private final int limit = Conf.radiusClaimFailureLimit - 1;
|
||||||
private int failCount = 0;
|
private int failCount = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean work() {
|
public boolean work() {
|
||||||
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
|
boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true);
|
||||||
if (success) {
|
if (success) {
|
||||||
failCount = 0;
|
failCount = 0;
|
||||||
} else if (failCount++ >= limit) {
|
} else if (failCount++ >= limit) {
|
||||||
this.stop();
|
this.stop();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TL getUsageTranslation() {
|
public TL getUsageTranslation() {
|
||||||
return TL.COMMAND_CLAIM_DESCRIPTION;
|
return TL.COMMAND_CLAIM_DESCRIPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user