Skip to content

Commit 97f116b

Browse files
committed
Always fall back to offline UUID when inspect lookup misses
- Resolve identifiers to a UUID in all cases by using OfflinePlayer fallback after Mojang miss - Remove `onlineMode` branching from `selectResolvedUuid` - Update tests to cover Mojang-miss fallback behavior and non-null resolution
1 parent d990732 commit 97f116b

2 files changed

Lines changed: 11 additions & 23 deletions

File tree

src/main/java/dev/noah/perplayerkit/commands/inspect/InspectCommandUtil.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ private InspectCommandUtil() {
5050
/**
5151
* Attempts to resolve a player identifier (name or UUID) to a UUID asynchronously.
5252
* This method first tries to parse as UUID, then checks online players synchronously,
53-
* and finally searches cached offline players and Mojang asynchronously.
53+
* and finally searches cached offline players and Mojang asynchronously before
54+
* falling back to the deterministic offline-mode UUID.
5455
*
5556
* @param identifier Player name or UUID string
56-
* @return CompletableFuture containing UUID if found, null otherwise
57+
* @return CompletableFuture containing the resolved UUID
5758
*/
5859
public static CompletableFuture<UUID> resolvePlayerIdentifierAsync(String identifier) {
5960
// First try to parse as UUID
@@ -73,7 +74,7 @@ public static CompletableFuture<UUID> resolvePlayerIdentifierAsync(String identi
7374
return CompletableFuture.supplyAsync(() -> {
7475
UUID cachedOfflinePlayer = findCachedOfflinePlayerUuid(identifier);
7576
return selectResolvedUuid(identifier, cachedOfflinePlayer,
76-
() -> lookupPlayerUuidFromMojang(identifier), Bukkit.getOnlineMode());
77+
() -> lookupPlayerUuidFromMojang(identifier));
7778
});
7879
}
7980

@@ -159,21 +160,17 @@ public static void showUsage(@NotNull Player player, @NotNull String commandName
159160
}
160161
}
161162

162-
static @Nullable UUID selectResolvedUuid(@NotNull String identifier, @Nullable UUID cachedOfflinePlayer,
163-
@NotNull Supplier<UUID> mojangLookup, boolean onlineMode) {
163+
static @NotNull UUID selectResolvedUuid(@NotNull String identifier, @Nullable UUID cachedOfflinePlayer,
164+
@NotNull Supplier<UUID> mojangLookup) {
164165
if (cachedOfflinePlayer != null) {
165166
return cachedOfflinePlayer;
166167
}
167168

168-
if (!onlineMode) {
169-
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + identifier).getBytes(StandardCharsets.UTF_8));
170-
}
171-
172169
UUID mojangUuid = mojangLookup.get();
173170
if (mojangUuid != null) {
174171
return mojangUuid;
175172
}
176173

177-
return null;
174+
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + identifier).getBytes(StandardCharsets.UTF_8));
178175
}
179176
}

src/test/java/dev/noah/perplayerkit/commands/inspect/InspectCommandUtilTest.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void selectResolvedUuidPrefersCachedOfflinePlayer() {
2424
UUID resolvedUuid = InspectCommandUtil.selectResolvedUuid("TargetPlayer", cachedUuid,
2525
() -> {
2626
throw new AssertionError("Mojang lookup should not run when cached player exists");
27-
}, false);
27+
});
2828

2929
assertEquals(cachedUuid, resolvedUuid);
3030
}
@@ -33,30 +33,21 @@ void selectResolvedUuidPrefersCachedOfflinePlayer() {
3333
void selectResolvedUuidUsesMojangResultWhenCacheMisses() {
3434
UUID mojangUuid = UUID.randomUUID();
3535

36-
UUID resolvedUuid = InspectCommandUtil.selectResolvedUuid("TargetPlayer", null, () -> mojangUuid, true);
36+
UUID resolvedUuid = InspectCommandUtil.selectResolvedUuid("TargetPlayer", null, () -> mojangUuid);
3737

3838
assertEquals(mojangUuid, resolvedUuid);
3939
}
4040

4141
@Test
42-
void selectResolvedUuidUsesOfflineFallbackWhenServerIsOfflineMode() {
42+
void selectResolvedUuidUsesOfflineFallbackWhenMojangLookupMisses() {
4343
String identifier = "TargetPlayer";
4444

45-
UUID resolvedUuid = InspectCommandUtil.selectResolvedUuid(identifier, null, () -> {
46-
throw new RuntimeException("mojang should not be consulted");
47-
}, false);
45+
UUID resolvedUuid = InspectCommandUtil.selectResolvedUuid(identifier, null, () -> null);
4846

4947
assertEquals(UUID.nameUUIDFromBytes(("OfflinePlayer:" + identifier).getBytes(StandardCharsets.UTF_8)),
5048
resolvedUuid);
5149
}
5250

53-
@Test
54-
void selectResolvedUuidReturnsNullWhenServerIsOnlineModeAndNoMatchExists() {
55-
UUID resolvedUuid = InspectCommandUtil.selectResolvedUuid("TargetPlayer", null, () -> null, true);
56-
57-
assertNull(resolvedUuid);
58-
}
59-
6051
@Test
6152
void findCachedOfflinePlayerUuidDoesNotScanOfflinePlayers() throws Exception {
6253
Method method = InspectCommandUtil.class.getDeclaredMethod("findCachedOfflinePlayerUuid", String.class);

0 commit comments

Comments
 (0)