Previous commit gave duplicates. Lets try this.
This commit is contained in:
		
							parent
							
								
									6599aac488
								
							
						
					
					
						commit
						3bd67f5029
					
				| @ -29,6 +29,7 @@ import com.massivecraft.factions.util.RelationUtil; | ||||
| import com.massivecraft.massivecore.Named; | ||||
| import com.massivecraft.massivecore.collections.MassiveList; | ||||
| import com.massivecraft.massivecore.collections.MassiveMapDef; | ||||
| import com.massivecraft.massivecore.collections.MassiveSet; | ||||
| import com.massivecraft.massivecore.collections.MassiveTreeSetDef; | ||||
| import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; | ||||
| import com.massivecraft.massivecore.mixin.MixinMessage; | ||||
| @ -1008,7 +1009,8 @@ public class Faction extends Entity<Faction> implements EconomyParticipator, Nam | ||||
| 	// FOREIGN KEY: MPLAYER | ||||
| 	// -------------------------------------------- // | ||||
| 	 | ||||
| 	protected transient List<MPlayer> mplayers = new ArrayList<MPlayer>(); | ||||
| 	protected transient Set<MPlayer> mplayers = new MassiveSet<MPlayer>(); | ||||
| 	 | ||||
| 	public void reindexMPlayers() | ||||
| 	{ | ||||
| 		this.mplayers.clear(); | ||||
|  | ||||
| @ -33,7 +33,6 @@ import com.massivecraft.massivecore.util.MUtil; | ||||
| import com.massivecraft.massivecore.util.Txt; | ||||
| import com.massivecraft.massivecore.xlib.gson.annotations.SerializedName; | ||||
| 
 | ||||
| 
 | ||||
| public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipator | ||||
| { | ||||
| 	// -------------------------------------------- // | ||||
| @ -89,33 +88,41 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 	// 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 | ||||
| 		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); | ||||
| 		 | ||||
| 		// After | ||||
| 		if (after != null) after.mplayers.add(this); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void postAttach(String id) | ||||
| 	{ | ||||
| 		if (!Factions.get().isDatabaseInitialized()) return; | ||||
| 		Faction before = null; | ||||
| 		Faction after = this.getFaction(); | ||||
| 		this.updateFactionIndexes(before, after); | ||||
| 		String beforeId = null; | ||||
| 		String afterId = this.getFactionId(); | ||||
| 		this.updateFactionIndexes(beforeId, afterId); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void preDetach(String id) | ||||
| 	{ | ||||
| 		if (!Factions.get().isDatabaseInitialized()) return; | ||||
| 		Faction before = this.getFaction(); | ||||
| 		Faction after = null; | ||||
| 		String before = this.getFactionId(); | ||||
| 		String after = null; | ||||
| 		this.updateFactionIndexes(before, after); | ||||
| 	} | ||||
| 
 | ||||
| @ -132,7 +139,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 	// There is actually more than one reason we store this data ourselves and don't use the OfflinePlayer#getLastPlayed. | ||||
| 	// 1. I don't trust that method. It's been very buggy or even completely broken in previous Bukkit versions. | ||||
| 	// 2. The method depends on the player.dat files being present. | ||||
| 	//    Server owners clear those files at times, or move their database data around between different servers. | ||||
| 	// Server owners clear those files at times, or move their database data around between different servers. | ||||
| 	private long lastActivityMillis = System.currentTimeMillis(); | ||||
| 
 | ||||
| 	// This is a foreign key. | ||||
| @ -150,7 +157,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 	// | ||||
| 	// Question: Can the title contain chat colors? | ||||
| 	// Answer: Yes but in such case the policy is that they already must be parsed using Txt.parse. | ||||
| 	//         If the title contains raw markup, such as "<white>" instead of "§f" it will not be parsed and "<white>" will be displayed. | ||||
| 	// If the title contains raw markup, such as "<white>" instead of "§f" it will not be parsed and "<white>" will be displayed. | ||||
| 	// | ||||
| 	// Null means the player has no title. | ||||
| 	private String title = null; | ||||
| @ -183,6 +190,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 	// Null means the player isn't auto claiming. | ||||
| 	// NOTE: This field will not be saved to the database ever. | ||||
| 	private transient Faction autoClaimFaction = null; | ||||
| 
 | ||||
| 	public Faction getAutoClaimFaction() { return this.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); | ||||
| 	} | ||||
| 
 | ||||
| 	// 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) | ||||
| 	{ | ||||
| 		// Clean input | ||||
| 		String target = factionId; | ||||
| 		// Before | ||||
| 		String beforeId = this.factionId; | ||||
| 
 | ||||
| 		// Detect Nochange | ||||
| 		if (MUtil.equals(this.factionId, target)) return; | ||||
| 		// After | ||||
| 		String afterId = factionId; | ||||
| 
 | ||||
| 		// Get the raw old value | ||||
| 		String oldFactionId = this.factionId; | ||||
| 		// NoChange | ||||
| 		if (MUtil.equals(beforeId, afterId)) return; | ||||
| 
 | ||||
| 		// Apply | ||||
| 		this.factionId = target; | ||||
| 		this.factionId = afterId; | ||||
| 
 | ||||
| 		// Must be attached and initialized | ||||
| 		if (!this.attached()) return; | ||||
| 		if (!Factions.get().isDatabaseInitialized()) return; | ||||
| 
 | ||||
| 		if (oldFactionId == null) oldFactionId = MConf.get().defaultPlayerFactionId; | ||||
| 		if (beforeId == null) beforeId = MConf.get().defaultPlayerFactionId; | ||||
| 
 | ||||
| 		// Update index | ||||
| 		Faction oldFaction = Faction.get(oldFactionId); | ||||
| 		Faction faction = this.getFaction(); | ||||
| 		Faction before = Faction.get(beforeId); | ||||
| 		Faction after = this.getFaction(); | ||||
| 
 | ||||
| 		if (oldFaction != null) oldFaction.mplayers.remove(this); | ||||
| 		if (faction != null) faction.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)); | ||||
| 		*/ | ||||
| 		if (before != null) before.mplayers.remove(this); | ||||
| 		if (after != null) after.mplayers.add(this); | ||||
| 
 | ||||
| 		// Mark as 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. | ||||
| 		// This should be removed once the migration phase is considered to be over. | ||||
| 		// NOTE: That we parse the title here is considered part of the 1.8 --> | ||||
| 		// 2.0 migration. | ||||
| 		// This should be removed once the migration phase is considered to be | ||||
| 		// over. | ||||
| 		if (target != null) | ||||
| 		{ | ||||
| 			target = Txt.parse(target); | ||||
| @ -588,7 +581,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 
 | ||||
| 	public boolean isTerritoryInfoTitles() | ||||
| 	{ | ||||
| 		if ( ! MixinTitle.get().isAvailable()) return false; | ||||
| 		if (!MixinTitle.get().isAvailable()) return false; | ||||
| 		if (this.territoryInfoTitles == null) return MConf.get().territoryInfoTitlesDefault; | ||||
| 		return this.territoryInfoTitles; | ||||
| 	} | ||||
| @ -661,6 +654,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 	{ | ||||
| 		return this.getNameAndTitle(this.getColorTo(faction).toString()); | ||||
| 	} | ||||
| 
 | ||||
| 	public String getNameAndTitle(MPlayer mplayer) | ||||
| 	{ | ||||
| 		return this.getNameAndTitle(this.getColorTo(mplayer).toString()); | ||||
| @ -746,7 +740,8 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 	public boolean considerRemovePlayerMillis(boolean async) | ||||
| 	{ | ||||
| 		// 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. | ||||
| 		if (this.detached()) return false; | ||||
| 
 | ||||
| @ -820,7 +815,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 
 | ||||
| 			if (MConf.get().logFactionLeave) | ||||
| 			{ | ||||
| 				Factions.get().log(this.getName()+" left the faction: "+myFaction.getName()); | ||||
| 				Factions.get().log(this.getName() + " left the faction: " + myFaction.getName()); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| @ -830,13 +825,13 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato | ||||
| 		{ | ||||
| 			EventFactionsDisband eventFactionsDisband = new EventFactionsDisband(this.getSender(), myFaction); | ||||
| 			eventFactionsDisband.run(); | ||||
| 			if ( ! eventFactionsDisband.isCancelled()) | ||||
| 			if (!eventFactionsDisband.isCancelled()) | ||||
| 			{ | ||||
| 				// Remove this faction | ||||
| 				this.msg("%s <i>was disbanded since you were the last player.", myFaction.describeTo(this, true)); | ||||
| 				if (MConf.get().logFactionDisband) | ||||
| 				{ | ||||
| 					Factions.get().log("The faction "+myFaction.getName()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving."); | ||||
| 					Factions.get().log("The faction " + myFaction.getName() + " (" + myFaction.getId() + ") was disbanded due to the last player (" + this.getName() + ") leaving."); | ||||
| 				} | ||||
| 				myFaction.detach(); | ||||
| 			} | ||||
|  | ||||
| @ -43,9 +43,9 @@ public class MPlayerColl extends SenderColl<MPlayer> | ||||
| 		 | ||||
| 		if (mplayer != null) | ||||
| 		{ | ||||
| 			Faction before = mplayer.getFaction(); | ||||
| 			Faction after = null; | ||||
| 			mplayer.updateFactionIndexes(before, after); | ||||
| 			String beforeId = mplayer.getFactionId(); | ||||
| 			String afterId = null; | ||||
| 			mplayer.updateFactionIndexes(beforeId, afterId); | ||||
| 		} | ||||
| 		 | ||||
| 		return super.removeAtLocalFixed(id); | ||||
| @ -63,20 +63,20 @@ public class MPlayerColl extends SenderColl<MPlayer> | ||||
| 		MPlayer mplayer = null; | ||||
| 		 | ||||
| 		// Before | ||||
| 		Faction before = null; | ||||
| 		String beforeId = null; | ||||
| 		if (mplayer == null) mplayer = this.id2entity.get(id); | ||||
| 		if (mplayer != null) before = mplayer.getFaction(); | ||||
| 		if (mplayer != null) beforeId = mplayer.getFactionId(); | ||||
| 		 | ||||
| 		// Super | ||||
| 		super.loadFromRemoteFixed(id, remoteEntry); | ||||
| 		 | ||||
| 		// After | ||||
| 		Faction after = null; | ||||
| 		String afterId = null; | ||||
| 		if (mplayer == null) mplayer = this.id2entity.get(id); | ||||
| 		if (mplayer != null) after = mplayer.getFaction(); | ||||
| 		if (mplayer != null) afterId = mplayer.getFactionId(); | ||||
| 		 | ||||
| 		// Perform | ||||
| 		if (mplayer != null) mplayer.updateFactionIndexes(before, after); | ||||
| 		if (mplayer != null) mplayer.updateFactionIndexes(beforeId, afterId); | ||||
| 	} | ||||
| 	 | ||||
| 	// -------------------------------------------- // | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user