From 53d002656ff3ec8259fed248b5097a4f1697cc34 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Thu, 8 Jun 2023 23:43:45 -0400 Subject: [PATCH] Update EmotePacket creation for 1.20 (#3841) Include xuid and platformId in EmotePacket --- .../geyser/session/GeyserSession.java | 4 ++- .../entity/player/BedrockEmoteTranslator.java | 29 +++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index a2b16ff3c..641473e22 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -1949,8 +1949,10 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } EmotePacket packet = new EmotePacket(); - packet.setEmoteId(emoteId); packet.setRuntimeEntityId(entity.getGeyserId()); + packet.setXuid(""); + packet.setPlatformId(""); // BDS sends empty + packet.setEmoteId(emoteId); sendUpstreamPacket(packet); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java index f499cbe64..7a37aa72e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockEmoteTranslator.java @@ -56,21 +56,38 @@ public class BedrockEmoteTranslator extends PacketTranslator { } int javaId = session.getPlayerEntity().getEntityId(); + String xuid = session.getAuthData().xuid(); + String emote = packet.getEmoteId(); for (GeyserSession otherSession : session.getGeyser().getSessionManager().getSessions().values()) { if (otherSession != session) { if (otherSession.isClosed()) continue; if (otherSession.getEventLoop().inEventLoop()) { - playEmote(otherSession, javaId, packet.getEmoteId()); + playEmote(otherSession, javaId, xuid, emote); } else { - otherSession.executeInEventLoop(() -> playEmote(otherSession, javaId, packet.getEmoteId())); + otherSession.executeInEventLoop(() -> playEmote(otherSession, javaId, xuid, emote)); } } } } - private void playEmote(GeyserSession otherSession, int javaId, String emoteId) { - Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId); // Must be ran on same thread - if (!(otherEntity instanceof PlayerEntity otherPlayer)) return; - otherSession.showEmote(otherPlayer, emoteId); + /** + * Play an emote by an emoter to the given session. + * This method must be called within the session's event loop. + * + * @param session the session to show the emote to + * @param emoterJavaId the java id of the emoter + * @param emoterXuid the xuid of the emoter + * @param emoteId the emote to play + */ + private static void playEmote(GeyserSession session, int emoterJavaId, String emoterXuid, String emoteId) { + Entity emoter = session.getEntityCache().getEntityByJavaId(emoterJavaId); // Must be ran on same thread + if (emoter instanceof PlayerEntity) { + EmotePacket packet = new EmotePacket(); + packet.setRuntimeEntityId(emoter.getGeyserId()); + packet.setXuid(emoterXuid); + packet.setPlatformId(""); // BDS sends empty + packet.setEmoteId(emoteId); + session.sendUpstreamPacket(packet); + } } }