Save last-known FPlayer names
Instead of performing a lookup each time FPlayer#getName() is called, save the player's name as s/he logs in
This commit is contained in:
parent
1d4ca46ebe
commit
c1752477c7
@ -10,6 +10,7 @@ import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.VisualizeUtil;
|
||||
import com.massivecraft.factions.zcore.persist.MemoryFPlayer;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -50,6 +51,7 @@ public class FactionsPlayerListener implements Listener {
|
||||
private void initPlayer(Player player) {
|
||||
// Make sure that all online players do have a fplayer.
|
||||
final FPlayer me = FPlayers.getInstance().getByPlayer(player);
|
||||
((MemoryFPlayer)me).setName(player.getName());
|
||||
|
||||
// Update the lastLoginTime for this fplayer
|
||||
me.setLastLoginTime(System.currentTimeMillis());
|
||||
|
@ -65,6 +65,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
protected ChatMode chatMode;
|
||||
|
||||
protected String id;
|
||||
protected String name;
|
||||
|
||||
protected boolean monitorJoins;
|
||||
|
||||
@ -333,11 +334,18 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (isOnline()) {
|
||||
return getPlayer().getName();
|
||||
if (this.name == null) {
|
||||
// Older versions of FactionsUUID don't save the name,
|
||||
// so `name` will be null the first time it's retrieved
|
||||
// after updating
|
||||
OfflinePlayer offline = Bukkit.getOfflinePlayer(UUID.fromString(getId()));
|
||||
this.name = offline.getName() != null ? offline.getName() : getId();
|
||||
}
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(getId()));
|
||||
return player.getName() != null ? player.getName() : getId();
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
@ -780,12 +788,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (player.getUniqueId().toString().equals(this.getId())) {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return Bukkit.getPlayer(UUID.fromString(this.getId()));
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
|
Loading…
Reference in New Issue
Block a user