package com.massivecraft.factions; import java.io.File; import java.lang.reflect.Type; import java.util.Map; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.CopyOnWriteArrayList; import com.massivecraft.mcore.xlib.gson.reflect.TypeToken; import com.massivecraft.factions.zcore.persist.PlayerEntityCollection; public class FPlayerColl extends PlayerEntityCollection { public static FPlayerColl i = new FPlayerColl(); private FPlayerColl() { super ( FPlayer.class, new CopyOnWriteArrayList(), new ConcurrentSkipListMap(String.CASE_INSENSITIVE_ORDER), new File(Factions.get().getDataFolder(), "players.json"), Factions.get().gson ); this.setCreative(true); } @Override public Type getMapType() { return new TypeToken>(){}.getType(); } public void clean() { for (FPlayer fplayer : this.get()) { if ( ! FactionColl.i.exists(fplayer.getFactionId())) { Factions.get().log("Reset faction data (invalid faction) for player "+fplayer.getName()); fplayer.resetFactionData(false); } } } public void autoLeaveOnInactivityRoutine() { if (ConfServer.autoLeaveAfterDaysOfInactivity <= 0.0) { return; } long now = System.currentTimeMillis(); double toleranceMillis = ConfServer.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000; for (FPlayer fplayer : FPlayerColl.i.get()) { if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) { if (ConfServer.logFactionLeave || ConfServer.logFactionKick) Factions.get().log("Player "+fplayer.getName()+" was auto-removed due to inactivity."); // if player is faction leader, sort out the faction since he's going away if (fplayer.getRole() == Rel.LEADER) { Faction faction = fplayer.getFaction(); if (faction != null) fplayer.getFaction().promoteNewLeader(); } fplayer.leave(false); fplayer.detach(); } } } }