Skip to content

Commit 92c3c64

Browse files
committed
feat: extend CloudPlayer API with session details, timestamps, and properties
1 parent 4d13ddb commit 92c3c64

4 files changed

Lines changed: 129 additions & 19 deletions

File tree

api/src/main/java/app/simplecloud/api/internal/player/CloudPlayerImpl.java

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
1616

1717
import java.time.Duration;
18+
import java.util.Collections;
19+
import java.util.HashMap;
20+
import java.util.Map;
1821
import java.util.UUID;
1922
import java.util.concurrent.CompletableFuture;
2023

@@ -32,26 +35,48 @@ public class CloudPlayerImpl implements CloudPlayer, ForwardingAudience.Single {
3235
private final UUID uniqueId;
3336
private final String name;
3437
private final String displayName;
35-
private final String connectedProxyId;
36-
private final String connectedServerId;
38+
private final String connectedProxyName;
39+
private final String connectedServerName;
40+
private final boolean online;
41+
private final long onlineTimeSeconds;
42+
private final String sessionId;
43+
private final String firstSeen;
44+
private final String lastSeen;
45+
private final Map<String, String> properties;
3746

3847
public CloudPlayerImpl(
3948
Connection natsConnection,
4049
String networkId,
4150
UUID uniqueId,
4251
String name,
4352
String displayName,
44-
String connectedProxyId,
45-
String connectedServerId
53+
String connectedProxyName,
54+
String connectedServerName,
55+
boolean online,
56+
long onlineTimeSeconds,
57+
String sessionId,
58+
String firstSeen,
59+
String lastSeen,
60+
Map<String, String> properties
4661
) {
4762
this.natsConnection = natsConnection;
4863
this.networkId = networkId;
4964
this.audience = RemoteAudience.builder(natsConnection, networkId).forPlayer(uniqueId);
5065
this.uniqueId = uniqueId;
5166
this.name = name;
5267
this.displayName = displayName;
53-
this.connectedProxyId = connectedProxyId;
54-
this.connectedServerId = connectedServerId;
68+
this.connectedProxyName = connectedProxyName;
69+
this.connectedServerName = connectedServerName;
70+
this.online = online;
71+
this.onlineTimeSeconds = onlineTimeSeconds;
72+
this.sessionId = sessionId;
73+
this.firstSeen = firstSeen;
74+
this.lastSeen = lastSeen;
75+
if (properties == null || properties.isEmpty()) {
76+
this.properties = Collections.emptyMap();
77+
} else {
78+
this.properties = Collections.unmodifiableMap(new HashMap<>(properties));
79+
}
5580
}
5681

5782
@Override
@@ -77,13 +102,43 @@ public String getDisplayName() {
77102
}
78103

79104
@Override
80-
public String getConnectedProxyId() {
81-
return connectedProxyId;
105+
public String getConnectedProxyName() {
106+
return connectedProxyName;
82107
}
83108

84109
@Override
85-
public String getConnectedServerId() {
86-
return connectedServerId;
110+
public String getConnectedServerName() {
111+
return connectedServerName;
112+
}
113+
114+
@Override
115+
public boolean isOnline() {
116+
return online;
117+
}
118+
119+
@Override
120+
public long getOnlineTimeSeconds() {
121+
return onlineTimeSeconds;
122+
}
123+
124+
@Override
125+
public String getSessionId() {
126+
return sessionId;
127+
}
128+
129+
@Override
130+
public String getFirstSeen() {
131+
return firstSeen;
132+
}
133+
134+
@Override
135+
public String getLastSeen() {
136+
return lastSeen;
137+
}
138+
139+
@Override
140+
public Map<String, String> getProperties() {
141+
return properties;
87142
}
88143

89144
@Override

api/src/main/java/app/simplecloud/api/internal/player/PlayerApiImpl.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ private CloudPlayer convertPlayer(ModelsOnlinePlayerResponse player) {
128128
player.getName(),
129129
player.getDisplayName(),
130130
player.getConnectedProxyName(),
131-
player.getConnectedServerName()
131+
player.getConnectedServerName(),
132+
player.getOnline() != null && player.getOnline(),
133+
player.getOnlineTimeSeconds() != null ? player.getOnlineTimeSeconds().longValue() : 0L,
134+
player.getSessionId(),
135+
player.getFirstSeen(),
136+
player.getLastSeen(),
137+
player.getProperties()
132138
);
133139
}
134140

@@ -140,7 +146,13 @@ private CloudPlayer convertPlayerResponse(ModelsPlayerResponse player) {
140146
player.getName(),
141147
player.getDisplayName(),
142148
player.getConnectedProxyName(),
143-
player.getConnectedServerName()
149+
player.getConnectedServerName(),
150+
player.getOnline() != null && player.getOnline(),
151+
player.getOnlineTimeSeconds() != null ? player.getOnlineTimeSeconds().longValue() : 0L,
152+
player.getSessionId(),
153+
player.getFirstSeen(),
154+
player.getLastSeen(),
155+
player.getProperties()
144156
);
145157
}
146158
}

api/src/main/java/app/simplecloud/api/player/CloudPlayer.java

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.kyori.adventure.audience.Audience;
44
import net.kyori.adventure.text.Component;
55

6+
import java.util.Map;
67
import java.util.UUID;
78
import java.util.concurrent.CompletableFuture;
89

@@ -61,18 +62,60 @@ public interface CloudPlayer extends Audience {
6162
String getDisplayName();
6263

6364
/**
64-
* Returns the unique ID of the proxy the player is connected through.
65+
* Returns the name of the proxy the player is connected through.
6566
*
66-
* @return the proxy server ID
67+
* @return the proxy name, or null if unavailable
6768
*/
68-
String getConnectedProxyId();
69+
String getConnectedProxyName();
6970

7071
/**
71-
* Returns the unique ID of the server the player is currently on.
72+
* Returns the name of the server the player is currently on.
7273
*
73-
* @return the server ID, or null if not connected to a backend server
74+
* @return the server name, or null if not connected to a backend server
7475
*/
75-
String getConnectedServerId();
76+
String getConnectedServerName();
77+
78+
/**
79+
* Returns whether the player is currently online.
80+
*
81+
* @return true if online
82+
*/
83+
boolean isOnline();
84+
85+
/**
86+
* Returns accumulated online time in seconds.
87+
*
88+
* @return total online time in seconds
89+
*/
90+
long getOnlineTimeSeconds();
91+
92+
/**
93+
* Returns the active session ID when online.
94+
*
95+
* @return session ID, or null if unavailable
96+
*/
97+
String getSessionId();
98+
99+
/**
100+
* Returns the first seen timestamp as returned by the controller.
101+
*
102+
* @return ISO-8601 timestamp string, or null if unavailable
103+
*/
104+
String getFirstSeen();
105+
106+
/**
107+
* Returns the last seen timestamp as returned by the controller.
108+
*
109+
* @return ISO-8601 timestamp string, or null if unavailable
110+
*/
111+
String getLastSeen();
112+
113+
/**
114+
* Returns custom player properties.
115+
*
116+
* @return immutable map of properties (empty if none)
117+
*/
118+
Map<String, String> getProperties();
76119

77120
/**
78121
* Kicks the player from the network with the specified reason.

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
`signing`
1010
}
1111

12-
val baseVersion = "0.1.0-platform.16"
12+
val baseVersion = "0.1.0-platform.17"
1313
val commitHash = System.getenv("COMMIT_HASH")
1414
val isSnapshot = commitHash != null
1515

0 commit comments

Comments
 (0)