From 26f3cb43c7c8b81d0b10c79dde6c308b34b280fb Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sun, 16 Aug 2020 14:02:04 -0400 Subject: [PATCH] Clean up some Adventure support code, implement another sendMessage overload --- .../api/proxy/ProxyAudience.java | 55 +------------------ .../connection/client/ConnectedPlayer.java | 11 ++++ .../proxy/protocol/packet/Chat.java | 2 + 3 files changed, 16 insertions(+), 52 deletions(-) diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyAudience.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyAudience.java index 36ff915a5..0b06b8f9d 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyAudience.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyAudience.java @@ -1,12 +1,8 @@ package com.velocitypowered.api.proxy; import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.bossbar.BossBar; -import net.kyori.adventure.inventory.Book; -import net.kyori.adventure.sound.Sound; -import net.kyori.adventure.sound.SoundStop; +import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.text.Component; -import net.kyori.adventure.title.Title; import org.checkerframework.checker.nullness.qual.NonNull; /** @@ -23,52 +19,7 @@ public interface ProxyAudience extends Audience { void sendMessage(@NonNull Component message); @Override - default void sendActionBar(@NonNull Component message) { - - } - - @Override - default void showTitle(@NonNull Title title) { - - } - - @Override - default void clearTitle() { - - } - - @Override - default void resetTitle() { - - } - - @Override - default void showBossBar(@NonNull BossBar bar) { - - } - - @Override - default void hideBossBar(@NonNull BossBar bar) { - - } - - @Override - default void playSound(@NonNull Sound sound) { - - } - - @Override - default void playSound(@NonNull Sound sound, double x, double y, double z) { - - } - - @Override - default void stopSound(@NonNull SoundStop stop) { - - } - - @Override - default void openBook(@NonNull Book book) { - + default void sendMessage(@NonNull Component message, @NonNull MessageType type) { + sendMessage(message); } } 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 3dbfdcd6c..32805b992 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 @@ -65,6 +65,7 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.ThreadLocalRandom; +import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; @@ -260,6 +261,16 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player { connection.write(Chat.createClientbound(message, this.getProtocolVersion())); } + @Override + public void sendMessage(@NonNull Component message, @NonNull MessageType type) { + Preconditions.checkNotNull(message, "message"); + Preconditions.checkNotNull(type, "type"); + + Chat packet = Chat.createClientbound(message, this.getProtocolVersion()); + packet.setType(type == MessageType.CHAT ? Chat.CHAT_TYPE : Chat.SYSTEM_TYPE); + connection.write(packet); + } + @Override public void sendActionBar(net.kyori.adventure.text.@NonNull Component message) { if (getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java index fa4db7792..a42d2650b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Chat.java @@ -13,6 +13,8 @@ import java.util.UUID; public class Chat implements MinecraftPacket { public static final byte CHAT_TYPE = (byte) 0; + public static final byte SYSTEM_TYPE = (byte) 1; + public static final int MAX_SERVERBOUND_MESSAGE_LENGTH = 256; public static final UUID EMPTY_SENDER = new UUID(0, 0);