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

Adventure 4.3.0: Player list header/footer

Dieser Commit ist enthalten in:
Riley Park 2020-12-06 17:50:57 -08:00
Ursprung 9825f5891b
Commit 5da085d82f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: D831AF236C834E45
9 geänderte Dateien mit 89 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -32,11 +32,12 @@ dependencies {
// DEPRECATED: Will be removed in Velocity 2.0.0
api 'com.moandjiezana.toml:toml4j:0.7.2'
api "net.kyori:adventure-api:${adventureVersion}"
api "net.kyori:adventure-text-serializer-gson:${adventureVersion}"
api "net.kyori:adventure-text-serializer-legacy:${adventureVersion}"
api "net.kyori:adventure-text-serializer-plain:${adventureVersion}"
api "net.kyori:adventure-text-serializer-legacy-text3:${adventurePlatformVersion}"
api(platform("net.kyori:adventure-bom:${adventureVersion}"))
api("net.kyori:adventure-api")
api("net.kyori:adventure-text-serializer-gson")
api("net.kyori:adventure-text-serializer-legacy")
api("net.kyori:adventure-text-serializer-plain")
api("net.kyori:adventure-text-serializer-legacy-text3:${adventurePlatformVersion}") // adventure-platform
api "org.slf4j:slf4j-api:${slf4jVersion}"
api 'com.google.inject:guice:4.2.3'

Datei anzeigen

@ -146,6 +146,20 @@ public interface Player extends CommandSource, Identified, InboundConnection,
@Deprecated
void clearHeaderAndFooter();
/**
* Returns the player's player list header.
*
* @return this player's player list header
*/
Component getPlayerListHeader();
/**
* Returns the player's player list footer.
*
* @return this player's tab list
*/
Component getPlayerListFooter();
/**
* Returns the player's tab list.
*

Datei anzeigen

@ -28,7 +28,9 @@ public interface TabList {
*
* @param header the header component
* @param footer the footer component
* @deprecated Use {@link Player#sendPlayerListHeaderAndFooter(Component, Component)} instead
*/
@Deprecated
void setHeaderAndFooter(Component header, Component footer);
/**

Datei anzeigen

@ -21,7 +21,7 @@ allprojects {
ext {
// dependency versions
textVersion = '3.0.4'
adventureVersion = '4.2.0'
adventureVersion = '4.3.0'
adventurePlatformVersion = '4.0.0-SNAPSHOT'
junitVersion = '5.7.0'
slf4jVersion = '1.7.30'

Datei anzeigen

@ -66,7 +66,9 @@ dependencies {
implementation 'it.unimi.dsi:fastutil:8.4.1'
implementation 'net.kyori:event-method-asm:4.0.0-SNAPSHOT'
implementation 'net.kyori:adventure-nbt:4.0.0-SNAPSHOT'
implementation(platform("net.kyori:adventure-bom:${adventureVersion}"))
implementation("net.kyori:adventure-nbt")
implementation 'org.asynchttpclient:async-http-client:2.12.1'

Datei anzeigen

@ -45,6 +45,7 @@ import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Chat;
import com.velocitypowered.proxy.protocol.packet.ClientSettings;
import com.velocitypowered.proxy.protocol.packet.Disconnect;
import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter;
import com.velocitypowered.proxy.protocol.packet.KeepAlive;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest;
@ -61,6 +62,7 @@ import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@ -105,6 +107,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
private @Nullable VelocityServerConnection connectionInFlight;
private @Nullable PlayerSettings settings;
private @Nullable ModInfo modInfo;
private Component playerListHeader = Component.empty();
private Component playerListFooter = Component.empty();
private final VelocityTabList tabList;
private final VelocityServer server;
private ClientConnectionPhase connectionPhase;
@ -116,9 +120,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
@Nullable InetSocketAddress virtualHost, boolean onlineMode) {
this.server = server;
if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
this.tabList = new VelocityTabList(connection);
this.tabList = new VelocityTabList(this);
} else {
this.tabList = new VelocityTabListLegacy(connection);
this.tabList = new VelocityTabListLegacy(this);
}
this.profile = profile;
this.connection = connection;
@ -301,6 +305,33 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
}
}
@Override
public Component getPlayerListHeader() {
return this.playerListHeader;
}
@Override
public Component getPlayerListFooter() {
return this.playerListFooter;
}
@Override
public void sendPlayerListHeader(@NonNull final Component header) {
this.sendPlayerListHeaderAndFooter(header, this.playerListFooter);
}
@Override
public void sendPlayerListFooter(@NonNull final Component footer) {
this.sendPlayerListHeaderAndFooter(this.playerListHeader, footer);
}
@Override
public void sendPlayerListHeaderAndFooter(final Component header, final Component footer) {
this.playerListHeader = Objects.requireNonNull(header, "header");
this.playerListFooter = Objects.requireNonNull(footer, "footer");
this.connection.write(HeaderAndFooter.create(header, footer, this.getProtocolVersion()));
}
@Override
public void showTitle(net.kyori.adventure.title.@NonNull Title title) {
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(this
@ -363,6 +394,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
this.profile = profile.withProperties(Preconditions.checkNotNull(properties));
}
@Deprecated
@Override
public void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer) {
tabList.setHeaderAndFooter(header, footer);

Datei anzeigen

@ -8,6 +8,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
public class HeaderAndFooter implements MinecraftPacket {
@ -51,15 +52,8 @@ public class HeaderAndFooter implements MinecraftPacket {
return handler.handle(this);
}
public static HeaderAndFooter create(net.kyori.text.Component header,
net.kyori.text.Component footer) {
return new HeaderAndFooter(
net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.serialize(header),
net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.serialize(footer));
}
public static HeaderAndFooter create(net.kyori.adventure.text.Component header,
net.kyori.adventure.text.Component footer, ProtocolVersion protocolVersion) {
public static HeaderAndFooter create(Component header,
Component footer, ProtocolVersion protocolVersion) {
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(protocolVersion);
return new HeaderAndFooter(serializer.serialize(header), serializer.serialize(footer));
}

Datei anzeigen

@ -5,6 +5,7 @@ import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem;
import java.util.ArrayList;
@ -15,31 +16,39 @@ import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import net.kyori.text.Component;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;
public class VelocityTabList implements TabList {
protected final ConnectedPlayer player;
protected final MinecraftConnection connection;
protected final Map<UUID, VelocityTabListEntry> entries = new ConcurrentHashMap<>();
public VelocityTabList(MinecraftConnection connection) {
this.connection = connection;
public VelocityTabList(final ConnectedPlayer player) {
this.player = player;
this.connection = player.getConnection();
}
@Deprecated
@Override
public void setHeaderAndFooter(net.kyori.text.Component header,
net.kyori.text.Component footer) {
Preconditions.checkNotNull(header, "header");
Preconditions.checkNotNull(footer, "footer");
this.player.sendPlayerListHeaderAndFooter(
LegacyText3ComponentSerializer.get().deserialize(header),
LegacyText3ComponentSerializer.get().deserialize(footer)
);
}
@Deprecated
@Override
public void setHeaderAndFooter(Component header, Component footer) {
Preconditions.checkNotNull(header, "header");
Preconditions.checkNotNull(footer, "footer");
connection.write(HeaderAndFooter.create(header, footer));
}
@Override
public void setHeaderAndFooter(net.kyori.adventure.text.Component header,
net.kyori.adventure.text.Component footer) {
Preconditions.checkNotNull(header, "header");
Preconditions.checkNotNull(footer, "footer");
connection.write(HeaderAndFooter.create(header, footer, connection.getProtocolVersion()));
this.player.sendPlayerListHeaderAndFooter(header, footer);
}
@Override

Datei anzeigen

@ -3,7 +3,7 @@ package com.velocitypowered.proxy.tablist;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem.Item;
import java.util.Collections;
@ -18,14 +18,16 @@ public class VelocityTabListLegacy extends VelocityTabList {
private final Map<String, UUID> nameMapping = new ConcurrentHashMap<>();
public VelocityTabListLegacy(MinecraftConnection connection) {
super(connection);
public VelocityTabListLegacy(final ConnectedPlayer player) {
super(player);
}
@Deprecated
@Override
public void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer) {
}
@Deprecated
@Override
public void setHeaderAndFooter(Component header, Component footer) {
}