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:
parent
8880d503e2
commit
60227b6dc4
@ -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;
|
||||
|
@ -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
|
||||
//----------------------------------------------//
|
||||
|
@ -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
|
||||
// -------------------------------------------- //
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user