package com.xfestudio.xfeservermanager.platform.bridge;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.UUID;
/** Opaque, versioned cursor for the stable UUID ordering of online-player pages. */
public final class PlayerPageCursor {
private static final String PREFIX = "v1:";
private PlayerPageCursor() {
}
public static String encode(UUID playerId) {
String payload = PREFIX + playerId.toString().toLowerCase(java.util.Locale.ROOT);
return Base64.getUrlEncoder().withoutPadding()
.encodeToString(payload.getBytes(StandardCharsets.US_ASCII));
}
/** Returns an empty key for the first page and a canonical UUID string otherwise. */
public static String afterKey(String cursor) {
if (cursor == null || cursor.isBlank()) {
return "";
}
if (cursor.length() > 128) {
throw new IllegalArgumentException("player cursor is invalid");
}
try {
String decoded = new String(Base64.getUrlDecoder().decode(cursor), StandardCharsets.US_ASCII);
if (!decoded.startsWith(PREFIX)) {
throw new IllegalArgumentException("player cursor version is unsupported");
}
return UUID.fromString(decoded.substring(PREFIX.length())).toString();
} catch (IllegalArgumentException exception) {
throw new IllegalArgumentException("player cursor is invalid", exception);
}
}
}
package com.xfestudio.xfeservermanager.platform.bridge;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.UUID;
/** Opaque, versioned cursor for the stable UUID ordering of online-player pages. */
public final class PlayerPageCursor {
private static final String PREFIX = "v1:";
private PlayerPageCursor() {
}
public static String encode(UUID playerId) {
String payload = PREFIX + playerId.toString().toLowerCase(java.util.Locale.ROOT);
return Base64.getUrlEncoder().withoutPadding()
.encodeToString(payload.getBytes(StandardCharsets.US_ASCII));
}
/** Returns an empty key for the first page and a canonical UUID string otherwise. */
public static String afterKey(String cursor) {
if (cursor == null || cursor.isBlank()) {
return "";
}
if (cursor.length() > 128) {
throw new IllegalArgumentException("player cursor is invalid");
}
try {
String decoded = new String(Base64.getUrlDecoder().decode(cursor), StandardCharsets.US_ASCII);
if (!decoded.startsWith(PREFIX)) {
throw new IllegalArgumentException("player cursor version is unsupported");
}
return UUID.fromString(decoded.substring(PREFIX.length())).toString();
} catch (IllegalArgumentException exception) {
throw new IllegalArgumentException("player cursor is invalid", exception);
}
}
}