diff --git a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java index 7ce2c0403..728654f0d 100644 --- a/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java +++ b/Core/src/main/java/com/plotsquared/core/util/PlayerManager.java @@ -28,6 +28,7 @@ import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.OfflinePlotPlayer; import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.Plot; import com.plotsquared.core.uuid.UUIDMapping; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; @@ -37,6 +38,7 @@ import net.kyori.adventure.text.minimessage.tag.Tag; import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.jetbrains.annotations.Contract; import java.util.ArrayList; import java.util.Collection; @@ -216,7 +218,29 @@ public abstract class PlayerManager

, T> { return StaticCaption.of(name); } - public CompletableFuture getUsernameCaption(@Nullable UUID uuid) { + /** + * Resolves a UUID to a formatted {@link Caption} representing the player behind the UUID. + * Returns a {@link CompletableFuture} instead of a plain {@link UUID} as this method may query the + * {@link com.plotsquared.core.uuid.UUIDPipeline ImpromptuUUIDPipeline}. + *
+ * Special Cases: + *

+ *
+ * Otherwise, if the UUID is a valid UUID and not reserved by PlotSquared itself, this method first attempts to query the + * online players ({@link #getPlayerIfExists(UUID)}) for the specific UUID. + * If no online player was found for that UUID, the {@link com.plotsquared.core.uuid.UUIDPipeline ImpromptuUUIDPipeline} is + * queried to retrieve the known username + * + * @param uuid The UUID of the player (for example provided by {@link Plot#getOwner()} + * @return A CompletableFuture resolving to a Caption representing the players name of the uuid + * @since TODO + */ + @Contract("_->!null") + public @NonNull CompletableFuture getUsernameCaption(@Nullable UUID uuid) { if (uuid == null) { return CompletableFuture.completedFuture(TranslatableCaption.of("info.none")); } @@ -226,8 +250,9 @@ public abstract class PlayerManager

, T> { if (uuid.equals(DBFunc.SERVER)) { return CompletableFuture.completedFuture(TranslatableCaption.of("info.server")); } - if (playerMap.containsKey(uuid)) { - return CompletableFuture.completedFuture(StaticCaption.of(playerMap.get(uuid).getName())); + P player = getPlayerIfExists(uuid); + if (player != null) { + return CompletableFuture.completedFuture(StaticCaption.of(player.getName())); } return PlotSquared.get().getImpromptuUUIDPipeline().getNames(Collections.singleton(uuid)).thenApply(mapping -> { if (mapping.isEmpty()) {