Skip to content

Commit

Permalink
Fix name lookups to invalid players
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed Oct 2, 2024
1 parent 4102af8 commit 06be778
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bukkit/src/main/java/org/popcraft/bolt/util/Profiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public final class Profiles {
private static final Set<String> KNOWN_NULL_LOOKUPS_BY_NAME = ConcurrentHashMap.newKeySet();
private static final String NIL_UUID_STRING = "00000000-0000-0000-0000-000000000000";
public static final UUID NIL_UUID = UUID.fromString(NIL_UUID_STRING);
public static final int MAX_NAME_LENGTH = 16;

private Profiles() {
}
Expand All @@ -47,7 +48,7 @@ public static Profile findProfileByName(final String name) {
}

public static CompletableFuture<Profile> lookupProfileByName(final String name) {
if (name == null || name.isEmpty() || NIL_UUID_STRING.equals(name) || KNOWN_NULL_LOOKUPS_BY_NAME.contains(name)) {
if (name == null || name.isEmpty() || NIL_UUID_STRING.equals(name) || name.length() > MAX_NAME_LENGTH || KNOWN_NULL_LOOKUPS_BY_NAME.contains(name)) {
return CompletableFuture.completedFuture(SimpleProfileCache.EMPTY_PROFILE);
}
final PlayerProfile playerProfile = Bukkit.createPlayerProfile(name);
Expand All @@ -60,7 +61,9 @@ public static CompletableFuture<Profile> lookupProfileByName(final String name)
KNOWN_NULL_LOOKUPS_BY_NAME.add(name);
}
});
return updatedProfile.thenApply(PlayerProfile::getUniqueId).thenApply(profileCache::getProfile);
return updatedProfile.thenApply(PlayerProfile::getUniqueId)
.thenApply(profileCache::getProfile)
.exceptionally(ignored -> SimpleProfileCache.EMPTY_PROFILE);
}

public static CompletableFuture<Profile> findOrLookupProfileByName(final String name) {
Expand Down Expand Up @@ -105,7 +108,9 @@ public static CompletableFuture<Profile> lookupProfileByUniqueId(final UUID uuid
KNOWN_NULL_LOOKUPS_BY_UUID.add(uuid);
}
});
return updatedProfile.thenApply(PlayerProfile::getName).thenApply(profileCache::getProfile);
return updatedProfile.thenApply(PlayerProfile::getName)
.thenApply(profileCache::getProfile)
.exceptionally(ignored -> SimpleProfileCache.EMPTY_PROFILE);
}

public static CompletableFuture<Profile> findOrLookupProfileByUniqueId(final UUID uuid) {
Expand Down

0 comments on commit 06be778

Please sign in to comment.