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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
@ -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;
|
||||
|
||||
|
@ -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