mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
chore: address review comments
This commit is contained in:
parent
04f38287ce
commit
622434871d
@ -28,6 +28,7 @@ import com.plotsquared.core.database.DBFunc;
|
|||||||
import com.plotsquared.core.player.ConsolePlayer;
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
|
import com.plotsquared.core.plot.Plot;
|
||||||
import com.plotsquared.core.uuid.UUIDMapping;
|
import com.plotsquared.core.uuid.UUIDMapping;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentLike;
|
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 net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.jetbrains.annotations.Contract;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -216,7 +218,29 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
return StaticCaption.of(name);
|
return StaticCaption.of(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Caption> 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}.
|
||||||
|
* <br>
|
||||||
|
* Special Cases:
|
||||||
|
* <ul>
|
||||||
|
* <li>{@code null}: Resolves to a {@link TranslatableCaption} with the key {@code info.none}</li>
|
||||||
|
* <li>{@link DBFunc#EVERYONE}: Resolves to a {@link TranslatableCaption} with the key {@code info.everyone}</li>
|
||||||
|
* <li>{@link DBFunc#SERVER}: Resolves to a {@link TranslatableCaption} with the key {@code info.server}</li>
|
||||||
|
* </ul>
|
||||||
|
* <br>
|
||||||
|
* 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<Caption> getUsernameCaption(@Nullable UUID uuid) {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
return CompletableFuture.completedFuture(TranslatableCaption.of("info.none"));
|
return CompletableFuture.completedFuture(TranslatableCaption.of("info.none"));
|
||||||
}
|
}
|
||||||
@ -226,8 +250,9 @@ public abstract class PlayerManager<P extends PlotPlayer<? extends T>, T> {
|
|||||||
if (uuid.equals(DBFunc.SERVER)) {
|
if (uuid.equals(DBFunc.SERVER)) {
|
||||||
return CompletableFuture.completedFuture(TranslatableCaption.of("info.server"));
|
return CompletableFuture.completedFuture(TranslatableCaption.of("info.server"));
|
||||||
}
|
}
|
||||||
if (playerMap.containsKey(uuid)) {
|
P player = getPlayerIfExists(uuid);
|
||||||
return CompletableFuture.completedFuture(StaticCaption.of(playerMap.get(uuid).getName()));
|
if (player != null) {
|
||||||
|
return CompletableFuture.completedFuture(StaticCaption.of(player.getName()));
|
||||||
}
|
}
|
||||||
return PlotSquared.get().getImpromptuUUIDPipeline().getNames(Collections.singleton(uuid)).thenApply(mapping -> {
|
return PlotSquared.get().getImpromptuUUIDPipeline().getNames(Collections.singleton(uuid)).thenApply(mapping -> {
|
||||||
if (mapping.isEmpty()) {
|
if (mapping.isEmpty()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user