Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Expand Adventure Support
Adds support for assorted Adventure interfaces
Dieser Commit ist enthalten in:
Ursprung
f579725002
Commit
3a1517f3a4
@ -8,18 +8,23 @@
|
|||||||
package com.velocitypowered.api.command;
|
package com.velocitypowered.api.command;
|
||||||
|
|
||||||
import com.velocitypowered.api.permission.PermissionSubject;
|
import com.velocitypowered.api.permission.PermissionSubject;
|
||||||
|
import com.velocitypowered.api.permission.Tristate;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.audience.MessageType;
|
import net.kyori.adventure.audience.MessageType;
|
||||||
import net.kyori.adventure.identity.Identified;
|
import net.kyori.adventure.identity.Identified;
|
||||||
import net.kyori.adventure.identity.Identity;
|
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.Component;
|
||||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||||
|
import net.kyori.adventure.util.TriState;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents something that can be used to run a {@link Command}.
|
* 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.
|
* Sends the specified {@code component} to the invoker.
|
||||||
@ -36,4 +41,19 @@ public interface CommandSource extends Audience, PermissionSubject {
|
|||||||
@NonNull MessageType type) {
|
@NonNull MessageType type) {
|
||||||
this.sendMessage(LegacyText3ComponentSerializer.get().serialize(message));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,16 +23,25 @@ import com.velocitypowered.api.util.title.Title;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.UnaryOperator;
|
||||||
import net.kyori.adventure.identity.Identified;
|
import net.kyori.adventure.identity.Identified;
|
||||||
import net.kyori.adventure.identity.Identity;
|
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.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.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a player who is connected to the proxy.
|
* Represents a player who is connected to the proxy.
|
||||||
*/
|
*/
|
||||||
public interface Player extends CommandSource, Identified, InboundConnection,
|
public interface Player extends CommandSource, Identified, InboundConnection,
|
||||||
ChannelMessageSource, ChannelMessageSink {
|
ChannelMessageSource, ChannelMessageSink, HoverEventSource<HoverEvent.ShowEntity>,
|
||||||
|
ComponentLike, Keyed {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player's current username.
|
* Returns the player's current username.
|
||||||
@ -275,4 +284,30 @@ public interface Player extends CommandSource, Identified, InboundConnection,
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren