Factions3/src/com/massivecraft/factions/FPlayerColl.java

81 lines
2.1 KiB
Java
Raw Normal View History

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 org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.zcore.persist.PlayerEntityCollection;
2013-04-09 13:22:23 +02:00
public class FPlayerColl extends PlayerEntityCollection<FPlayer>
{
2013-04-09 13:22:23 +02:00
public static FPlayerColl i = new FPlayerColl();
Factions p = Factions.get();
2013-04-09 13:22:23 +02:00
private FPlayerColl()
{
super
(
FPlayer.class,
new CopyOnWriteArrayList<FPlayer>(),
new ConcurrentSkipListMap<String, FPlayer>(String.CASE_INSENSITIVE_ORDER),
new File(Factions.get().getDataFolder(), "players.json"),
Factions.get().gson
);
this.setCreative(true);
}
@Override
public Type getMapType()
{
return new TypeToken<Map<String, FPlayer>>(){}.getType();
}
public void clean()
{
for (FPlayer fplayer : this.get())
{
2013-04-09 12:58:39 +02:00
if ( ! FactionColl.i.exists(fplayer.getFactionId()))
{
p.log("Reset faction data (invalid faction) for player "+fplayer.getName());
fplayer.resetFactionData(false);
}
}
}
public void autoLeaveOnInactivityRoutine()
{
2013-04-09 13:15:25 +02:00
if (ConfServer.autoLeaveAfterDaysOfInactivity <= 0.0)
{
return;
}
long now = System.currentTimeMillis();
2013-04-09 13:15:25 +02:00
double toleranceMillis = ConfServer.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
2013-04-09 13:22:23 +02:00
for (FPlayer fplayer : FPlayerColl.i.get())
{
if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis)
{
2013-04-09 13:15:25 +02:00
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();
}
}
}
}