3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Expand Adventure Support

Adds support for assorted Adventure interfaces
Dieser Commit ist enthalten in:
lexikiq 2021-06-11 19:39:40 -04:00
Ursprung f579725002
Commit 3a1517f3a4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: AE6C11E94FDBB116
2 geänderte Dateien mit 57 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -8,18 +8,23 @@
package com.velocitypowered.api.command;
import com.velocitypowered.api.permission.PermissionSubject;
import com.velocitypowered.api.permission.Tristate;
import net.kyori.adventure.audience.Audience;
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.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;
/**
* Represents something that can be used to run a {@link Command}.
*/
public interface CommandSource extends Audience, PermissionSubject {
public interface CommandSource extends Audience, PermissionSubject, PermissionChecker {
/**
* Sends the specified {@code component} to the invoker.
@ -36,4 +41,19 @@ public interface CommandSource extends Audience, PermissionSubject {
@NonNull MessageType type) {
this.sendMessage(LegacyText3ComponentSerializer.get().serialize(message));
}
@Override
default @NotNull Pointers pointers() {
return Pointers.builder().withStatic(PermissionChecker.POINTER, this).build();
}
@Override
default @NotNull TriState value(String permission) {
Tristate state = getPermissionValue(permission);
if (state == Tristate.TRUE)
return TriState.TRUE;
if (state == Tristate.UNDEFINED)
return TriState.NOT_SET;
return TriState.FALSE;
}
}

Datei anzeigen

@ -23,16 +23,25 @@ import com.velocitypowered.api.util.title.Title;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.function.UnaryOperator;
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.HoverEvent;
import net.kyori.adventure.text.event.HoverEventSource;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
/**
* Represents a player who is connected to the proxy.
*/
public interface Player extends CommandSource, Identified, InboundConnection,
ChannelMessageSource, ChannelMessageSink {
ChannelMessageSource, ChannelMessageSink, HoverEventSource<HoverEvent.ShowEntity>,
ComponentLike, Keyed {
/**
* Returns the player's current username.
@ -275,4 +284,30 @@ public interface Player extends CommandSource, Identified, InboundConnection,
*/
@Override
boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data);
@Override
default @NotNull Key key() {
return Key.key("player");
}
@Override
default @NotNull Component asComponent() {
return Component.text(getUsername()).hoverEvent(this);
}
@Override
default @NotNull HoverEvent<HoverEvent.ShowEntity> asHoverEvent(
@NotNull UnaryOperator<HoverEvent.ShowEntity> op) {
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();
}
}