2011-10-08 22:03:44 +02:00
|
|
|
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;
|
|
|
|
|
2012-08-26 08:02:31 +02:00
|
|
|
import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken;
|
2011-12-18 14:50:41 +01:00
|
|
|
import com.massivecraft.factions.struct.Rel;
|
2011-10-08 22:03:44 +02:00
|
|
|
import com.massivecraft.factions.zcore.persist.PlayerEntityCollection;
|
|
|
|
|
|
|
|
public class FPlayers extends PlayerEntityCollection<FPlayer>
|
|
|
|
{
|
|
|
|
public static FPlayers i = new FPlayers();
|
|
|
|
|
|
|
|
P p = P.p;
|
|
|
|
|
|
|
|
private FPlayers()
|
|
|
|
{
|
|
|
|
super
|
|
|
|
(
|
|
|
|
FPlayer.class,
|
|
|
|
new CopyOnWriteArrayList<FPlayer>(),
|
|
|
|
new ConcurrentSkipListMap<String, FPlayer>(String.CASE_INSENSITIVE_ORDER),
|
|
|
|
new File(P.p.getDataFolder(), "players.json"),
|
|
|
|
P.p.gson
|
|
|
|
);
|
|
|
|
|
|
|
|
this.setCreative(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Type getMapType()
|
|
|
|
{
|
|
|
|
return new TypeToken<Map<String, FPlayer>>(){}.getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clean()
|
|
|
|
{
|
|
|
|
for (FPlayer fplayer : this.get())
|
|
|
|
{
|
|
|
|
if ( ! Factions.i.exists(fplayer.getFactionId()))
|
|
|
|
{
|
|
|
|
p.log("Reset faction data (invalid faction) for player "+fplayer.getName());
|
2012-01-07 22:56:17 +01:00
|
|
|
fplayer.resetFactionData(false);
|
2011-10-08 22:03:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void autoLeaveOnInactivityRoutine()
|
|
|
|
{
|
|
|
|
if (Conf.autoLeaveAfterDaysOfInactivity <= 0.0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
long now = System.currentTimeMillis();
|
|
|
|
double toleranceMillis = Conf.autoLeaveAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
for (FPlayer fplayer : FPlayers.i.get())
|
|
|
|
{
|
2012-02-26 23:55:58 +01:00
|
|
|
if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis)
|
2011-10-08 22:03:44 +02:00
|
|
|
{
|
2012-01-10 04:37:16 +01:00
|
|
|
if (Conf.logFactionLeave || Conf.logFactionKick)
|
|
|
|
P.p.log("Player "+fplayer.getName()+" was auto-removed due to inactivity.");
|
2011-12-18 14:50:41 +01:00
|
|
|
|
|
|
|
// if player is faction leader, sort out the faction since he's going away
|
|
|
|
if (fplayer.getRole() == Rel.LEADER)
|
2012-01-28 10:16:25 +01:00
|
|
|
{
|
|
|
|
Faction faction = fplayer.getFaction();
|
|
|
|
if (faction != null)
|
|
|
|
fplayer.getFaction().promoteNewLeader();
|
|
|
|
}
|
2011-12-18 14:50:41 +01:00
|
|
|
|
2011-10-08 22:03:44 +02:00
|
|
|
fplayer.leave(false);
|
2012-01-10 04:37:16 +01:00
|
|
|
fplayer.detach();
|
2011-10-08 22:03:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|