Harden Index Updates. Remove ancient debug output.
This commit is contained in:
parent
9a1f339e61
commit
2f96e747b5
@ -46,7 +46,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: ENTITY
|
||||
// LOAD
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
@ -65,6 +65,10 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// IS DEFAULT
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean isDefault()
|
||||
{
|
||||
@ -81,30 +85,38 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UPDATE FACTION INDEXES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void updateFactionIndexes(Faction before, Faction after)
|
||||
{
|
||||
// NoChange
|
||||
if (MUtil.equals(before, after)) return;
|
||||
|
||||
// Before
|
||||
if (before != null) before.mplayers.remove(this);
|
||||
|
||||
// After
|
||||
if (after != null) after.mplayers.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postAttach(String id)
|
||||
{
|
||||
// If inited ...
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
// ... update the index.
|
||||
Faction faction = this.getFaction();
|
||||
faction.mplayers.add(this);
|
||||
|
||||
//Factions.get().log(Txt.parse("<g>postAttach added <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", id, MixinDisplayName.get().getDisplayName(id), faction.getId(), faction.getName()));
|
||||
Faction before = null;
|
||||
Faction after = this.getFaction();
|
||||
this.updateFactionIndexes(before, after);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preDetach(String id)
|
||||
{
|
||||
// If inited ...
|
||||
if (!Factions.get().isDatabaseInitialized()) return;
|
||||
|
||||
// ... update the index.
|
||||
Faction faction = this.getFaction();
|
||||
faction.mplayers.remove(this);
|
||||
|
||||
//Factions.get().log(Txt.parse("<b>preDetach removed <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", id, MixinDisplayName.get().getDisplayName(id), faction.getId(), faction.getName()));
|
||||
Faction before = this.getFaction();
|
||||
Faction after = null;
|
||||
this.updateFactionIndexes(before, after);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -280,6 +292,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
||||
if (oldFaction != null) oldFaction.mplayers.remove(this);
|
||||
if (faction != null) faction.mplayers.add(this);
|
||||
|
||||
/*
|
||||
String oldFactionIdDesc = "NULL";
|
||||
String oldFactionNameDesc = "NULL";
|
||||
if (oldFaction != null)
|
||||
@ -294,8 +307,8 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
||||
factionIdDesc = faction.getId();
|
||||
factionNameDesc = faction.getName();
|
||||
}
|
||||
|
||||
Factions.get().log(Txt.parse("<i>setFactionId moved <h>%s <i>aka <h>%s <i>from <h>%s <i>aka <h>%s <i>to <h>%s <i>aka <h>%s<i>.", this.getId(), this.getDisplayName(IdUtil.getConsole()), oldFactionIdDesc, oldFactionNameDesc, factionIdDesc, factionNameDesc));
|
||||
*/
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -8,6 +9,7 @@ import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.massivecore.store.SenderColl;
|
||||
import com.massivecraft.massivecore.util.IdUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
|
||||
public class MPlayerColl extends SenderColl<MPlayer>
|
||||
{
|
||||
@ -28,6 +30,55 @@ public class MPlayerColl extends SenderColl<MPlayer>
|
||||
super.onTick();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// 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);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user