Only send the client brand on game join (#1299)

* Only send the client brand on game join

* Apply suggested changes
This commit is contained in:
Camotoy 2020-09-21 16:06:25 -04:00 committed by GitHub
parent 5fafa0759e
commit 2db1d16f5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 21 deletions

View file

@ -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<ServerJoinGamePacke
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(locale, (byte) session.getRenderDistance(), ChatVisibility.FULL, true, skinParts, HandPreference.RIGHT_HAND);
session.sendDownstreamPacket(clientSettingsPacket);
session.sendDownstreamPacket(new ClientPluginMessagePacket("minecraft:brand", PluginMessageUtils.getGeyserBrandData()));
if (!newDimension.equals(entity.getDimension())) {
DimensionUtils.switchDimension(session, newDimension);
}

View file

@ -23,39 +23,30 @@
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network.translators.java;
package org.geysermc.connector.utils;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerPluginMessagePacket;
import java.nio.charset.StandardCharsets;
@Translator(packet = ServerPluginMessagePacket.class)
public class JavaPluginMessageTranslator extends PacketTranslator<ServerPluginMessagePacket> {
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) {