Factions3/src/com/massivecraft/factions/entity/UPlayerColl.java

77 lines
2.3 KiB
Java
Raw Normal View History

2013-04-22 09:37:53 +02:00
package com.massivecraft.factions.entity;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.store.SenderColl;
import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt;
public class UPlayerColl extends SenderColl<UPlayer>
{
2013-04-12 08:56:26 +02:00
// -------------------------------------------- //
// CONSTRUCT
2013-04-12 08:56:26 +02:00
// -------------------------------------------- //
public UPlayerColl(String name)
{
2013-11-11 09:31:04 +01:00
super(name, UPlayer.class, MStore.getDb(), Factions.get());
}
2013-04-12 08:56:26 +02:00
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public void clean()
{
2013-04-25 16:02:37 +02:00
FactionColl factionColl = FactionColls.get().get(this);
String universe = this.getUniverse();
for (UPlayer uplayer : this.getAll())
{
2013-04-25 16:02:37 +02:00
String factionId = uplayer.getFactionId();
if (factionColl.containsId(factionId)) continue;
2013-04-25 16:02:37 +02:00
uplayer.resetFactionData();
String message = Txt.parse("<i>Reset data for <h>%s <i>in <h>%s <i>universe. Unknown factionId <h>%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();
}
}
}