PlayerProfile.java 1.91 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
package emu.grasscutter.game.friends;

import dev.morphia.annotations.*;
4
import emu.grasscutter.game.Player;
Melledy's avatar
Melledy committed
5
6
import emu.grasscutter.utils.Utils;

7
@Entity
Melledy's avatar
Melledy committed
8
public class PlayerProfile {
9
	@Transient private Player player;
Melledy's avatar
Melledy committed
10
	
11
	@AlsoLoad("id") private int uid;
Melledy's avatar
Melledy committed
12
13
14
15
16
17
18
19
20
21
22
23
24
	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() { }
	
25
	public PlayerProfile(Player player) {
26
		this.uid = player.getUid();
Melledy's avatar
Melledy committed
27
28
29
		this.syncWithCharacter(player);
	}
	
30
31
	public int getUid() {
		return uid;
Melledy's avatar
Melledy committed
32
33
	}

34
	public Player getPlayer() {
Melledy's avatar
Melledy committed
35
36
37
		return player;
	}
	
38
	public synchronized void setPlayer(Player player) {
Melledy's avatar
Melledy committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		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;
	}

86
	public void syncWithCharacter(Player player) {
Melledy's avatar
Melledy committed
87
88
89
90
		if (player == null) {
			return;
		}
		
91
		this.uid = player.getUid();
Melledy's avatar
Melledy committed
92
93
94
95
96
97
98
99
100
101
		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();
	}
}