From d69b278728867faf7360808a379e7a85f4ef0485 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sat, 9 Jul 2011 01:36:18 -0500 Subject: [PATCH] New options in conf.json which will now treat enemy factions differently: "territoryEnemyDenyBuild", "territoryEnemyDenyBuildWhenOffline","territoryEnemyDenyUseage", and "territoryEnemyProtectMaterials" (all default to true). If someone in an enemy faction tries any of those (builsing/destroying, using certain inventory items, or interacting with certain blocks such as doors), these new values will be checked; otherwise, for neutral and allied factions the existing values will be used. Also slightly simplified the code used for checking relations. --- src/org/mcteam/factions/Conf.java | 4 ++++ .../mcteam/factions/commands/FCommandShow.java | 5 ++--- .../listeners/FactionsBlockListener.java | 10 +++++++--- .../listeners/FactionsEntityListener.java | 10 +++++++--- .../listeners/FactionsPlayerListener.java | 7 ++++++- src/org/mcteam/factions/struct/Relation.java | 16 ++++++++++++++++ 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/org/mcteam/factions/Conf.java b/src/org/mcteam/factions/Conf.java index f666d10b..441c09ad 100644 --- a/src/org/mcteam/factions/Conf.java +++ b/src/org/mcteam/factions/Conf.java @@ -78,6 +78,10 @@ public class Conf { public static boolean territoryDenyBuild = true; public static boolean territoryDenyBuildWhenOffline = true; public static boolean territoryDenyUseage = true; + public static boolean territoryEnemyDenyBuild = true; + public static boolean territoryEnemyDenyBuildWhenOffline = true; + public static boolean territoryEnemyDenyUseage = true; + public static boolean territoryEnemyProtectMaterials = true; public static boolean territoryBlockCreepers = false; public static boolean territoryBlockCreepersWhenOffline = false; public static boolean territoryBlockFireballs = false; diff --git a/src/org/mcteam/factions/commands/FCommandShow.java b/src/org/mcteam/factions/commands/FCommandShow.java index d12aa3c1..78110342 100644 --- a/src/org/mcteam/factions/commands/FCommandShow.java +++ b/src/org/mcteam/factions/commands/FCommandShow.java @@ -7,7 +7,6 @@ import org.bukkit.entity.Player; import org.mcteam.factions.Conf; import org.mcteam.factions.FPlayer; import org.mcteam.factions.Faction; -import org.mcteam.factions.struct.Relation; import org.mcteam.factions.struct.Role; import org.mcteam.factions.util.TextUtil; @@ -73,9 +72,9 @@ public class FCommandShow extends FBaseCommand { continue; } listpart = otherFaction.getTag(me)+Conf.colorSystem+", "; - if (otherFaction.getRelation(faction) == Relation.ALLY) { + if (otherFaction.getRelation(faction).isAlly()) { allyList += listpart; - } else if (otherFaction.getRelation(faction) == Relation.ENEMY) { + } else if (otherFaction.getRelation(faction).isEnemy()) { enemyList += listpart; } } diff --git a/src/org/mcteam/factions/listeners/FactionsBlockListener.java b/src/org/mcteam/factions/listeners/FactionsBlockListener.java index c3faf3c4..e93ca7df 100644 --- a/src/org/mcteam/factions/listeners/FactionsBlockListener.java +++ b/src/org/mcteam/factions/listeners/FactionsBlockListener.java @@ -88,13 +88,17 @@ public class FactionsBlockListener extends BlockListener { me.sendMessage("You can't "+action+" in a war zone."); return false; } - + Faction myFaction = me.getFaction(); - + boolean areEnemies = myFaction.getRelation(otherFaction).isEnemy(); + // Cancel if we are not in our own territory if (myFaction != otherFaction) { boolean online = otherFaction.hasPlayersOnline(); - if ((online && Conf.territoryDenyBuild) || (!online && Conf.territoryDenyBuildWhenOffline)) { + if ( + (online && (areEnemies ? Conf.territoryEnemyDenyBuild : Conf.territoryDenyBuild)) + || (!online && (areEnemies ? Conf.territoryEnemyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline)) + ) { me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction)); return false; } diff --git a/src/org/mcteam/factions/listeners/FactionsEntityListener.java b/src/org/mcteam/factions/listeners/FactionsEntityListener.java index 53b54956..8c5dfe91 100644 --- a/src/org/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/org/mcteam/factions/listeners/FactionsEntityListener.java @@ -193,13 +193,13 @@ public class FactionsEntityListener extends EntityListener { } // You can never hurt faction members or allies - if (relation == Relation.MEMBER || relation == Relation.ALLY) { + if (relation.isMember() || relation.isAlly()) { attacker.sendMessage(Conf.colorSystem+"You can't hurt "+defender.getNameAndRelevant(attacker)); return false; } // You can not hurt neutrals in their own territory. - if (relation == Relation.NEUTRAL && defender.isInOwnTerritory()) { + if (relation.isNeutral() && defender.isInOwnTerritory()) { attacker.sendMessage(Conf.colorSystem+"You can't hurt "+relation.getColor()+defender.getNameAndRelevant(attacker)+Conf.colorSystem+" in their own territory."); defender.sendMessage(attacker.getNameAndRelevant(defender)+Conf.colorSystem+" tried to hurt you."); return false; @@ -319,11 +319,15 @@ public class FactionsEntityListener extends EntityListener { } Faction myFaction = me.getFaction(); + boolean areEnemies = myFaction.getRelation(otherFaction).isEnemy(); // Cancel if we are not in our own territory if (myFaction != otherFaction) { boolean online = otherFaction.hasPlayersOnline(); - if ((online && Conf.territoryDenyBuild) || (!online && Conf.territoryDenyBuildWhenOffline)) { + if ( + (online && (areEnemies ? Conf.territoryEnemyDenyBuild : Conf.territoryDenyBuild)) + || (!online && (areEnemies ? Conf.territoryEnemyDenyBuildWhenOffline : Conf.territoryDenyBuildWhenOffline)) + ) { me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction)); return false; } diff --git a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java index 6b7c9461..db538a90 100644 --- a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java @@ -287,9 +287,10 @@ public class FactionsPlayerListener extends PlayerListener{ } Faction myFaction = me.getFaction(); + boolean areEnemies = myFaction.getRelation(otherFaction).isEnemy(); // Cancel if we are not in our own territory - if (myFaction != otherFaction && Conf.territoryDenyUseage) { + if (myFaction != otherFaction && (areEnemies ? Conf.territoryEnemyDenyUseage : Conf.territoryDenyUseage)) { me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); return false; } @@ -321,6 +322,10 @@ public class FactionsPlayerListener extends PlayerListener{ FPlayer me = FPlayer.get(player); Faction myFaction = me.getFaction(); + if (myFaction.getRelation(otherFaction).isEnemy() && !Conf.territoryEnemyProtectMaterials) { + return true; + } + // You may use any block unless it is another faction's territory... if (otherFaction.isNormal() && myFaction != otherFaction) { me.sendMessage("You can't use "+TextUtil.getMaterialName(material)+" in the territory of "+otherFaction.getTag(myFaction)); diff --git a/src/org/mcteam/factions/struct/Relation.java b/src/org/mcteam/factions/struct/Relation.java index 17565050..f3233e19 100644 --- a/src/org/mcteam/factions/struct/Relation.java +++ b/src/org/mcteam/factions/struct/Relation.java @@ -23,6 +23,22 @@ public enum Relation { return this.nicename; } + public boolean isMember() { + return this == Relation.MEMBER; + } + + public boolean isAlly() { + return this == Relation.ALLY; + } + + public boolean isNeutral() { + return this == Relation.NEUTRAL; + } + + public boolean isEnemy() { + return this == Relation.ENEMY; + } + public ChatColor getColor() { if (this == Relation.MEMBER) { return Conf.colorMember;