From 9b487d7d034fc97acf80ca020fc9dfcd7b93414e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 3 Apr 2020 17:20:14 -0500 Subject: [PATCH] Fix combat by sending the animate packet after damage (Closes #260) --- .../translators/bedrock/BedrockAnimateTranslator.java | 10 ++++++++-- .../bedrock/BedrockInventoryTransactionTranslator.java | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java index 33eea7651..7ccb24262 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java @@ -33,6 +33,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket; import com.nukkitx.protocol.bedrock.packet.AnimatePacket; +import java.util.concurrent.TimeUnit; + @Translator(packet = AnimatePacket.class) public class BedrockAnimateTranslator extends PacketTranslator { @@ -40,8 +42,12 @@ public class BedrockAnimateTranslator extends PacketTranslator { public void translate(AnimatePacket packet, GeyserSession session) { switch (packet.getAction()) { case SWING_ARM: - ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND); - session.getDownstream().getSession().send(swingArmPacket); + // Delay so entity damage can be processed first + session.getConnector().getGeneralThreadPool().schedule(() -> + session.getDownstream().getSession().send(new ClientPlayerSwingArmPacket(Hand.MAIN_HAND)), + 25, + TimeUnit.MILLISECONDS + ); break; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index cc399f107..de23b8a05 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -61,7 +61,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator