Added option "considerFactionsReallyOfflineAfterXMinutes" (default 0.0, immediately) which makes all "Offline" options still consider the faction as having members online until X minutes after the last one logs off

This commit is contained in:
Brettflan 2011-06-21 00:20:36 -05:00
parent 8880d503e2
commit 60227b6dc4
6 changed files with 36 additions and 7 deletions

View File

@ -70,6 +70,8 @@ public class Conf {
public static boolean claimsMustBeConnected = false; public static boolean claimsMustBeConnected = false;
public static double considerFactionsReallyOfflineAfterXMinutes = 0;
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 territoryDenyBuildWhenOffline = true;

View File

@ -32,6 +32,7 @@ public class Faction {
private String tag; private String tag;
private String description; private String description;
private Location home; private Location home;
private transient long lastPlayerLoggedOffTime;
// -------------------------------------------- // // -------------------------------------------- //
// Construct // Construct
@ -43,6 +44,7 @@ public class Faction {
this.open = Conf.newFactionsDefaultOpen; this.open = Conf.newFactionsDefaultOpen;
this.tag = "???"; this.tag = "???";
this.description = "Default faction description :("; this.description = "Default faction description :(";
this.lastPlayerLoggedOffTime = 0;
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -269,8 +271,8 @@ public class Faction {
} }
// slightly faster check than getOnlinePlayers() if you just want to see if there are any players online // slightly faster check than getOnlinePlayers() if you just want to see if there are any players online
public boolean HasPlayersOnline() { public boolean hasPlayersOnline() {
// only real factions can have players online, not wilderness / safe zone / war zone // only real factions can have players online, not safe zone / war zone
if (id < 0) if (id < 0)
return false; return false;
@ -280,9 +282,21 @@ public class Faction {
return true; return true;
} }
} }
// even if all players are technically logged off, maybe someone was on recently enough to not consider them officially offline yet
if (Conf.considerFactionsReallyOfflineAfterXMinutes > 0 &&
System.currentTimeMillis() < lastPlayerLoggedOffTime + (Conf.considerFactionsReallyOfflineAfterXMinutes * 60000)) {
return true;
}
return false; return false;
} }
public void memberLoggedOff() {
if (this.isNormal()) {
lastPlayerLoggedOffTime = System.currentTimeMillis();
}
}
//----------------------------------------------// //----------------------------------------------//
// Faction tag // Faction tag
//----------------------------------------------// //----------------------------------------------//

View File

@ -240,6 +240,18 @@ public class Factions extends JavaPlugin {
return me.getChatTag(you).trim(); return me.getChatTag(you).trim();
} }
// Get a player's title within their faction, mainly for usage by chat plugins for local/channel chat
public static String getPlayerTitle(Player player) {
if (player == null)
return "";
FPlayer me = FPlayer.get(player);
if (me == null)
return "";
return me.getTitle().trim();
}
// -------------------------------------------- // // -------------------------------------------- //
// Test rights // Test rights
// -------------------------------------------- // // -------------------------------------------- //

View File

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

View File

@ -93,7 +93,7 @@ public class FactionsEntityListener extends EntityListener {
} }
Faction faction = Board.getFactionAt(new FLocation(event.getLocation())); Faction faction = Board.getFactionAt(new FLocation(event.getLocation()));
boolean online = faction.HasPlayersOnline(); boolean online = faction.hasPlayersOnline();
if (event.getEntity() instanceof Creeper && ( if (event.getEntity() instanceof Creeper && (
(faction.isNone() && Conf.wildernessBlockCreepers) || (faction.isNone() && Conf.wildernessBlockCreepers) ||
@ -317,7 +317,7 @@ public class FactionsEntityListener extends EntityListener {
// Cancel if we are not in our own territory // Cancel if we are not in our own territory
if (myFaction != otherFaction) { if (myFaction != otherFaction) {
boolean online = otherFaction.HasPlayersOnline(); boolean online = otherFaction.hasPlayersOnline();
if ((online && Conf.territoryDenyBuild) || (!online && Conf.territoryDenyBuildWhenOffline)) { if ((online && Conf.territoryDenyBuild) || (!online && Conf.territoryDenyBuildWhenOffline)) {
me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction)); me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction));
return false; return false;

View File

@ -141,6 +141,7 @@ public class FactionsPlayerListener extends PlayerListener{
// Make sure player's power is up to date when they log off. // Make sure player's power is up to date when they log off.
FPlayer me = FPlayer.get(event.getPlayer()); FPlayer me = FPlayer.get(event.getPlayer());
me.getPower(); me.getPower();
me.getFaction().memberLoggedOff();
} }
@Override @Override
@ -251,7 +252,7 @@ public class FactionsPlayerListener extends PlayerListener{
Faction otherFaction = Board.getFactionAt(new FLocation(block)); Faction otherFaction = Board.getFactionAt(new FLocation(block));
if (otherFaction.HasPlayersOnline()){ 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.
} }
@ -307,7 +308,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.HasPlayersOnline()){ if (otherFaction.hasPlayersOnline()){
if ( ! Conf.territoryProtectedMaterials.contains(material)) { if ( ! Conf.territoryProtectedMaterials.contains(material)) {
return true; return true;
} }