From 60227b6dc41e6d50b6bd3fe44c9607c1116a858a Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 21 Jun 2011 00:20:36 -0500 Subject: [PATCH] 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 --- src/org/mcteam/factions/Conf.java | 2 ++ src/org/mcteam/factions/Faction.java | 18 ++++++++++++++++-- src/org/mcteam/factions/Factions.java | 12 ++++++++++++ .../listeners/FactionsBlockListener.java | 2 +- .../listeners/FactionsEntityListener.java | 4 ++-- .../listeners/FactionsPlayerListener.java | 5 +++-- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/org/mcteam/factions/Conf.java b/src/org/mcteam/factions/Conf.java index 6ff36dd5..f6043f68 100644 --- a/src/org/mcteam/factions/Conf.java +++ b/src/org/mcteam/factions/Conf.java @@ -70,6 +70,8 @@ public class Conf { public static boolean claimsMustBeConnected = false; + public static double considerFactionsReallyOfflineAfterXMinutes = 0; + public static double territoryShieldFactor = 0.3; public static boolean territoryDenyBuild = true; public static boolean territoryDenyBuildWhenOffline = true; diff --git a/src/org/mcteam/factions/Faction.java b/src/org/mcteam/factions/Faction.java index 4e97e95d..36f119f9 100644 --- a/src/org/mcteam/factions/Faction.java +++ b/src/org/mcteam/factions/Faction.java @@ -32,6 +32,7 @@ public class Faction { private String tag; private String description; private Location home; + private transient long lastPlayerLoggedOffTime; // -------------------------------------------- // // Construct @@ -43,6 +44,7 @@ public class Faction { this.open = Conf.newFactionsDefaultOpen; this.tag = "???"; 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 - public boolean HasPlayersOnline() { - // only real factions can have players online, not wilderness / safe zone / war zone + public boolean hasPlayersOnline() { + // only real factions can have players online, not safe zone / war zone if (id < 0) return false; @@ -280,9 +282,21 @@ public class Faction { 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; } + public void memberLoggedOff() { + if (this.isNormal()) { + lastPlayerLoggedOffTime = System.currentTimeMillis(); + } + } + //----------------------------------------------// // Faction tag //----------------------------------------------// diff --git a/src/org/mcteam/factions/Factions.java b/src/org/mcteam/factions/Factions.java index 014e2295..58fe4e3f 100644 --- a/src/org/mcteam/factions/Factions.java +++ b/src/org/mcteam/factions/Factions.java @@ -240,6 +240,18 @@ public class Factions extends JavaPlugin { 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 // -------------------------------------------- // diff --git a/src/org/mcteam/factions/listeners/FactionsBlockListener.java b/src/org/mcteam/factions/listeners/FactionsBlockListener.java index abacd284..c3faf3c4 100644 --- a/src/org/mcteam/factions/listeners/FactionsBlockListener.java +++ b/src/org/mcteam/factions/listeners/FactionsBlockListener.java @@ -93,7 +93,7 @@ public class FactionsBlockListener extends BlockListener { // Cancel if we are not in our own territory if (myFaction != otherFaction) { - boolean online = otherFaction.HasPlayersOnline(); + 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; diff --git a/src/org/mcteam/factions/listeners/FactionsEntityListener.java b/src/org/mcteam/factions/listeners/FactionsEntityListener.java index 08adbef2..ad1e8ddc 100644 --- a/src/org/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/org/mcteam/factions/listeners/FactionsEntityListener.java @@ -93,7 +93,7 @@ public class FactionsEntityListener extends EntityListener { } Faction faction = Board.getFactionAt(new FLocation(event.getLocation())); - boolean online = faction.HasPlayersOnline(); + boolean online = faction.hasPlayersOnline(); if (event.getEntity() instanceof Creeper && ( (faction.isNone() && Conf.wildernessBlockCreepers) || @@ -317,7 +317,7 @@ public class FactionsEntityListener extends EntityListener { // Cancel if we are not in our own territory if (myFaction != otherFaction) { - boolean online = otherFaction.HasPlayersOnline(); + 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; diff --git a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java index 9416634a..98d13e49 100644 --- a/src/org/mcteam/factions/listeners/FactionsPlayerListener.java +++ b/src/org/mcteam/factions/listeners/FactionsPlayerListener.java @@ -141,6 +141,7 @@ public class FactionsPlayerListener extends PlayerListener{ // Make sure player's power is up to date when they log off. FPlayer me = FPlayer.get(event.getPlayer()); me.getPower(); + me.getFaction().memberLoggedOff(); } @Override @@ -251,7 +252,7 @@ public class FactionsPlayerListener extends PlayerListener{ Faction otherFaction = Board.getFactionAt(new FLocation(block)); - if (otherFaction.HasPlayersOnline()){ + if (otherFaction.hasPlayersOnline()){ if ( ! Conf.territoryDenyUseageMaterials.contains(material)) { 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)); // We only care about some material types. - if (otherFaction.HasPlayersOnline()){ + if (otherFaction.hasPlayersOnline()){ if ( ! Conf.territoryProtectedMaterials.contains(material)) { return true; }