From 82db1624c983f7786621e217093957abe907e9ac Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 23 Aug 2011 17:12:17 -0500 Subject: [PATCH] Added new "Ally" related protection options to complement the "Enemy" ones (added thanks to donation from BeTrayed) --- src/com/massivecraft/factions/Conf.java | 6 ++++++ .../listeners/FactionsBlockListener.java | 17 +++++++++-------- .../listeners/FactionsEntityListener.java | 6 +++--- .../listeners/FactionsPlayerListener.java | 7 ++++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 570b1e7f..82c3ab1c 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -107,6 +107,12 @@ public class Conf { public static boolean territoryEnemyPainBuildWhenOffline = false; public static boolean territoryEnemyDenyUseage = true; public static boolean territoryEnemyProtectMaterials = true; + public static boolean territoryAllyDenyBuild = true; + public static boolean territoryAllyDenyBuildWhenOffline = true; + public static boolean territoryAllyPainBuild = false; + public static boolean territoryAllyPainBuildWhenOffline = false; + public static boolean territoryAllyDenyUseage = true; + public static boolean territoryAllyProtectMaterials = true; public static boolean territoryBlockCreepers = false; public static boolean territoryBlockCreepersWhenOffline = false; public static boolean territoryBlockFireballs = false; diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index 7eeab481..5fa3233d 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -17,6 +17,7 @@ import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.struct.Relation; public class FactionsBlockListener extends BlockListener { @@ -134,12 +135,12 @@ public class FactionsBlockListener extends BlockListener { return false; } - boolean areEnemies = pistonFaction.getRelation(otherFaction).isEnemy(); + Relation rel = pistonFaction.getRelation(otherFaction); boolean online = otherFaction.hasPlayersOnline(); if ( - (online && (areEnemies ? Conf.territoryEnemyDenyBuild : Conf.territoryDenyBuild)) - || (!online && (areEnemies ? Conf.territoryEnemyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline)) + (online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuild : (rel.isAlly() ? Conf.territoryAllyDenyBuild : Conf.territoryDenyBuild))) + || (!online && (rel.isEnemy() ? Conf.territoryEnemyDenyBuildWhenOffline : (rel.isAlly() ? Conf.territoryAllyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline))) ) { return false; } @@ -180,15 +181,15 @@ public class FactionsBlockListener extends BlockListener { } Faction myFaction = me.getFaction(); - boolean areEnemies = myFaction.getRelation(otherFaction).isEnemy(); + Relation rel = myFaction.getRelation(otherFaction); // Cancel if we are not in our own territory if (myFaction != otherFaction) { boolean online = otherFaction.hasPlayersOnline(); - boolean pain = (online && (areEnemies ? Conf.territoryEnemyPainBuild : Conf.territoryPainBuild)) - || (!online && (areEnemies ? Conf.territoryEnemyPainBuildWhenOffline : Conf.territoryPainBuildWhenOffline)); - boolean deny = (online && (areEnemies ? Conf.territoryEnemyDenyBuild : Conf.territoryDenyBuild)) - || (!online && (areEnemies ? Conf.territoryEnemyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline)); + 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 //hurt the player for building/destroying? if (pain) { diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 31aac61f..5c3f673f 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -371,14 +371,14 @@ public class FactionsEntityListener extends EntityListener { } Faction myFaction = me.getFaction(); - boolean areEnemies = myFaction.getRelation(otherFaction).isEnemy(); + Relation rel = myFaction.getRelation(otherFaction); // Cancel if we are not in our own territory if (myFaction != otherFaction) { boolean online = otherFaction.hasPlayersOnline(); if ( - (online && (areEnemies ? Conf.territoryEnemyDenyBuild : Conf.territoryDenyBuild)) - || (!online && (areEnemies ? Conf.territoryEnemyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline)) + (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; diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 6c2b8d01..9f86712e 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -321,11 +321,11 @@ public class FactionsPlayerListener extends PlayerListener{ } Faction myFaction = me.getFaction(); - boolean areEnemies = myFaction.getRelation(otherFaction).isEnemy(); + Relation rel = myFaction.getRelation(otherFaction); // Cancel if we are not in our own territory if (myFaction != otherFaction) { - if (areEnemies ? Conf.territoryEnemyDenyUseage : Conf.territoryDenyUseage) { + 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; } @@ -367,8 +367,9 @@ public class FactionsPlayerListener extends PlayerListener{ FPlayer me = FPlayer.get(player); Faction myFaction = me.getFaction(); + Relation rel = myFaction.getRelation(otherFaction); - if (myFaction.getRelation(otherFaction).isEnemy() && !Conf.territoryEnemyProtectMaterials) { + if ((rel.isEnemy() && !Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && !Conf.territoryAllyProtectMaterials)) { return true; }