Skip to content

Commit 9c1bd7d

Browse files
committed
Add username() method
1 parent fb949ac commit 9c1bd7d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/org/codegame/client/GameSocket.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void connect(String gameId, String playerId, String playerSecret) throws
8383
}
8484
}
8585

86-
public void connect(String gameId) throws IOException {
86+
public void spectate(String gameId) throws IOException {
8787
if (session.gameURL != "")
8888
throw new IllegalStateException("This socket is already connected to a game.");
8989

@@ -169,6 +169,14 @@ public void removeCallback(String eventName, String id) {
169169
eventListeners.get(eventName).callbacks.remove(id);
170170
}
171171

172+
public String username(String playerID) throws IOException {
173+
if (usernameCache.containsKey(playerID))
174+
return usernameCache.get(playerID);
175+
var username = api.fetchUsername(session.gameId, playerID);
176+
usernameCache.put(playerID, username);
177+
return username;
178+
}
179+
172180
public Api getApi() {
173181
return api;
174182
}

0 commit comments

Comments
 (0)