From d23ac9de0930b9f5b16c5c1892f2671e28853e3e Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 4 Dec 2014 10:49:43 +0100 Subject: [PATCH] Repair the war claiming if statement. Fixes #708. Fixes #711. --- .../factions/engine/EngineMain.java | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/engine/EngineMain.java b/src/main/java/com/massivecraft/factions/engine/EngineMain.java index 4e59b2e4..c8651780 100644 --- a/src/main/java/com/massivecraft/factions/engine/EngineMain.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineMain.java @@ -590,39 +590,52 @@ public class EngineMain extends EngineAbstract } // For each of the old factions ... - for (Faction oldFaction : currentFactions) + for (Entry> entry : currentFactionChunks.entrySet()) { + Faction oldFaction = entry.getKey(); + Set oldChunks = entry.getValue(); + // ... that is an actual faction ... if (oldFaction.isNone()) continue; // ... for which the msender lacks permission ... if (MPerm.getPermTerritory().has(msender, oldFaction, false)) continue; - // ... print the error message of choice ... - if (msender.hasFaction() && msender.getFaction() == oldFaction) - { - msender.sendMessage(MPerm.getPermTerritory().createDeniedMessage(msender, oldFaction)); - } - else if ( ! MConf.get().claimingFromOthersAllowed) + // ... consider all reasons to forbid "overclaiming/warclaiming" ... + + // ... claiming from others may be forbidden ... + if ( ! MConf.get().claimingFromOthersAllowed) { msender.msg("You may not claim land from others."); - } - else if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) - { - msender.msg("You can't claim this land due to your relation with the current owner."); - } - else if ( ! oldFaction.hasLandInflation()) - { - msender.msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(msender)); - } - else if ( ! BoardColl.get().isAnyBorderPs(chunks)) - { - msender.msg("You must start claiming land at the border of the territory."); + event.setCancelled(true); + return; } - // ... and cancel. - event.setCancelled(true); - return; + // ... the relation may forbid ... + if (oldFaction.getRelationTo(newFaction).isAtLeast(Rel.TRUCE)) + { + msender.msg("You can't claim this land due to your relation with the current owner."); + event.setCancelled(true); + return; + } + + // ... the old faction might not be inflated enough ... + if (oldFaction.getPowerRounded() > oldFaction.getLandCount() - oldChunks.size()) + { + msender.msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(msender)); + event.setCancelled(true); + return; + } + + // ... and you might be trying to claim without starting at the border ... + if ( ! BoardColl.get().isAnyBorderPs(chunks)) + { + msender.msg("You must start claiming land at the border of the territory."); + event.setCancelled(true); + return; + } + + // ... otherwise you may claim from this old faction even though you lack explicit permission from them. } }