From 2db1d16f5c2b923bcc4bf3145e9e6f64a021829a Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Mon, 21 Sep 2020 16:06:25 -0400 Subject: [PATCH] Only send the client brand on game join (#1299) * Only send the client brand on game join * Apply suggested changes --- .../java/JavaJoinGameTranslator.java | 4 +++ .../PluginMessageUtils.java} | 33 +++++++------------ 2 files changed, 16 insertions(+), 21 deletions(-) rename connector/src/main/java/org/geysermc/connector/{network/translators/java/JavaPluginMessageTranslator.java => utils/PluginMessageUtils.java} (66%) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index a8fc122b..c479b23f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -28,6 +28,7 @@ package org.geysermc.connector.network.translators.java; import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference; import com.github.steveice10.mc.protocol.data.game.setting.ChatVisibility; import com.github.steveice10.mc.protocol.data.game.setting.SkinPart; +import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; import com.nukkitx.protocol.bedrock.data.GameRuleData; @@ -38,6 +39,7 @@ import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.utils.DimensionUtils; +import org.geysermc.connector.utils.PluginMessageUtils; import java.util.Arrays; import java.util.List; @@ -92,6 +94,8 @@ public class JavaJoinGameTranslator extends PacketTranslator { +public class PluginMessageUtils { - private static byte[] brandData; + private static final byte[] BRAND_DATA; static { byte[] data = GeyserConnector.NAME.getBytes(StandardCharsets.UTF_8); byte[] varInt = writeVarInt(data.length); - brandData = new byte[varInt.length + data.length]; - System.arraycopy(varInt, 0, brandData, 0, varInt.length); - System.arraycopy(data, 0, brandData, varInt.length, data.length); + BRAND_DATA = new byte[varInt.length + data.length]; + System.arraycopy(varInt, 0, BRAND_DATA, 0, varInt.length); + System.arraycopy(data, 0, BRAND_DATA, varInt.length, data.length); } - - @Override - public void translate(ServerPluginMessagePacket packet, GeyserSession session) { - if (packet.getChannel().equals("minecraft:brand")) { - session.sendDownstreamPacket( - new ClientPluginMessagePacket(packet.getChannel(), brandData) - ); - } + /** + * Get the prebuilt brand as a byte array + * @return the brand information of the Geyser client + */ + public static byte[] getGeyserBrandData() { + return BRAND_DATA; } private static byte[] writeVarInt(int value) {