"autoLeaveAfterDaysOfInactivity" routine now runs only once every few minutes instead of running every time a player logs in. New setting "autoLeaveRoutineRunsEveryXMinutes" (default 5 minutes) to determine just how often the routine is run.

The routine is also slightly more careful about how it calculates how long a player has been offline.
This commit is contained in:
Brettflan 2012-02-26 16:55:57 -06:00
parent cbd2507676
commit 84ee922ac1
5 changed files with 60 additions and 4 deletions

View File

@ -70,6 +70,7 @@ public class Conf
public static String allianceChatFormat = ChatColor.LIGHT_PURPLE+"%s:"+ChatColor.WHITE+" %s"; public static String allianceChatFormat = ChatColor.LIGHT_PURPLE+"%s:"+ChatColor.WHITE+" %s";
public static double autoLeaveAfterDaysOfInactivity = 10.0; public static double autoLeaveAfterDaysOfInactivity = 10.0;
public static double autoLeaveRoutineRunsEveryXMinutes = 5.0;
public static boolean removePlayerDataWhenBanned = true; public static boolean removePlayerDataWhenBanned = true;
public static boolean worldGuardChecking = false; public static boolean worldGuardChecking = false;

View File

@ -60,7 +60,7 @@ public class FPlayers extends PlayerEntityCollection<FPlayer>
for (FPlayer fplayer : FPlayers.i.get()) for (FPlayer fplayer : FPlayers.i.get())
{ {
if (now - fplayer.getLastLoginTime() > toleranceMillis) if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis)
{ {
if (Conf.logFactionLeave || Conf.logFactionKick) if (Conf.logFactionLeave || Conf.logFactionKick)
P.p.log("Player "+fplayer.getName()+" was auto-removed due to inactivity."); P.p.log("Player "+fplayer.getName()+" was auto-removed due to inactivity.");

View File

@ -27,6 +27,7 @@ import com.massivecraft.factions.listeners.FactionsEntityListener;
import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.listeners.FactionsPlayerListener;
import com.massivecraft.factions.listeners.FactionsServerListener; import com.massivecraft.factions.listeners.FactionsServerListener;
import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.util.AutoLeaveTask;
import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter; import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
import com.massivecraft.factions.util.MyLocationTypeAdapter; import com.massivecraft.factions.util.MyLocationTypeAdapter;
import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.MPlugin;
@ -51,6 +52,7 @@ public class P extends MPlugin
private boolean locked = false; private boolean locked = false;
public boolean getLocked() {return this.locked;} public boolean getLocked() {return this.locked;}
public void setLocked(boolean val) {this.locked = val; this.setAutoSave(val);} public void setLocked(boolean val) {this.locked = val; this.setAutoSave(val);}
private Integer AutoLeaveTask = null;
// Commands // Commands
public FCmdRoot cmdBase; public FCmdRoot cmdBase;
@ -94,6 +96,9 @@ public class P extends MPlugin
Worldguard.init(this); Worldguard.init(this);
} }
// start up task which runs the autoLeaveAfterDaysOfInactivity routine
startAutoLeaveTask(false);
// Register Event Handlers // Register Event Handlers
getServer().getPluginManager().registerEvents(playerListener, this); getServer().getPluginManager().registerEvents(playerListener, this);
getServer().getPluginManager().registerEvents(chatEarlyListener, this); getServer().getPluginManager().registerEvents(chatEarlyListener, this);
@ -123,9 +128,29 @@ public class P extends MPlugin
Board.save(); Board.save();
Conf.save(); Conf.save();
EssentialsFeatures.unhookChat(); EssentialsFeatures.unhookChat();
if (AutoLeaveTask != null)
{
this.getServer().getScheduler().cancelTask(AutoLeaveTask);
AutoLeaveTask = null;
}
super.onDisable(); super.onDisable();
} }
public void startAutoLeaveTask(boolean restartIfRunning)
{
if (AutoLeaveTask != null)
{
if ( ! restartIfRunning) return;
this.getServer().getScheduler().cancelTask(AutoLeaveTask);
}
if (Conf.autoLeaveRoutineRunsEveryXMinutes > 0.0)
{
long ticks = (long)(20 * 60 * Conf.autoLeaveRoutineRunsEveryXMinutes);
AutoLeaveTask = getServer().getScheduler().scheduleSyncRepeatingTask(this, new AutoLeaveTask(), ticks, ticks);
}
}
@Override @Override
public void postAutoSave() public void postAutoSave()
{ {

View File

@ -152,9 +152,11 @@ public class FactionsPlayerListener implements Listener
// Update the lastLoginTime for this fplayer // Update the lastLoginTime for this fplayer
me.setLastLoginTime(System.currentTimeMillis()); me.setLastLoginTime(System.currentTimeMillis());
/* This is now done in a separate task which runs every few minutes
// Run the member auto kick routine. Twice to get to the admins... // Run the member auto kick routine. Twice to get to the admins...
FPlayers.i.autoLeaveOnInactivityRoutine(); FPlayers.i.autoLeaveOnInactivityRoutine();
FPlayers.i.autoLeaveOnInactivityRoutine(); FPlayers.i.autoLeaveOnInactivityRoutine();
*/
SpoutFeatures.updateAppearancesShortly(event.getPlayer()); SpoutFeatures.updateAppearancesShortly(event.getPlayer());
} }
@ -162,9 +164,13 @@ public class FactionsPlayerListener implements Listener
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(PlayerQuitEvent event) public void onPlayerQuit(PlayerQuitEvent event)
{ {
// Make sure player's power is up to date when they log off.
FPlayer me = FPlayers.i.get(event.getPlayer()); FPlayer me = FPlayers.i.get(event.getPlayer());
// Make sure player's power is up to date when they log off.
me.getPower(); me.getPower();
// and update their last login time to point to when the logged off, for auto-remove routine
me.setLastLoginTime(System.currentTimeMillis());
Faction myFaction = me.getFaction(); Faction myFaction = me.getFaction();
if (myFaction != null) if (myFaction != null)
{ {

View File

@ -0,0 +1,24 @@
package com.massivecraft.factions.util;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.P;
public class AutoLeaveTask implements Runnable
{
double rate;
public AutoLeaveTask()
{
this.rate = Conf.autoLeaveRoutineRunsEveryXMinutes;
}
public void run()
{
FPlayers.i.autoLeaveOnInactivityRoutine();
// maybe setting has been changed? if so, restart task at new rate
if (this.rate != Conf.autoLeaveRoutineRunsEveryXMinutes)
P.p.startAutoLeaveTask(true);
}
}