package com.massivecraft.factions.entity; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.store.MStore; import com.massivecraft.mcore.store.SenderColl; import com.massivecraft.mcore.util.TimeUnit; import com.massivecraft.mcore.util.Txt; public class UPlayerColl extends SenderColl { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public UPlayerColl(String name) { super(name, UPlayer.class, MStore.getDb(ConfServer.dburi), Factions.get()); } // -------------------------------------------- // // EXTRAS // -------------------------------------------- // public void clean() { FactionColl factionColl = FactionColls.get().get(this); String universe = this.getUniverse(); for (UPlayer uplayer : this.getAll()) { String factionId = uplayer.getFactionId(); if (factionColl.containsId(factionId)) continue; uplayer.resetFactionData(); String message = Txt.parse("Reset data for %s in %s universe. Unknown factionId %s", uplayer.getDisplayName(), universe, factionId); Factions.get().log(message); } } public void removePlayerDataAfterInactiveDaysRoutine() { if (MConf.get().removePlayerDataAfterInactiveDays <= 0.0) return; long now = System.currentTimeMillis(); double toleranceMillis = MConf.get().removePlayerDataAfterInactiveDays * TimeUnit.MILLIS_PER_DAY; for (UPlayer uplayer : this.getAll()) { Long lastPlayed = Mixin.getLastPlayed(uplayer.getId()); if (lastPlayed == null) continue; if (uplayer.isOnline()) continue; if (now - lastPlayed <= toleranceMillis) continue; if (MConf.get().logFactionLeave || MConf.get().logFactionKick) { Factions.get().log("Player "+uplayer.getName()+" was auto-removed due to inactivity."); } // if player is faction leader, sort out the faction since he's going away if (uplayer.getRole() == Rel.LEADER) { Faction faction = uplayer.getFaction(); if (faction != null) { uplayer.getFaction().promoteNewLeader(); } } uplayer.leave(); uplayer.detach(); } } }