mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-20 08:40:02 +08:00
91b685586e
1. During the conversion of Morphia calls to the new API, some of the `Filter.eq()` calls had their `field` set to `playerId` due to a copy/paste typo. 2. Morphia 2 switches to the codec system, so anything that will be serialized in the pipeline requires the `@Entity` annotation.
101 lines
1.9 KiB
Java
101 lines
1.9 KiB
Java
package emu.grasscutter.game.friends;
|
|
|
|
import dev.morphia.annotations.*;
|
|
import emu.grasscutter.game.GenshinPlayer;
|
|
import emu.grasscutter.utils.Utils;
|
|
|
|
@Entity
|
|
public class PlayerProfile {
|
|
@Transient private GenshinPlayer player;
|
|
|
|
private int id;
|
|
private int nameCard;
|
|
private int avatarId;
|
|
private String name;
|
|
private String signature;
|
|
private int achievements;
|
|
|
|
private int playerLevel;
|
|
private int worldLevel;
|
|
private int lastActiveTime;
|
|
|
|
@Deprecated // Morphia only
|
|
public PlayerProfile() { }
|
|
|
|
public PlayerProfile(GenshinPlayer player) {
|
|
this.id = player.getUid();
|
|
this.syncWithCharacter(player);
|
|
}
|
|
|
|
public int getId() {
|
|
return id;
|
|
}
|
|
|
|
public GenshinPlayer getPlayer() {
|
|
return player;
|
|
}
|
|
|
|
public synchronized void setPlayer(GenshinPlayer player) {
|
|
this.player = player;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public int getNameCard() {
|
|
return nameCard;
|
|
}
|
|
|
|
public int getAvatarId() {
|
|
return avatarId;
|
|
}
|
|
|
|
public String getSignature() {
|
|
return signature;
|
|
}
|
|
|
|
public int getAchievements() {
|
|
return achievements;
|
|
}
|
|
|
|
public int getPlayerLevel() {
|
|
return playerLevel;
|
|
}
|
|
|
|
public int getWorldLevel() {
|
|
return worldLevel;
|
|
}
|
|
|
|
public int getLastActiveTime() {
|
|
return lastActiveTime;
|
|
}
|
|
|
|
public void updateLastActiveTime() {
|
|
this.lastActiveTime = Utils.getCurrentSeconds();
|
|
}
|
|
|
|
public int getDaysSinceLogin() {
|
|
return (int) Math.floor((Utils.getCurrentSeconds() - getLastActiveTime()) / 86400.0);
|
|
}
|
|
|
|
public boolean isOnline() {
|
|
return this.getPlayer() != null;
|
|
}
|
|
|
|
public void syncWithCharacter(GenshinPlayer player) {
|
|
if (player == null) {
|
|
return;
|
|
}
|
|
|
|
this.name = player.getNickname();
|
|
this.avatarId = player.getHeadImage();
|
|
this.signature = player.getSignature();
|
|
this.nameCard = player.getNameCardId();
|
|
this.playerLevel = player.getLevel();
|
|
this.worldLevel = player.getWorldLevel();
|
|
//this.achievements = 0;
|
|
this.updateLastActiveTime();
|
|
}
|
|
}
|