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