From c89db2c4d69598759a2b5259fe6898bba7851420 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 6 Sep 2011 16:35:43 -0500 Subject: [PATCH] Fix for allies bypassing ownership if Ally options allowed them to build/interact/use in allied territory Also consolidated some Conf lookups into new functions for Relations, to simplify and de-uglify the code a bit --- .../listeners/FactionsBlockListener.java | 28 +++---- .../listeners/FactionsEntityListener.java | 24 ++---- .../listeners/FactionsPlayerListener.java | 39 +++------ .../factions/struct/Relation.java | 79 +++++++++++++++++-- 4 files changed, 104 insertions(+), 66 deletions(-) diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index 5fa3233d..ed22ac05 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -179,23 +179,25 @@ public class FactionsBlockListener extends BlockListener { me.sendMessage("You can't "+action+" in a war zone."); return false; } - + Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelation(otherFaction); - - // Cancel if we are not in our own territory - if (myFaction != otherFaction) { + boolean ownershipFail = Conf.ownedAreasEnabled && (Conf.ownedAreaDenyBuild || Conf.ownedAreaPainBuild) && !otherFaction.playerHasOwnershipRights(me, loc); + + // Cancel and/or cause pain (depending on configuration) if we are not in our own territory + if (!rel.isMember()) { boolean online = otherFaction.hasPlayersOnline(); - boolean pain = (online && (rel.isEnemy() ? Conf.territoryEnemyPainBuild : (rel.isAlly() ? Conf.territoryAllyPainBuild : Conf.territoryPainBuild))) - || (!online && (rel.isEnemy() ? Conf.territoryEnemyPainBuildWhenOffline : (rel.isAlly() ? Conf.territoryAllyPainBuildWhenOffline : Conf.territoryPainBuildWhenOffline))); - boolean deny = (online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuild : (rel.isAlly() ? Conf.territoryAllyDenyBuild : Conf.territoryDenyBuild))) - || (!online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuildWhenOffline : (rel.isAlly() ? Conf.territoryAllyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline))); - //added by Bladedpenguin@gmail.com + boolean pain = rel.confPainBuild(online); + boolean deny = rel.confDenyBuild(online); + //hurt the player for building/destroying? if (pain) { player.damage(Conf.actionDeniedPainAmount); if (!deny) { me.sendMessage("You are hurt for "+action+" in the territory of "+otherFaction.getTag(myFaction)); + if (!Conf.ownedAreaDenyBuild) { + return true; + } } } if (deny) { @@ -203,12 +205,8 @@ public class FactionsBlockListener extends BlockListener { return false; } } - // Also cancel if player doesn't have ownership rights for this claim - else if ( - Conf.ownedAreasEnabled - && (Conf.ownedAreaDenyBuild || Conf.ownedAreaPainBuild) - && !myFaction.playerHasOwnershipRights(me, loc) - && !Factions.hasPermOwnershipBypass(player) + // Also cancel and/or cause pain if player doesn't have ownership rights for this claim + if (ownershipFail && !Factions.hasPermOwnershipBypass(player) ) { if (Conf.ownedAreaPainBuild){ player.damage(Conf.actionDeniedPainAmount); diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 5c3f673f..5cfb6621 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -372,26 +372,16 @@ public class FactionsEntityListener extends EntityListener { Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelation(otherFaction); + boolean ownershipFail = Conf.ownedAreasEnabled && Conf.ownedAreaDenyBuild && !otherFaction.playerHasOwnershipRights(me, loc); - // Cancel if we are not in our own territory - if (myFaction != otherFaction) { - boolean online = otherFaction.hasPlayersOnline(); - if ( - (online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuild : (rel.isAlly() ? Conf.territoryAllyDenyBuild : Conf.territoryDenyBuild))) - || (!online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuildWhenOffline : (rel.isAlly() ? Conf.territoryAllyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline))) - ) { - me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction)); - return false; - } + // Cancel if we are not in our own territory and building should be denied + if (!rel.isMember() && rel.confDenyBuild(otherFaction.hasPlayersOnline())) { + me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction)); + return false; } // Also cancel if player doesn't have ownership rights for this claim - else if ( - Conf.ownedAreasEnabled - && Conf.ownedAreaDenyBuild - && !myFaction.playerHasOwnershipRights(me, loc) - && !Factions.hasPermOwnershipBypass(player) - ) { - me.sendMessage("You can't "+action+" paintings in this territory, it is owned by: "+myFaction.getOwnerListString(loc)); + else if (ownershipFail && (!rel.isMember() || !Factions.hasPermOwnershipBypass(player))) { + me.sendMessage("You can't "+action+" paintings in this territory, it is owned by: "+otherFaction.getOwnerListString(loc)); return false; } diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 9f86712e..9762bf2f 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -322,25 +322,19 @@ public class FactionsPlayerListener extends PlayerListener{ Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelation(otherFaction); - + boolean ownershipFail = Conf.ownedAreasEnabled && Conf.ownedAreaDenyUseage && !otherFaction.playerHasOwnershipRights(me, loc); + // Cancel if we are not in our own territory - if (myFaction != otherFaction) { - if (rel.isEnemy() ? Conf.territoryEnemyDenyUseage : (rel.isAlly() ? Conf.territoryAllyDenyUseage : Conf.territoryDenyUseage)) { - me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); - return false; - } + if (!rel.isMember() && rel.confDenyUseage()) { + me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); + return false; } // Also cancel if player doesn't have ownership rights for this claim - else if ( - Conf.ownedAreasEnabled - && Conf.ownedAreaDenyUseage - && !myFaction.playerHasOwnershipRights(me, loc) - && !Factions.hasPermOwnershipBypass(player) - ) { + else if (ownershipFail && (!rel.isMember() || !Factions.hasPermOwnershipBypass(player))) { me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc)); return false; } - + return true; } @@ -364,28 +358,19 @@ public class FactionsPlayerListener extends PlayerListener{ return true; } } - + FPlayer me = FPlayer.get(player); Faction myFaction = me.getFaction(); Relation rel = myFaction.getRelation(otherFaction); - - if ((rel.isEnemy() && !Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && !Conf.territoryAllyProtectMaterials)) { - return true; - } - + boolean ownershipFail = Conf.ownedAreasEnabled && Conf.ownedAreaProtectMaterials && !otherFaction.playerHasOwnershipRights(me, loc); + // You may use any block unless it is another faction's territory... - if (otherFaction.isNormal() && myFaction != otherFaction) { + if ((rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials)) { me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); return false; } // Also cancel if player doesn't have ownership rights for this claim - else if ( - myFaction == otherFaction - && Conf.ownedAreasEnabled - && Conf.ownedAreaProtectMaterials - && !myFaction.playerHasOwnershipRights(me, loc) - && !Factions.hasPermOwnershipBypass(player) - ) { + else if (ownershipFail && (!rel.isMember() || !Factions.hasPermOwnershipBypass(player))) { me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in this territory, it is owned by: "+myFaction.getOwnerListString(loc)); return false; } diff --git a/src/com/massivecraft/factions/struct/Relation.java b/src/com/massivecraft/factions/struct/Relation.java index 94fdc5aa..dc525553 100644 --- a/src/com/massivecraft/factions/struct/Relation.java +++ b/src/com/massivecraft/factions/struct/Relation.java @@ -25,19 +25,19 @@ public enum Relation { } public boolean isMember() { - return this == Relation.MEMBER; + return this.value == MEMBER.value; } public boolean isAlly() { - return this == Relation.ALLY; + return this.value == ALLY.value; } public boolean isNeutral() { - return this == Relation.NEUTRAL; + return this.value == NEUTRAL.value; } public boolean isEnemy() { - return this == Relation.ENEMY; + return this.value == ENEMY.value; } public boolean isAtLeast(Relation relation) { @@ -49,14 +49,79 @@ public enum Relation { } public ChatColor getColor() { - if (this == Relation.MEMBER) { + if (this.value == MEMBER.value) { return Conf.colorMember; - } else if (this == Relation.ALLY) { + } else if (this.value == ALLY.value) { return Conf.colorAlly; - } else if (this == Relation.NEUTRAL) { + } else if (this.value == NEUTRAL.value) { return Conf.colorNeutral; } else { return Conf.colorEnemy; } } + + // return appropriate Conf setting for DenyBuild based on this relation and their online status + public boolean confDenyBuild(boolean online) { + if (online) { + if (isEnemy()) { + return Conf.territoryEnemyDenyBuild; + } + else if (isAlly()) { + return Conf.territoryAllyDenyBuild; + } + else { + return Conf.territoryDenyBuild; + } + } + else { + if (isEnemy()) { + return Conf.territoryEnemyDenyBuildWhenOffline; + } + else if (isAlly()) { + return Conf.territoryAllyDenyBuildWhenOffline; + } + else { + return Conf.territoryDenyBuildWhenOffline; + } + } + } + + // return appropriate Conf setting for PainBuild based on this relation and their online status + public boolean confPainBuild(boolean online) { + if (online) { + if (isEnemy()) { + return Conf.territoryEnemyPainBuild; + } + else if (isAlly()) { + return Conf.territoryAllyPainBuild; + } + else { + return Conf.territoryPainBuild; + } + } + else { + if (isEnemy()) { + return Conf.territoryEnemyPainBuildWhenOffline; + } + else if (isAlly()) { + return Conf.territoryAllyPainBuildWhenOffline; + } + else { + return Conf.territoryPainBuildWhenOffline; + } + } + } + + // return appropriate Conf setting for DenyUseage based on this relation + public boolean confDenyUseage() { + if (isEnemy()) { + return Conf.territoryEnemyDenyUseage; + } + else if (isAlly()) { + return Conf.territoryAllyDenyUseage; + } + else { + return Conf.territoryDenyUseage; + } + } }