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.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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.
|
// 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.
|
// 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.
|
// 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();
|
private long lastActivityMillis = System.currentTimeMillis();
|
||||||
|
|
||||||
// This is a foreign key.
|
// This is a foreign key.
|
||||||
@ -150,7 +157,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
//
|
//
|
||||||
// Question: Can the title contain chat colors?
|
// 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.
|
// 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.
|
// Null means the player has no title.
|
||||||
private String title = null;
|
private String title = null;
|
||||||
@ -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);
|
||||||
@ -588,7 +581,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
|
|
||||||
public boolean isTerritoryInfoTitles()
|
public boolean isTerritoryInfoTitles()
|
||||||
{
|
{
|
||||||
if ( ! MixinTitle.get().isAvailable()) return false;
|
if (!MixinTitle.get().isAvailable()) return false;
|
||||||
if (this.territoryInfoTitles == null) return MConf.get().territoryInfoTitlesDefault;
|
if (this.territoryInfoTitles == null) return MConf.get().territoryInfoTitlesDefault;
|
||||||
return this.territoryInfoTitles;
|
return this.territoryInfoTitles;
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
|
|
||||||
@ -820,7 +815,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
|
|
||||||
if (MConf.get().logFactionLeave)
|
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 eventFactionsDisband = new EventFactionsDisband(this.getSender(), myFaction);
|
||||||
eventFactionsDisband.run();
|
eventFactionsDisband.run();
|
||||||
if ( ! eventFactionsDisband.isCancelled())
|
if (!eventFactionsDisband.isCancelled())
|
||||||
{
|
{
|
||||||
// Remove this faction
|
// Remove this faction
|
||||||
this.msg("%s <i>was disbanded since you were the last player.", myFaction.describeTo(this, true));
|
this.msg("%s <i>was disbanded since you were the last player.", myFaction.describeTo(this, true));
|
||||||
if (MConf.get().logFactionDisband)
|
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();
|
myFaction.detach();
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
Loading…
Reference in New Issue
Block a user