Added new "territoryDenyBuildWhenOffline" option to go with other two new offline prevention options by thomastanck; slight speed improvement for offline check

This commit is contained in:
Brettflan 2011-06-10 14:14:02 -05:00
parent cbd0ee42ba
commit 7ab0d700cc
5 changed files with 45 additions and 10 deletions

View File

@ -65,6 +65,7 @@ public class Conf {
public static double territoryShieldFactor = 0.3;
public static boolean territoryDenyBuild = true;
public static boolean territoryDenyBuildWhenOffline = true;
public static boolean territoryDenyUseage = true;
public static boolean territoryBlockCreepers = false;
public static boolean territoryBlockFireballs = false;

View File

@ -213,26 +213,36 @@ public class Faction {
public ArrayList<FPlayer> getFPlayers() {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (id <= 0)
return ret;
for (FPlayer fplayer : FPlayer.getAll()) {
if (fplayer.getFaction() == this) {
ret.add(fplayer);
}
}
return ret;
}
public ArrayList<FPlayer> getFPlayersWhereOnline(boolean online) {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (id <= 0)
return ret;
for (FPlayer fplayer : FPlayer.getAll()) {
if (fplayer.getFaction() == this && fplayer.isOnline() == online) {
ret.add(fplayer);
}
}
return ret;
}
public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (id <= 0)
return ret;
for (FPlayer fplayer : FPlayer.getAll()) {
if (fplayer.getFaction() == this && fplayer.getRole() == role) {
@ -245,15 +255,34 @@ public class Faction {
public ArrayList<Player> getOnlinePlayers() {
ArrayList<Player> ret = new ArrayList<Player>();
if (id <= 0)
return ret;
for (Player player: Factions.instance.getServer().getOnlinePlayers()) {
FPlayer fplayer = FPlayer.get(player);
if (fplayer.getFaction() == this) {
ret.add(player);
}
}
return ret;
}
// slightly faster check than getOnlinePlayers() if you just want to see if there are any players online
public boolean HasPlayersOnline() {
// only real factions can have players online, not wilderness / safe zone / war zone
if (id <= 0)
return false;
for (Player player: Factions.instance.getServer().getOnlinePlayers()) {
FPlayer fplayer = FPlayer.get(player);
if (fplayer.getFaction() == this) {
return true;
}
}
return false;
}
//----------------------------------------------//
// Faction tag
//----------------------------------------------//

View File

@ -88,9 +88,12 @@ public class FactionsBlockListener extends BlockListener {
Faction myFaction = me.getFaction();
// Cancel if we are not in our own territory
if (myFaction != otherFaction && Conf.territoryDenyBuild) {
me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
return false;
if (myFaction != otherFaction) {
boolean online = otherFaction.HasPlayersOnline();
if ((online && Conf.territoryDenyBuild) || (!online && Conf.territoryDenyBuildWhenOffline)) {
me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
return false;
}
}
return true;

View File

@ -303,9 +303,12 @@ public class FactionsEntityListener extends EntityListener {
Faction myFaction = me.getFaction();
// Cancel if we are not in our own territory
if (myFaction != otherFaction && Conf.territoryDenyBuild) {
me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction));
return false;
if (myFaction != otherFaction) {
boolean online = otherFaction.HasPlayersOnline();
if ((online && Conf.territoryDenyBuild) || (!online && Conf.territoryDenyBuildWhenOffline)) {
me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction));
return false;
}
}
return true;

View File

@ -204,7 +204,7 @@ public class FactionsPlayerListener extends PlayerListener{
Faction otherFaction = Board.getFactionAt(new FLocation(block));
if (otherFaction.getOnlinePlayers()!=null){
if (otherFaction.HasPlayersOnline()){
if ( ! Conf.territoryDenyUseageMaterials.contains(material)) {
return true; // Item isn't one we're preventing for online factions.
}
@ -261,7 +261,7 @@ public class FactionsPlayerListener extends PlayerListener{
Faction otherFaction = Board.getFactionAt(new FLocation(block));
// We only care about some material types.
if (otherFaction.getOnlinePlayers()!=null){
if (otherFaction.HasPlayersOnline()){
if ( ! Conf.territoryProtectedMaterials.contains(material)) {
return true;
}
@ -274,13 +274,12 @@ public class FactionsPlayerListener extends PlayerListener{
FPlayer me = FPlayer.get(player);
Faction myFaction = me.getFaction();
// In safe zones you may use any block...
// 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));
return false;
}
// You may use doors in both safeZone and wilderness
return true;
}