"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:
parent
cbd2507676
commit
84ee922ac1
@ -70,6 +70,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.");
|
||||
|
@ -27,6 +27,7 @@ import com.massivecraft.factions.listeners.FactionsEntityListener;
|
||||
import com.massivecraft.factions.listeners.FactionsPlayerListener;
|
||||
import com.massivecraft.factions.listeners.FactionsServerListener;
|
||||
import com.massivecraft.factions.struct.ChatMode;
|
||||
import com.massivecraft.factions.util.AutoLeaveTask;
|
||||
import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
|
||||
import com.massivecraft.factions.util.MyLocationTypeAdapter;
|
||||
import com.massivecraft.factions.zcore.MPlugin;
|
||||
@ -51,6 +52,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;
|
||||
@ -94,6 +96,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);
|
||||
@ -123,9 +128,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()
|
||||
{
|
||||
|
@ -151,10 +151,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());
|
||||
}
|
||||
@ -162,9 +164,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());
|
||||
|
||||
Faction myFaction = me.getFaction();
|
||||
if (myFaction != null)
|
||||
{
|
||||
|
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user