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 double territoryShieldFactor = 0.3;
public static boolean territoryDenyBuild = true; public static boolean territoryDenyBuild = true;
public static boolean territoryDenyBuildWhenOffline = true;
public static boolean territoryDenyUseage = true; public static boolean territoryDenyUseage = true;
public static boolean territoryBlockCreepers = false; public static boolean territoryBlockCreepers = false;
public static boolean territoryBlockFireballs = false; public static boolean territoryBlockFireballs = false;

View File

@ -213,26 +213,36 @@ public class Faction {
public ArrayList<FPlayer> getFPlayers() { public ArrayList<FPlayer> getFPlayers() {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>(); ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (id <= 0)
return ret;
for (FPlayer fplayer : FPlayer.getAll()) { for (FPlayer fplayer : FPlayer.getAll()) {
if (fplayer.getFaction() == this) { if (fplayer.getFaction() == this) {
ret.add(fplayer); ret.add(fplayer);
} }
} }
return ret; return ret;
} }
public ArrayList<FPlayer> getFPlayersWhereOnline(boolean online) { public ArrayList<FPlayer> getFPlayersWhereOnline(boolean online) {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>(); ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (id <= 0)
return ret;
for (FPlayer fplayer : FPlayer.getAll()) { for (FPlayer fplayer : FPlayer.getAll()) {
if (fplayer.getFaction() == this && fplayer.isOnline() == online) { if (fplayer.getFaction() == this && fplayer.isOnline() == online) {
ret.add(fplayer); ret.add(fplayer);
} }
} }
return ret; return ret;
} }
public ArrayList<FPlayer> getFPlayersWhereRole(Role role) { public ArrayList<FPlayer> getFPlayersWhereRole(Role role) {
ArrayList<FPlayer> ret = new ArrayList<FPlayer>(); ArrayList<FPlayer> ret = new ArrayList<FPlayer>();
if (id <= 0)
return ret;
for (FPlayer fplayer : FPlayer.getAll()) { for (FPlayer fplayer : FPlayer.getAll()) {
if (fplayer.getFaction() == this && fplayer.getRole() == role) { if (fplayer.getFaction() == this && fplayer.getRole() == role) {
@ -245,15 +255,34 @@ public class Faction {
public ArrayList<Player> getOnlinePlayers() { public ArrayList<Player> getOnlinePlayers() {
ArrayList<Player> ret = new ArrayList<Player>(); ArrayList<Player> ret = new ArrayList<Player>();
if (id <= 0)
return ret;
for (Player player: Factions.instance.getServer().getOnlinePlayers()) { for (Player player: Factions.instance.getServer().getOnlinePlayers()) {
FPlayer fplayer = FPlayer.get(player); FPlayer fplayer = FPlayer.get(player);
if (fplayer.getFaction() == this) { if (fplayer.getFaction() == this) {
ret.add(player); ret.add(player);
} }
} }
return ret; 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 // Faction tag
//----------------------------------------------// //----------------------------------------------//

View File

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

View File

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

View File

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