From d44ccda2111b66bd65505ba1fe7f565caccaf650 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 25 Oct 2011 01:27:58 -0500 Subject: [PATCH] autoclaim will now cancel beforehand if player isn't able to claim land for the specified faction --- src/com/massivecraft/factions/FPlayer.java | 18 ++++++++++++++++++ .../factions/cmd/CmdAutoClaim.java | 13 ++++++++++++- .../massivecraft/factions/cmd/FCommand.java | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 62f9cd07..b182b7d0 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -632,6 +632,24 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } } + public boolean canClaimForFaction(Faction forFaction) + { + if (forFaction.isNone()) return false; + + if + ( + this.isAdminBypassing() + || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) + || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) + || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer())) + ) + { + return true; + } + + return false; + } + public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) { String error = null; diff --git a/src/com/massivecraft/factions/cmd/CmdAutoClaim.java b/src/com/massivecraft/factions/cmd/CmdAutoClaim.java index d07ad4e0..a8bdd40a 100644 --- a/src/com/massivecraft/factions/cmd/CmdAutoClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdAutoClaim.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Role; public class CmdAutoClaim extends FCommand { @@ -26,12 +27,22 @@ public class CmdAutoClaim extends FCommand public void perform() { Faction forFaction = this.argAsFaction(0, myFaction); - if (forFaction == null || (forFaction == myFaction && fme.getAutoClaimFor() == myFaction)) + if (forFaction == null || forFaction == fme.getAutoClaimFor()) { fme.setAutoClaimFor(null); msg("Auto-claiming of land disabled."); return; } + + if (! fme.canClaimForFaction(forFaction)) + { + if (myFaction == forFaction) + msg("You must be %s to claim land.", Role.MODERATOR.toString()); + else + msg("You can't claim land for %s.", forFaction.describeTo(fme)); + + return; + } fme.setAutoClaimFor(forFaction); diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index 5863cbf6..e2ab7914 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -164,7 +164,7 @@ public abstract class FCommand extends MCommand

if (msg && ret == null) { - this.msg("No player \"

%s\" could not be found.", name); + this.msg("No player \"

%s\" could be found.", name); } return ret;