mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-12-17 22:27:57 +01:00
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.Relation;
|
||||||
import com.massivecraft.factions.struct.Role;
|
import com.massivecraft.factions.struct.Role;
|
||||||
import com.massivecraft.factions.util.VisualizeUtil;
|
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.TL;
|
||||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -50,6 +51,7 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
private void initPlayer(Player player) {
|
private void initPlayer(Player player) {
|
||||||
// Make sure that all online players do have a fplayer.
|
// Make sure that all online players do have a fplayer.
|
||||||
final FPlayer me = FPlayers.getInstance().getByPlayer(player);
|
final FPlayer me = FPlayers.getInstance().getByPlayer(player);
|
||||||
|
((MemoryFPlayer)me).setName(player.getName());
|
||||||
|
|
||||||
// Update the lastLoginTime for this fplayer
|
// Update the lastLoginTime for this fplayer
|
||||||
me.setLastLoginTime(System.currentTimeMillis());
|
me.setLastLoginTime(System.currentTimeMillis());
|
||||||
|
@ -65,6 +65,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
protected ChatMode chatMode;
|
protected ChatMode chatMode;
|
||||||
|
|
||||||
protected String id;
|
protected String id;
|
||||||
|
protected String name;
|
||||||
|
|
||||||
protected boolean monitorJoins;
|
protected boolean monitorJoins;
|
||||||
|
|
||||||
@ -333,11 +334,18 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
if (isOnline()) {
|
if (this.name == null) {
|
||||||
return getPlayer().getName();
|
// 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 name;
|
||||||
return player.getName() != null ? player.getName() : getId();
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTag() {
|
public String getTag() {
|
||||||
@ -780,12 +788,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
return Bukkit.getPlayer(UUID.fromString(this.getId()));
|
||||||
if (player.getUniqueId().toString().equals(this.getId())) {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOnline() {
|
public boolean isOnline() {
|
||||||
|
Loading…
Reference in New Issue
Block a user