2013-04-22 21:00:00 +02:00
|
|
|
package com.massivecraft.factions.entity;
|
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
2013-04-22 21:00:00 +02:00
|
|
|
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;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.massivecore.util.IdUtil;
|
|
|
|
import com.massivecraft.massivecore.util.Txt;
|
2013-04-22 21:00:00 +02:00
|
|
|
|
|
|
|
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());
|
2013-04-22 21:00:00 +02:00
|
|
|
}
|
2015-02-03 11:21:28 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// STACK TRACEABILITY
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTick()
|
|
|
|
{
|
|
|
|
super.onTick();
|
|
|
|
}
|
2013-04-22 21:00:00 +02:00
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// EXTRAS
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
public void clean()
|
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
for (MPlayer mplayer : this.getAll())
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-09-17 13:29:58 +02:00
|
|
|
String factionId = mplayer.getFactionId();
|
2014-09-17 13:17:33 +02:00
|
|
|
if (FactionColl.get().containsId(factionId)) continue;
|
|
|
|
|
2014-09-17 13:29:58 +02:00
|
|
|
mplayer.resetFactionData();
|
2014-09-17 13:17:33 +02:00
|
|
|
|
2014-09-17 13:33:09 +02:00
|
|
|
String message = Txt.parse("<i>Reset data for <h>%s <i>. Unknown factionId <h>%s", mplayer.getDisplayName(IdUtil.getConsole()), factionId);
|
2014-09-17 13:17:33 +02:00
|
|
|
Factions.get().log(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
public void considerRemovePlayerMillis()
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-06 13:08:34 +02:00
|
|
|
// If the config option is 0 or below that means the server owner want it disabled.
|
|
|
|
if (MConf.get().removePlayerMillisDefault <= 0.0) return;
|
2014-09-17 13:17:33 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// 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();
|
2014-09-17 13:17:33 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-06 13:08:34 +02:00
|
|
|
@Override
|
|
|
|
public void run()
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-06 13:08:34 +02:00
|
|
|
for (MPlayer mplayer : mplayersOffline)
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2014-10-06 13:08:34 +02:00
|
|
|
mplayer.considerRemovePlayerMillis(true);
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 13:08:34 +02:00
|
|
|
});
|
2014-09-17 13:17:33 +02:00
|
|
|
}
|
|
|
|
|
2013-04-22 21:00:00 +02:00
|
|
|
}
|