"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:
		@@ -81,6 +81,7 @@ public class Conf
 | 
			
		||||
	public static String allianceChatFormat = ChatColor.LIGHT_PURPLE+"%s:"+ChatColor.WHITE+" %s";
 | 
			
		||||
	
 | 
			
		||||
	public static double autoLeaveAfterDaysOfInactivity = 10.0;
 | 
			
		||||
	public static double autoLeaveRoutineRunsEveryXMinutes = 5.0;
 | 
			
		||||
	public static boolean removePlayerDataWhenBanned = true;
 | 
			
		||||
 | 
			
		||||
	public static boolean worldGuardChecking = false;
 | 
			
		||||
 
 | 
			
		||||
@@ -60,7 +60,7 @@ public class FPlayers extends PlayerEntityCollection<FPlayer>
 | 
			
		||||
		
 | 
			
		||||
		for (FPlayer fplayer : FPlayers.i.get())
 | 
			
		||||
		{
 | 
			
		||||
			if (now - fplayer.getLastLoginTime() > toleranceMillis)
 | 
			
		||||
			if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis)
 | 
			
		||||
			{
 | 
			
		||||
				if (Conf.logFactionLeave || Conf.logFactionKick)
 | 
			
		||||
					P.p.log("Player "+fplayer.getName()+" was auto-removed due to inactivity.");
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,7 @@ import com.massivecraft.factions.struct.ChatMode;
 | 
			
		||||
import com.massivecraft.factions.struct.FFlag;
 | 
			
		||||
import com.massivecraft.factions.struct.FPerm;
 | 
			
		||||
import com.massivecraft.factions.struct.Rel;
 | 
			
		||||
import com.massivecraft.factions.util.AutoLeaveTask;
 | 
			
		||||
import com.massivecraft.factions.zcore.MPlugin;
 | 
			
		||||
 | 
			
		||||
import com.google.gson.GsonBuilder;
 | 
			
		||||
@@ -56,6 +57,7 @@ public class P extends MPlugin
 | 
			
		||||
	private boolean locked = false;
 | 
			
		||||
	public boolean getLocked() {return this.locked;}
 | 
			
		||||
	public void setLocked(boolean val) {this.locked = val; this.setAutoSave(val);}
 | 
			
		||||
	private Integer AutoLeaveTask = null;
 | 
			
		||||
	
 | 
			
		||||
	// Commands
 | 
			
		||||
	public FCmdRoot cmdBase;
 | 
			
		||||
@@ -99,6 +101,9 @@ public class P extends MPlugin
 | 
			
		||||
			Worldguard.init(this);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// start up task which runs the autoLeaveAfterDaysOfInactivity routine
 | 
			
		||||
		startAutoLeaveTask(false);
 | 
			
		||||
 | 
			
		||||
		// Register Event Handlers
 | 
			
		||||
		getServer().getPluginManager().registerEvents(playerListener, this);
 | 
			
		||||
		getServer().getPluginManager().registerEvents(chatEarlyListener, this);
 | 
			
		||||
@@ -131,9 +136,29 @@ public class P extends MPlugin
 | 
			
		||||
		Board.save();
 | 
			
		||||
		Conf.save();
 | 
			
		||||
		EssentialsFeatures.unhookChat();
 | 
			
		||||
		if (AutoLeaveTask != null)
 | 
			
		||||
		{
 | 
			
		||||
			this.getServer().getScheduler().cancelTask(AutoLeaveTask);
 | 
			
		||||
			AutoLeaveTask = null;
 | 
			
		||||
		}
 | 
			
		||||
		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
 | 
			
		||||
	public void postAutoSave()
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -150,10 +150,12 @@ public class FactionsPlayerListener implements Listener
 | 
			
		||||
		
 | 
			
		||||
		// Update the lastLoginTime for this fplayer
 | 
			
		||||
		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...
 | 
			
		||||
		FPlayers.i.autoLeaveOnInactivityRoutine();
 | 
			
		||||
		FPlayers.i.autoLeaveOnInactivityRoutine();
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
		SpoutFeatures.updateAppearancesShortly(event.getPlayer());
 | 
			
		||||
	}
 | 
			
		||||
@@ -161,9 +163,13 @@ public class FactionsPlayerListener implements Listener
 | 
			
		||||
	@EventHandler(priority = EventPriority.NORMAL)
 | 
			
		||||
    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());
 | 
			
		||||
 | 
			
		||||
		// Make sure player's power is up to date when they log off.
 | 
			
		||||
		me.getPower();
 | 
			
		||||
		// and update their last login time to point to when the logged off, for auto-remove routine
 | 
			
		||||
		me.setLastLoginTime(System.currentTimeMillis());
 | 
			
		||||
 | 
			
		||||
		SpoutFeatures.playerDisconnect(me);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								src/com/massivecraft/factions/util/AutoLeaveTask.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/com/massivecraft/factions/util/AutoLeaveTask.java
									
									
									
									
									
										Normal 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);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user