From f59516165f76fbfa8e82313a49c6bef726630549 Mon Sep 17 00:00:00 2001 From: lexikiq Date: Fri, 11 Jun 2021 21:06:59 -0400 Subject: [PATCH] Rebase onto feature/adventure-pointers --- .../velocitypowered/api/command/CommandSource.java | 11 ++++++++--- .../java/com/velocitypowered/api/proxy/Player.java | 10 ---------- .../proxy/connection/client/ConnectedPlayer.java | 4 ++-- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/command/CommandSource.java b/api/src/main/java/com/velocitypowered/api/command/CommandSource.java index 2f465fda7..75748fb0c 100644 --- a/api/src/main/java/com/velocitypowered/api/command/CommandSource.java +++ b/api/src/main/java/com/velocitypowered/api/command/CommandSource.java @@ -14,12 +14,13 @@ import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.permission.PermissionChecker; -import net.kyori.adventure.pointer.Pointers; +import net.kyori.adventure.pointer.Pointer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer; import net.kyori.adventure.util.TriState; import org.checkerframework.checker.nullness.qual.NonNull; import org.jetbrains.annotations.NotNull; +import java.util.Optional; /** * Represents something that can be used to run a {@link Command}. @@ -43,8 +44,12 @@ public interface CommandSource extends Audience, PermissionSubject, PermissionCh } @Override - default @NotNull Pointers pointers() { - return Pointers.builder().withStatic(PermissionChecker.POINTER, this).build(); + @SuppressWarnings("unchecked") // safe casts + default @NotNull Optional get(final @NotNull Pointer pointer) { + if (pointer == PermissionChecker.POINTER) { + return Optional.of((T) this); + } + return Audience.super.get(pointer); } @Override diff --git a/api/src/main/java/com/velocitypowered/api/proxy/Player.java b/api/src/main/java/com/velocitypowered/api/proxy/Player.java index be83ee4b6..a06db7ba0 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/Player.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/Player.java @@ -28,7 +28,6 @@ import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Keyed; -import net.kyori.adventure.pointer.Pointers; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.text.event.ClickEvent; @@ -304,13 +303,4 @@ public interface Player extends CommandSource, Identified, InboundConnection, return HoverEvent.showEntity(op.apply(HoverEvent.ShowEntity.of(this, getUniqueId(), Component.text(getUsername())))); } - - @Override - default @NotNull Pointers pointers() { - return CommandSource.super.pointers().toBuilder() - .withDynamic(Identity.NAME, this::getUsername) - .withDynamic(Identity.DISPLAY_NAME, this::asComponent) - .withDynamic(Identity.UUID, this::getUniqueId) - .build(); - } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java index 1f58f0089..bfbd9038a 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java @@ -285,8 +285,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { return Optional.of((T) this.getUniqueId()); } else if (pointer == Identity.NAME) { return Optional.of((T) this.getGameProfile().getName()); - } else if (pointer == PermissionChecker.POINTER) { - return Optional.of((T) this.permissionChecker); + } else if (pointer == Identity.DISPLAY_NAME) { + return Optional.of((T) asComponent()); } return Player.super.get(pointer); }