Factions/src/com/massivecraft/factions/entity/MPlayerColl.java

69 lines
2.0 KiB
Java
Raw Normal View History

package com.massivecraft.factions.entity;
import java.util.Collection;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Const;
import com.massivecraft.factions.Factions;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.store.SenderColl;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.Txt;
public class MPlayerColl extends SenderColl<MPlayer>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MPlayerColl i = new MPlayerColl();
public static MPlayerColl get() { return i; }
private MPlayerColl()
{
2013-11-11 09:31:04 +01:00
super(Const.COLLECTION_MPLAYER, MPlayer.class, MStore.getDb(), Factions.get());
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public void clean()
{
2014-09-17 13:29:58 +02:00
for (MPlayer mplayer : this.getAll())
{
2014-09-17 13:29:58 +02:00
String factionId = mplayer.getFactionId();
if (FactionColl.get().containsId(factionId)) continue;
2014-09-17 13:29:58 +02:00
mplayer.resetFactionData();
String message = Txt.parse("<i>Reset data for <h>%s <i>. Unknown factionId <h>%s", mplayer.getDisplayName(IdUtil.getConsole()), factionId);
Factions.get().log(message);
}
}
public void considerRemovePlayerMillis()
{
// If the config option is 0 or below that means the server owner want it disabled.
if (MConf.get().removePlayerMillisDefault <= 0.0) return;
// For each of the offline players...
// NOTE: If the player is currently online it's most definitely not inactive.
// NOTE: This check catches some important special cases like the @console "player".
final Collection<MPlayer> mplayersOffline = this.getAllOffline();
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
for (MPlayer mplayer : mplayersOffline)
{
mplayer.considerRemovePlayerMillis(true);
}
}
});
}
}