Previous commit gave duplicates. Lets try this.
This commit is contained in:
		@@ -29,6 +29,7 @@ import com.massivecraft.factions.util.RelationUtil;
 | 
				
			|||||||
import com.massivecraft.massivecore.Named;
 | 
					import com.massivecraft.massivecore.Named;
 | 
				
			||||||
import com.massivecraft.massivecore.collections.MassiveList;
 | 
					import com.massivecraft.massivecore.collections.MassiveList;
 | 
				
			||||||
import com.massivecraft.massivecore.collections.MassiveMapDef;
 | 
					import com.massivecraft.massivecore.collections.MassiveMapDef;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.collections.MassiveSet;
 | 
				
			||||||
import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
 | 
					import com.massivecraft.massivecore.collections.MassiveTreeSetDef;
 | 
				
			||||||
import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
 | 
					import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive;
 | 
				
			||||||
import com.massivecraft.massivecore.mixin.MixinMessage;
 | 
					import com.massivecraft.massivecore.mixin.MixinMessage;
 | 
				
			||||||
@@ -1008,7 +1009,8 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam
 | 
				
			|||||||
	// FOREIGN KEY: MPLAYER
 | 
						// FOREIGN KEY: MPLAYER
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	protected transient List<MPlayer> mplayers = new ArrayList<MPlayer>();
 | 
						protected transient Set<MPlayer> mplayers = new MassiveSet<MPlayer>();
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	public void reindexMPlayers()
 | 
						public void reindexMPlayers()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		this.mplayers.clear();
 | 
							this.mplayers.clear();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,7 +33,6 @@ import com.massivecraft.massivecore.util.MUtil;
 | 
				
			|||||||
import com.massivecraft.massivecore.util.Txt;
 | 
					import com.massivecraft.massivecore.util.Txt;
 | 
				
			||||||
import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
 | 
					import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipator
 | 
					public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipator
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
@@ -89,33 +88,41 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
				
			|||||||
	// UPDATE FACTION INDEXES
 | 
						// UPDATE FACTION INDEXES
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public void updateFactionIndexes(Faction before, Faction after)
 | 
						public void updateFactionIndexes(String beforeId, String afterId)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							// Really?
 | 
				
			||||||
 | 
							if (!Factions.get().isDatabaseInitialized()) return;
 | 
				
			||||||
 | 
							if (!this.attached()) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Fix IDs
 | 
				
			||||||
 | 
							if (beforeId == null) beforeId = MConf.get().defaultPlayerFactionId;
 | 
				
			||||||
 | 
							if (afterId == null) afterId = MConf.get().defaultPlayerFactionId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// NoChange
 | 
							// NoChange
 | 
				
			||||||
		if (MUtil.equals(before, after)) return;
 | 
							if (MUtil.equals(beforeId, afterId)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Before
 | 
							// Resolve
 | 
				
			||||||
 | 
							Faction before = Faction.get(beforeId);
 | 
				
			||||||
 | 
							Faction after = Faction.get(afterId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Apply
 | 
				
			||||||
		if (before != null) before.mplayers.remove(this);
 | 
							if (before != null) before.mplayers.remove(this);
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// After
 | 
					 | 
				
			||||||
		if (after != null) after.mplayers.add(this);
 | 
							if (after != null) after.mplayers.add(this);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void postAttach(String id)
 | 
						public void postAttach(String id)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (!Factions.get().isDatabaseInitialized()) return;
 | 
							String beforeId = null;
 | 
				
			||||||
		Faction before = null;
 | 
							String afterId = this.getFactionId();
 | 
				
			||||||
		Faction after = this.getFaction();
 | 
							this.updateFactionIndexes(beforeId, afterId);
 | 
				
			||||||
		this.updateFactionIndexes(before, after);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void preDetach(String id)
 | 
						public void preDetach(String id)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (!Factions.get().isDatabaseInitialized()) return;
 | 
							String before = this.getFactionId();
 | 
				
			||||||
		Faction before = this.getFaction();
 | 
							String after = null;
 | 
				
			||||||
		Faction after = null;
 | 
					 | 
				
			||||||
		this.updateFactionIndexes(before, after);
 | 
							this.updateFactionIndexes(before, after);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -183,6 +190,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
				
			|||||||
	// Null means the player isn't auto claiming.
 | 
						// Null means the player isn't auto claiming.
 | 
				
			||||||
	// NOTE: This field will not be saved to the database ever.
 | 
						// NOTE: This field will not be saved to the database ever.
 | 
				
			||||||
	private transient Faction autoClaimFaction = null;
 | 
						private transient Faction autoClaimFaction = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public Faction getAutoClaimFaction() { return this.autoClaimFaction; }
 | 
						public Faction getAutoClaimFaction() { return this.autoClaimFaction; }
 | 
				
			||||||
	public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = autoClaimFaction; }
 | 
						public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = autoClaimFaction; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -264,51 +272,34 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
				
			|||||||
		return !this.getFactionId().equals(Factions.ID_NONE);
 | 
							return !this.getFactionId().equals(Factions.ID_NONE);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// This setter is so long because it search for default/null case and takes care of updating the faction member index 
 | 
						// This setter is so long because it search for default/null case and takes
 | 
				
			||||||
 | 
						// care of updating the faction member index
 | 
				
			||||||
	public void setFactionId(String factionId)
 | 
						public void setFactionId(String factionId)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// Clean input
 | 
							// Before
 | 
				
			||||||
		String target = factionId;
 | 
							String beforeId = this.factionId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Detect Nochange
 | 
							// After
 | 
				
			||||||
		if (MUtil.equals(this.factionId, target)) return;
 | 
							String afterId = factionId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get the raw old value
 | 
							// NoChange
 | 
				
			||||||
		String oldFactionId = this.factionId;
 | 
							if (MUtil.equals(beforeId, afterId)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Apply
 | 
							// Apply
 | 
				
			||||||
		this.factionId = target;
 | 
							this.factionId = afterId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Must be attached and initialized
 | 
							// Must be attached and initialized
 | 
				
			||||||
		if (!this.attached()) return;
 | 
							if (!this.attached()) return;
 | 
				
			||||||
		if (!Factions.get().isDatabaseInitialized()) return;
 | 
							if (!Factions.get().isDatabaseInitialized()) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (oldFactionId == null) oldFactionId = MConf.get().defaultPlayerFactionId;
 | 
							if (beforeId == null) beforeId = MConf.get().defaultPlayerFactionId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Update index
 | 
							// Update index
 | 
				
			||||||
		Faction oldFaction = Faction.get(oldFactionId);
 | 
							Faction before = Faction.get(beforeId);
 | 
				
			||||||
		Faction faction = this.getFaction();
 | 
							Faction after = this.getFaction();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (oldFaction != null) oldFaction.mplayers.remove(this);
 | 
							if (before != null) before.mplayers.remove(this);
 | 
				
			||||||
		if (faction != null) faction.mplayers.add(this);
 | 
							if (after != null) after.mplayers.add(this);
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		/*
 | 
					 | 
				
			||||||
		String oldFactionIdDesc = "NULL";
 | 
					 | 
				
			||||||
		String oldFactionNameDesc = "NULL";
 | 
					 | 
				
			||||||
		if (oldFaction != null)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			oldFactionIdDesc = oldFaction.getId();
 | 
					 | 
				
			||||||
			oldFactionNameDesc = oldFaction.getName();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		String factionIdDesc = "NULL";
 | 
					 | 
				
			||||||
		String factionNameDesc = "NULL";
 | 
					 | 
				
			||||||
		if (faction != null)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			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
 | 
							// Mark as changed
 | 
				
			||||||
		this.changed();
 | 
							this.changed();
 | 
				
			||||||
@@ -378,8 +369,10 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// NOTE: That we parse the title here is considered part of the 1.8 --> 2.0 migration.
 | 
							// NOTE: That we parse the title here is considered part of the 1.8 -->
 | 
				
			||||||
		// This should be removed once the migration phase is considered to be over.
 | 
							// 2.0 migration.
 | 
				
			||||||
 | 
							// This should be removed once the migration phase is considered to be
 | 
				
			||||||
 | 
							// over.
 | 
				
			||||||
		if (target != null)
 | 
							if (target != null)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			target = Txt.parse(target);
 | 
								target = Txt.parse(target);
 | 
				
			||||||
@@ -661,6 +654,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		return this.getNameAndTitle(this.getColorTo(faction).toString());
 | 
							return this.getNameAndTitle(this.getColorTo(faction).toString());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public String getNameAndTitle(MPlayer mplayer)
 | 
						public String getNameAndTitle(MPlayer mplayer)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		return this.getNameAndTitle(this.getColorTo(mplayer).toString());
 | 
							return this.getNameAndTitle(this.getColorTo(mplayer).toString());
 | 
				
			||||||
@@ -746,7 +740,8 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
				
			|||||||
	public boolean considerRemovePlayerMillis(boolean async)
 | 
						public boolean considerRemovePlayerMillis(boolean async)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// This may or may not be required.
 | 
							// This may or may not be required.
 | 
				
			||||||
		// Some users have been reporting a loop issue with the same player detaching over and over again.
 | 
							// Some users have been reporting a loop issue with the same player
 | 
				
			||||||
 | 
							// detaching over and over again.
 | 
				
			||||||
		// Maybe skipping ahead if the player is detached will solve the issue.
 | 
							// Maybe skipping ahead if the player is detached will solve the issue.
 | 
				
			||||||
		if (this.detached()) return false;
 | 
							if (this.detached()) return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,9 +43,9 @@ public class MPlayerColl extends SenderColl<MPlayer>
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		if (mplayer != null)
 | 
							if (mplayer != null)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Faction before = mplayer.getFaction();
 | 
								String beforeId = mplayer.getFactionId();
 | 
				
			||||||
			Faction after = null;
 | 
								String afterId = null;
 | 
				
			||||||
			mplayer.updateFactionIndexes(before, after);
 | 
								mplayer.updateFactionIndexes(beforeId, afterId);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		return super.removeAtLocalFixed(id);
 | 
							return super.removeAtLocalFixed(id);
 | 
				
			||||||
@@ -63,20 +63,20 @@ public class MPlayerColl extends SenderColl<MPlayer>
 | 
				
			|||||||
		MPlayer mplayer = null;
 | 
							MPlayer mplayer = null;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Before
 | 
							// Before
 | 
				
			||||||
		Faction before = null;
 | 
							String beforeId = null;
 | 
				
			||||||
		if (mplayer == null) mplayer = this.id2entity.get(id);
 | 
							if (mplayer == null) mplayer = this.id2entity.get(id);
 | 
				
			||||||
		if (mplayer != null) before = mplayer.getFaction();
 | 
							if (mplayer != null) beforeId = mplayer.getFactionId();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Super
 | 
							// Super
 | 
				
			||||||
		super.loadFromRemoteFixed(id, remoteEntry);
 | 
							super.loadFromRemoteFixed(id, remoteEntry);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// After
 | 
							// After
 | 
				
			||||||
		Faction after = null;
 | 
							String afterId = null;
 | 
				
			||||||
		if (mplayer == null) mplayer = this.id2entity.get(id);
 | 
							if (mplayer == null) mplayer = this.id2entity.get(id);
 | 
				
			||||||
		if (mplayer != null) after = mplayer.getFaction();
 | 
							if (mplayer != null) afterId = mplayer.getFactionId();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Perform
 | 
							// Perform
 | 
				
			||||||
		if (mplayer != null) mplayer.updateFactionIndexes(before, after);
 | 
							if (mplayer != null) mplayer.updateFactionIndexes(beforeId, afterId);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user