3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Add MessageRaw support to BungeeCordMessageResponder

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-07-16 15:18:11 -04:00
Ursprung f6bdab8e53
Commit 21ad6a433f

Datei anzeigen

@ -17,7 +17,11 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.Optional;
import java.util.StringJoiner;
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
class BungeeCordMessageResponder {
@ -134,15 +138,24 @@ class BungeeCordMessageResponder {
}
private void processMessage(ByteBufDataInput in) {
processMessage0(in, LegacyComponentSerializer.legacy());
}
private void processMessageRaw(ByteBufDataInput in) {
processMessage0(in, GsonComponentSerializer.gson());
}
private void processMessage0(ByteBufDataInput in,
ComponentSerializer<Component, ?, String> serializer) {
String target = in.readUTF();
String message = in.readUTF();
Component messageComponent = serializer.deserialize(message);
if (target.equals("ALL")) {
for (Player player : proxy.getAllPlayers()) {
player.sendMessage(LegacyComponentSerializer.INSTANCE.deserialize(message));
}
proxy.sendMessage(messageComponent);
} else {
proxy.getPlayer(target).ifPresent(player -> {
player.sendMessage(LegacyComponentSerializer.INSTANCE.deserialize(message));
player.sendMessage(messageComponent);
});
}
}
@ -197,7 +210,7 @@ class BungeeCordMessageResponder {
private void processKick(ByteBufDataInput in) {
proxy.getPlayer(in.readUTF()).ifPresent(player -> {
String kickReason = in.readUTF();
player.disconnect(LegacyComponentSerializer.INSTANCE.deserialize(kickReason));
player.disconnect(LegacyComponentSerializer.legacy().deserialize(kickReason));
});
}
@ -312,6 +325,9 @@ class BungeeCordMessageResponder {
case "Message":
this.processMessage(in);
break;
case "MessageRaw":
this.processMessageRaw(in);
break;
case "GetServer":
this.processGetServer();
break;