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;
|
2016-07-30 12:09:20 +02:00
|
|
|
import java.util.Map.Entry;
|
2014-10-06 13:08:34 +02:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
2013-04-22 21:00:00 +02:00
|
|
|
import com.massivecraft.factions.Factions;
|
2014-06-04 14:02:23 +02:00
|
|
|
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;
|
2016-07-30 12:09:20 +02:00
|
|
|
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
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; }
|
2015-02-03 11:21:28 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// STACK TRACEABILITY
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTick()
|
|
|
|
{
|
|
|
|
super.onTick();
|
|
|
|
}
|
2013-04-22 21:00:00 +02:00
|
|
|
|
2016-07-30 12:09:20 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// UPDATE FACTION INDEXES
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized MPlayer removeAtLocalFixed(String id)
|
|
|
|
{
|
|
|
|
if (!Factions.get().isDatabaseInitialized()) return super.removeAtLocalFixed(id);
|
|
|
|
|
|
|
|
MPlayer mplayer = this.id2entity.get(id);
|
|
|
|
|
|
|
|
if (mplayer != null)
|
|
|
|
{
|
|
|
|
Faction before = mplayer.getFaction();
|
|
|
|
Faction after = null;
|
|
|
|
mplayer.updateFactionIndexes(before, after);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.removeAtLocalFixed(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public synchronized void loadFromRemoteFixed(String id, Entry<JsonObject, Long> remoteEntry)
|
|
|
|
{
|
|
|
|
if (!Factions.get().isDatabaseInitialized())
|
|
|
|
{
|
|
|
|
super.loadFromRemoteFixed(id, remoteEntry);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MPlayer mplayer = null;
|
|
|
|
|
|
|
|
// Before
|
|
|
|
Faction before = null;
|
|
|
|
if (mplayer == null) mplayer = this.id2entity.get(id);
|
|
|
|
if (mplayer != null) before = mplayer.getFaction();
|
|
|
|
|
|
|
|
// Super
|
|
|
|
super.loadFromRemoteFixed(id, remoteEntry);
|
|
|
|
|
|
|
|
// After
|
|
|
|
Faction after = null;
|
|
|
|
if (mplayer == null) mplayer = this.id2entity.get(id);
|
|
|
|
if (mplayer != null) after = mplayer.getFaction();
|
|
|
|
|
|
|
|
// Perform
|
|
|
|
if (mplayer != null) mplayer.updateFactionIndexes(before, after);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|