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.
This commit is contained in:
Brettflan 2011-07-09 01:36:18 -05:00
parent 787e6b867a
commit d69b278728
6 changed files with 42 additions and 10 deletions

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));

View File

@ -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;