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)
|
|
|
|
{
|
2016-08-03 12:51:06 +02:00
|
|
|
String beforeId = mplayer.getFactionId();
|
|
|
|
String afterId = null;
|
|
|
|
mplayer.updateFactionIndexes(beforeId, afterId);
|
2016-07-30 12:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2016-08-03 12:51:06 +02:00
|
|
|
String beforeId = null;
|
2016-07-30 12:09:20 +02:00
|
|
|
if (mplayer == null) mplayer = this.id2entity.get(id);
|
2016-08-03 12:51:06 +02:00
|
|
|
if (mplayer != null) beforeId = mplayer.getFactionId();
|
2016-07-30 12:09:20 +02:00
|
|
|
|
|
|
|
// Super
|
|
|
|
super.loadFromRemoteFixed(id, remoteEntry);
|
|
|
|
|
|
|
|
// After
|
2016-08-03 12:51:06 +02:00
|
|
|
String afterId = null;
|
2016-07-30 12:09:20 +02:00
|
|
|
if (mplayer == null) mplayer = this.id2entity.get(id);
|
2016-08-03 12:51:06 +02:00
|
|
|
if (mplayer != null) afterId = mplayer.getFactionId();
|
2016-07-30 12:09:20 +02:00
|
|
|
|
|
|
|
// Perform
|
2016-08-03 12:51:06 +02:00
|
|
|
if (mplayer != null) mplayer.updateFactionIndexes(beforeId, afterId);
|
2016-07-30 12:09:20 +02:00
|
|
|
}
|
|
|
|
|
2014-09-17 13:17:33 +02:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// EXTRAS
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
public void clean()
|
|
|
|
{
|
2017-03-12 17:55:01 +01:00
|
|
|
// For each player ...
|
2014-09-17 13:29:58 +02:00
|
|
|
for (MPlayer mplayer : this.getAll())
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2017-03-12 17:55:01 +01:00
|
|
|
// ... who doesn't have a valid faction ...
|
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;
|
|
|
|
|
2017-03-12 17:55:01 +01:00
|
|
|
// ... reset their faction data ...
|
2014-09-17 13:29:58 +02:00
|
|
|
mplayer.resetFactionData();
|
2014-09-17 13:17:33 +02:00
|
|
|
|
2017-03-12 17:55:01 +01:00
|
|
|
// ... and log.
|
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
|
|
|
{
|
2017-03-12 17:55:01 +01:00
|
|
|
// For each offline player ...
|
2014-10-06 13:08:34 +02:00
|
|
|
for (MPlayer mplayer : mplayersOffline)
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2017-03-12 17:55:01 +01:00
|
|
|
// ... see if they should be removed.
|
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
|
|
|
}
|