| 1 | package net.minecraft.server.jsonrpc.internalapi;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import java.util.Optional;
|
| 5 | import java.util.UUID;
|
| 6 | import java.util.concurrent.CompletableFuture;
|
| 7 | import net.minecraft.server.jsonrpc.methods.ClientInfo;
|
| 8 | import net.minecraft.server.level.ServerPlayer;
|
| 9 | import net.minecraft.server.players.NameAndId;
|
| 10 | import net.minecraft.util.Util;
|
| 11 | import org.jspecify.annotations.Nullable;
|
| 12 |
|
| 13 | public interface MinecraftPlayerListService {
|
| 14 | List<ServerPlayer> getPlayers();
|
| 15 |
|
| 16 | @Nullable ServerPlayer getPlayer(UUID uuid);
|
| 17 |
|
| 18 | default CompletableFuture<Optional<NameAndId>> getUser(final Optional<UUID> id, final Optional<String> name) {
|
| 19 | if (id.isPresent()) {
|
| 20 | Optional<NameAndId> nameAndId = this.getCachedUserById(id.get());
|
| 21 | return nameAndId.isPresent()
|
| 22 | ? CompletableFuture.completedFuture(nameAndId)
|
| 23 | : CompletableFuture.supplyAsync(() -> this.fetchUserById(id.get()), Util.nonCriticalIoPool());
|
| 24 | } else {
|
| 25 | return name.isPresent()
|
| 26 | ? CompletableFuture.supplyAsync(() -> this.fetchUserByName(name.get()), Util.nonCriticalIoPool())
|
| 27 | : CompletableFuture.completedFuture(Optional.empty());
|
| 28 | }
|
| 29 | }
|
| 30 |
|
| 31 | Optional<NameAndId> fetchUserByName(String name);
|
| 32 |
|
| 33 | Optional<NameAndId> fetchUserById(UUID id);
|
| 34 |
|
| 35 | Optional<NameAndId> getCachedUserById(UUID id);
|
| 36 |
|
| 37 | Optional<ServerPlayer> getPlayer(Optional<UUID> id, Optional<String> name);
|
| 38 |
|
| 39 | List<ServerPlayer> getPlayersWithAddress(String ip);
|
| 40 |
|
| 41 | @Nullable ServerPlayer getPlayerByName(String name);
|
| 42 |
|
| 43 | void remove(ServerPlayer player, ClientInfo clientInfo);
|
| 44 | }
|
| 45 |
|