From 9e296d197d00ce58498a91d0224e8e597dc3222d Mon Sep 17 00:00:00 2001 From: Draycia Date: Sun, 1 Oct 2023 21:22:01 -0700 Subject: [PATCH] Fix sponge profile resolver --- .../paper/users/PaperProfileResolver.java | 1 + .../sponge/users/SpongeProfileResolver.java | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/paper/src/main/java/net/draycia/carbon/paper/users/PaperProfileResolver.java b/paper/src/main/java/net/draycia/carbon/paper/users/PaperProfileResolver.java index b658411be..4ff452364 100644 --- a/paper/src/main/java/net/draycia/carbon/paper/users/PaperProfileResolver.java +++ b/paper/src/main/java/net/draycia/carbon/paper/users/PaperProfileResolver.java @@ -47,6 +47,7 @@ private PaperProfileResolver(final Server server, final MojangProfileResolver mo @Override public CompletableFuture<@Nullable UUID> resolveUUID(final String username, final boolean cacheOnly) { final @Nullable Player online = this.server.getPlayer(username); + if (online != null) { return CompletableFuture.completedFuture(online.getUniqueId()); } diff --git a/sponge/src/main/java/net/draycia/carbon/sponge/users/SpongeProfileResolver.java b/sponge/src/main/java/net/draycia/carbon/sponge/users/SpongeProfileResolver.java index ae51a6052..bce4c6f5f 100644 --- a/sponge/src/main/java/net/draycia/carbon/sponge/users/SpongeProfileResolver.java +++ b/sponge/src/main/java/net/draycia/carbon/sponge/users/SpongeProfileResolver.java @@ -2,6 +2,7 @@ import com.google.inject.Inject; import com.google.inject.Singleton; +import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; import net.draycia.carbon.common.users.MojangProfileResolver; @@ -10,7 +11,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.framework.qual.DefaultQualifier; import org.spongepowered.api.Sponge; -import org.spongepowered.api.profile.GameProfile; +import org.spongepowered.api.entity.living.player.server.ServerPlayer; @Singleton @DefaultQualifier(NonNull.class) @@ -25,14 +26,24 @@ private SpongeProfileResolver(final MojangProfileResolver mojang) { @Override public CompletableFuture<@Nullable UUID> resolveUUID(final String username, final boolean cacheOnly) { - return Sponge.server().gameProfileManager().basicProfile(username).thenApply(GameProfile::uuid).exceptionallyCompose(throwable -> - this.mojang.resolveUUID(username, cacheOnly)); + final Optional player = Sponge.server().player(username); + + if (player.isPresent()) { + return CompletableFuture.completedFuture(player.get().uniqueId()); + } + + return this.mojang.resolveUUID(username, cacheOnly); } @Override public CompletableFuture<@Nullable String> resolveName(final UUID uuid, final boolean cacheOnly) { - return Sponge.server().gameProfileManager().basicProfile(uuid).thenApply(profile -> profile.name().orElseThrow()).exceptionallyCompose(throwable -> - this.mojang.resolveName(uuid, cacheOnly)); + final Optional player = Sponge.server().player(uuid); + + if (player.isPresent()) { + return CompletableFuture.completedFuture(player.get().name()); + } + + return this.mojang.resolveName(uuid, cacheOnly); } @Override