From 3fa35b2cb94b628aaaa229742002eacfb0a42bad Mon Sep 17 00:00:00 2001 From: Kas-tle <26531652+Kas-tle@users.noreply.github.com> Date: Thu, 12 Oct 2023 06:02:57 -0700 Subject: [PATCH] Restrict game packets to state; Closes #4191 (#4210) Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> --- .../command/defaults/StatisticsCommand.java | 2 +- .../geyser/entity/type/InteractionEntity.java | 2 +- .../geyser/inventory/AnvilContainer.java | 4 +- .../geyser/inventory/click/ClickPlan.java | 2 +- .../updater/AnvilInventoryUpdater.java | 2 +- .../geyser/session/GeyserSession.java | 47 ++++++++++++++++--- .../session/cache/AdvancementsCache.java | 6 +-- .../geyser/session/cache/BookEditCache.java | 2 +- .../inventory/BeaconInventoryTranslator.java | 2 +- .../EnchantingInventoryTranslator.java | 2 +- .../inventory/LecternInventoryTranslator.java | 4 +- .../inventory/LoomInventoryTranslator.java | 2 +- .../MerchantInventoryTranslator.java | 2 +- .../inventory/PlayerInventoryTranslator.java | 6 +-- .../StonecutterInventoryTranslator.java | 2 +- .../bedrock/BedrockAnimateTranslator.java | 6 +-- .../BedrockBlockEntityDataTranslator.java | 4 +- .../BedrockCommandBlockUpdateTranslator.java | 4 +- .../BedrockContainerCloseTranslator.java | 2 +- ...BedrockInventoryTransactionTranslator.java | 28 +++++------ .../BedrockItemFrameDropItemTranslator.java | 2 +- .../BedrockLecternUpdateTranslator.java | 8 ++-- .../BedrockMobEquipmentTranslator.java | 4 +- .../BedrockMoveEntityAbsoluteTranslator.java | 2 +- .../bedrock/BedrockPlayerInputTranslator.java | 4 +- .../BedrockRequestAbilityTranslator.java | 2 +- .../bedrock/BedrockRespawnTranslator.java | 2 +- .../bedrock/BedrockShowCreditsTranslator.java | 2 +- .../entity/BedrockEntityEventTranslator.java | 2 +- .../player/BedrockActionTranslator.java | 40 +++++++--------- .../player/BedrockInteractTranslator.java | 8 ++-- .../player/BedrockMovePlayerTranslator.java | 4 +- .../player/BedrockRiderJumpTranslator.java | 2 +- .../BedrockLevelSoundEventTranslator.java | 2 +- .../java/JavaCustomQueryTranslator.java | 2 +- .../player/JavaPlayerPositionTranslator.java | 4 +- .../inventory/JavaOpenScreenTranslator.java | 2 +- .../JavaChunkBatchFinishedTranslator.java | 2 +- .../java/level/JavaGameEventTranslator.java | 2 +- .../geysermc/geyser/util/InventoryUtils.java | 8 ++-- 40 files changed, 132 insertions(+), 103 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java index ea2da51df..1ff12dea3 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/StatisticsCommand.java @@ -44,7 +44,7 @@ public class StatisticsCommand extends GeyserCommand { session.setWaitingForStatistics(true); ServerboundClientCommandPacket ServerboundClientCommandPacket = new ServerboundClientCommandPacket(ClientCommand.STATS); - session.sendDownstreamPacket(ServerboundClientCommandPacket); + session.sendDownstreamGamePacket(ServerboundClientCommandPacket); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java index c88f90f19..0917465d4 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/InteractionEntity.java @@ -68,7 +68,7 @@ public class InteractionEntity extends Entity { animatePacket.setAction(AnimatePacket.Action.SWING_ARM); session.sendUpstreamPacket(animatePacket); - session.sendDownstreamPacket(new ServerboundSwingPacket(hand)); + session.sendDownstreamGamePacket(new ServerboundSwingPacket(hand)); return InteractionResult.SUCCESS; } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java b/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java index 5b0800e44..e99b901a4 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java @@ -82,14 +82,14 @@ public class AnvilContainer extends Container { correctRename = plainNewName; // Java Edition sends a packet every time an item is renamed even slightly in GUI. Fortunately, this works out for us now ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainNewName); - session.sendDownstreamPacket(renameItemPacket); + session.sendDownstreamGamePacket(renameItemPacket); } else { // Restore formatting for item since we're not renaming correctRename = MessageTranslator.convertMessageLenient(originalName); // Java Edition sends the original custom name when not renaming, // if there isn't a custom name an empty string is sent ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(plainOriginalName); - session.sendDownstreamPacket(renameItemPacket); + session.sendDownstreamGamePacket(renameItemPacket); } useJavaLevelCost = false; diff --git a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java index bfe5a7d9d..f31f6d82f 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/click/ClickPlan.java @@ -152,7 +152,7 @@ public final class ClickPlan { changedItems ); - session.sendDownstreamPacket(clickPacket); + session.sendDownstreamGamePacket(clickPacket); } session.getPlayerInventory().setCursor(simulatedCursor, session); diff --git a/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java b/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java index ea4ef674b..aa7897038 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java @@ -120,7 +120,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater { // does not result in a FilterTextPacket String originalName = MessageTranslator.convertToPlainTextLenient(ItemUtils.getCustomName(input.getNbt()), session.locale()); ServerboundRenameItemPacket renameItemPacket = new ServerboundRenameItemPacket(originalName); - session.sendDownstreamPacket(renameItemPacket); + session.sendDownstreamGamePacket(renameItemPacket); anvilContainer.setNewName(null); } 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 673ff5f37..35b532905 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -1135,7 +1135,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { if (position != null) { ServerboundMovePlayerPosPacket packet = new ServerboundMovePlayerPosPacket(playerEntity.isOnGround(), position.getX(), position.getY(), position.getZ()); - sendDownstreamPacket(packet); + sendDownstreamGamePacket(packet); } lastMovementTimestamp = System.currentTimeMillis(); } @@ -1317,7 +1317,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { return false; } - sendDownstreamPacket(useItemPacket); + sendDownstreamGamePacket(useItemPacket); playerEntity.setFlag(EntityFlag.BLOCKING, true); // Metadata should be updated later return true; @@ -1351,7 +1351,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { if (playerEntity.getFlag(EntityFlag.BLOCKING)) { ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, Vector3i.ZERO, Direction.DOWN, 0); - sendDownstreamPacket(releaseItemPacket); + sendDownstreamGamePacket(releaseItemPacket); playerEntity.setFlag(EntityFlag.BLOCKING, false); return true; } @@ -1361,7 +1361,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { public void requestOffhandSwap() { ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO, Direction.DOWN, 0); - sendDownstreamPacket(swapHandsPacket); + sendDownstreamGamePacket(swapHandsPacket); } @Override @@ -1396,14 +1396,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { * Sends a chat message to the Java server. */ public void sendChat(String message) { - sendDownstreamPacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet())); + sendDownstreamGamePacket(new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0L, null, 0, new BitSet())); } /** * Sends a command to the Java server. */ public void sendCommand(String command) { - sendDownstreamPacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet())); + sendDownstreamGamePacket(new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0L, Collections.emptyList(), 0, new BitSet())); } public void setServerRenderDistance(int renderDistance) { @@ -1575,6 +1575,39 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { upstream.sendPacketImmediately(packet); } + /** + * Send a packet to the remote server if in the game state. + * + * @param packet the java edition packet from MCProtocolLib + */ + public void sendDownstreamGamePacket(Packet packet) { + sendDownstreamPacket(packet, ProtocolState.GAME); + } + + /** + * Send a packet to the remote server if in the login state. + * + * @param packet the java edition packet from MCProtocolLib + */ + public void sendDownstreamLoginPacket(Packet packet) { + sendDownstreamPacket(packet, ProtocolState.LOGIN); + } + + /** + * Send a packet to the remote server if in the specified state. + * + * @param packet the java edition packet from MCProtocolLib + * @param intendedState the state the client should be in + */ + public void sendDownstreamPacket(Packet packet, ProtocolState intendedState) { + if (protocol.getState() != intendedState) { + geyser.getLogger().debug("Tried to send " + packet.getClass().getSimpleName() + " packet while not in " + intendedState.name() + " state"); + return; + } + + sendDownstreamPacket(packet); + } + /** * Send a packet to the remote server. * @@ -1718,7 +1751,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { // We're "flying locked" in this gamemode flying = true; ServerboundPlayerAbilitiesPacket abilitiesPacket = new ServerboundPlayerAbilitiesPacket(true); - sendDownstreamPacket(abilitiesPacket); + sendDownstreamGamePacket(abilitiesPacket); } abilities.add(Ability.FLYING); } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java index 00b186292..db0321147 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java @@ -97,7 +97,7 @@ public class AdvancementsCache { } else { // Send a packet indicating that we intend to open this particular advancement window ServerboundSeenAdvancementsPacket packet = new ServerboundSeenAdvancementsPacket(id); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); // Wait for a response there } } @@ -137,7 +137,7 @@ public class AdvancementsCache { builder.closedResultHandler(() -> { // Indicate that we have closed the current advancement tab - session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket()); + session.sendDownstreamGamePacket(new ServerboundSeenAdvancementsPacket()); }).validResultHandler((response) -> { if (response.getClickedButtonId() < visibleAdvancements.size()) { @@ -146,7 +146,7 @@ public class AdvancementsCache { } else { buildAndShowMenuForm(); // Indicate that we have closed the current advancement tab - session.sendDownstreamPacket(new ServerboundSeenAdvancementsPacket()); + session.sendDownstreamGamePacket(new ServerboundSeenAdvancementsPacket()); } }); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java index 35bea7295..d1ebd0c78 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java @@ -68,7 +68,7 @@ public class BookEditCache { packet = null; return; } - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); packet = null; lastBookUpdate = System.currentTimeMillis(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java index a0b6ebe9c..00323ce83 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/BeaconInventoryTranslator.java @@ -114,7 +114,7 @@ public class BeaconInventoryTranslator extends AbstractBlockInventoryTranslator // Input a beacon payment BeaconPaymentAction beaconPayment = (BeaconPaymentAction) request.getActions()[0]; ServerboundSetBeaconPacket packet = new ServerboundSetBeaconPacket(toJava(beaconPayment.getPrimaryEffect()), toJava(beaconPayment.getSecondaryEffect())); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet())); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java index a1c928c6b..0085a7550 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/EnchantingInventoryTranslator.java @@ -129,7 +129,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla return rejectRequest(request); } ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), javaSlot); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); return acceptRequest(request, makeContainerEntries(session, inventory, IntSets.emptySet())); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java index ec0d4534d..92cd8a0d4 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/LecternInventoryTranslator.java @@ -102,7 +102,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { if (session.isDroppingLecternBook()) { // We have to enter the inventory GUI to eject the book ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), 3); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); session.setDroppingLecternBook(false); InventoryUtils.closeInventory(session, inventory.getJavaId(), false); } else if (lecternContainer.getBlockEntityTag() == null) { @@ -153,7 +153,7 @@ public class LecternInventoryTranslator extends BaseInventoryTranslator { session.getLecternCache().add(position); // Close the window - we will reopen it once the client has this data synced ServerboundContainerClosePacket closeWindowPacket = new ServerboundContainerClosePacket(lecternContainer.getJavaId()); - session.sendDownstreamPacket(closeWindowPacket); + session.sendDownstreamGamePacket(closeWindowPacket); InventoryUtils.closeInventory(session, inventory.getJavaId(), false); } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java index 8fb98a284..0e43ba660 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java @@ -149,7 +149,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator { // And the Java loom window has a fixed row/width of four // So... Number / 4 = row (so we don't have to bother there), and number % 4 is our column, which leads us back to our index. :) ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), index); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); GeyserItemStack inputCopy = inventory.getItem(0).copy(1); inputCopy.setNetId(session.getNextItemNetId()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java index e159827e8..c4f958ba1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/MerchantInventoryTranslator.java @@ -155,7 +155,7 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator { private ItemStackResponse handleTrade(GeyserSession session, Inventory inventory, ItemStackRequest request, int tradeChoice) { ServerboundSelectTradePacket packet = new ServerboundSelectTradePacket(tradeChoice); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); if (session.isEmulatePost1_13Logic()) { // 1.18 Java cooperates nicer than older versions diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java index b9468ac4f..613121dfd 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/PlayerInventoryTranslator.java @@ -359,7 +359,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator { } ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, sourceItem.getItemStack(dropAction.getCount())); - session.sendDownstreamPacket(creativeDropPacket); + session.sendDownstreamGamePacket(creativeDropPacket); sourceItem.sub(dropAction.getCount()); } @@ -494,7 +494,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator { dropStack = new ItemStack(javaCreativeItem.getId(), dropAction.getCount(), javaCreativeItem.getNbt()); } ServerboundSetCreativeModeSlotPacket creativeDropPacket = new ServerboundSetCreativeModeSlotPacket(-1, dropStack); - session.sendDownstreamPacket(creativeDropPacket); + session.sendDownstreamGamePacket(creativeDropPacket); break; } default: @@ -515,7 +515,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator { ItemStack itemStack = item.isEmpty() ? new ItemStack(-1, 0, null) : item.getItemStack(); ServerboundSetCreativeModeSlotPacket creativePacket = new ServerboundSetCreativeModeSlotPacket(slot, itemStack); - session.sendDownstreamPacket(creativePacket); + session.sendDownstreamGamePacket(creativePacket); } private static boolean isCraftingGrid(ItemStackRequestSlotData slotInfoData) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java index 0663866ed..50c040a0b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/StonecutterInventoryTranslator.java @@ -69,7 +69,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl if (container.getStonecutterButton() != button) { // Getting the index of the item in the Java stonecutter list ServerboundContainerButtonClickPacket packet = new ServerboundContainerButtonClickPacket(inventory.getJavaId(), button); - session.sendDownstreamPacket(packet); + session.sendDownstreamGamePacket(packet); container.setStonecutterButton(button); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java index 60ff187f5..33fbaed30 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockAnimateTranslator.java @@ -64,7 +64,7 @@ public class BedrockAnimateTranslator extends PacketTranslator { // and Bedrock 1.19.51. // Note for the future: we should probably largely ignore this packet and instead replicate // all actions on our end, and send swings where needed. - session.sendDownstreamPacket(new ServerboundSwingPacket(Hand.MAIN_HAND)); + session.sendDownstreamGamePacket(new ServerboundSwingPacket(Hand.MAIN_HAND)); session.activateArmAnimationTicking(); } }, @@ -77,12 +77,12 @@ public class BedrockAnimateTranslator extends PacketTranslator { // Packet value is a float of how long one has been rowing, so we convert that into a boolean session.setSteeringLeft(packet.getRowingTime() > 0.0); ServerboundPaddleBoatPacket steerLeftPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight()); - session.sendDownstreamPacket(steerLeftPacket); + session.sendDownstreamGamePacket(steerLeftPacket); } case ROW_RIGHT -> { session.setSteeringRight(packet.getRowingTime() > 0.0); ServerboundPaddleBoatPacket steerRightPacket = new ServerboundPaddleBoatPacket(session.isSteeringLeft(), session.isSteeringRight()); - session.sendDownstreamPacket(steerRightPacket); + session.sendDownstreamGamePacket(steerRightPacket); } } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java index f280f144f..bab5e59a5 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockBlockEntityDataTranslator.java @@ -108,7 +108,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator legacySlots = packet.getLegacySlots(); if (packet.getActions().size() == 1 && legacySlots.size() > 0) { @@ -453,13 +453,13 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator currentJavaPage) { for (int i = currentJavaPage; i < newJavaPage; i++) { ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 2); - session.sendDownstreamPacket(clickButtonPacket); + session.sendDownstreamGamePacket(clickButtonPacket); } } else { for (int i = currentJavaPage; i > newJavaPage; i--) { ServerboundContainerButtonClickPacket clickButtonPacket = new ServerboundContainerButtonClickPacket(session.getOpenInventory().getJavaId(), 1); - session.sendDownstreamPacket(clickButtonPacket); + session.sendDownstreamGamePacket(clickButtonPacket); } } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java index d045a6c24..f5086e29a 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMobEquipmentTranslator.java @@ -58,7 +58,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator session.sendDownstreamPacket(new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence())), + session.scheduleInEventLoop(() -> session.sendDownstreamGamePacket(new ServerboundUseItemPacket(Hand.MAIN_HAND, session.getWorldCache().nextPredictionSequence())), 50, TimeUnit.MILLISECONDS); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java index 4b5107bda..8a8749e34 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockMoveEntityAbsoluteTranslator.java @@ -72,6 +72,6 @@ public class BedrockMoveEntityAbsoluteTranslator extends PacketTranslator { public void translate(GeyserSession session, RespawnPacket packet) { if (packet.getState() == RespawnPacket.State.CLIENT_READY) { ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN); - session.sendDownstreamPacket(javaRespawnPacket); + session.sendDownstreamGamePacket(javaRespawnPacket); } } } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java index 0aec2a5d9..3314975ef 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockShowCreditsTranslator.java @@ -39,7 +39,7 @@ public class BedrockShowCreditsTranslator extends PacketTranslator { // Not sent as of 1.18.10 ServerboundSelectTradePacket selectTradePacket = new ServerboundSelectTradePacket(packet.getData()); - session.sendDownstreamPacket(selectTradePacket); + session.sendDownstreamGamePacket(selectTradePacket); session.scheduleInEventLoop(() -> { Inventory openInventory = session.getOpenInventory(); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java index 826a76575..bff097248 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockActionTranslator.java @@ -26,10 +26,6 @@ package org.geysermc.geyser.translator.protocol.bedrock.entity.player; import com.github.steveice10.mc.protocol.data.game.entity.object.Direction; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundInteractPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerAbilitiesPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket; -import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction; @@ -97,7 +93,7 @@ public class BedrockActionTranslator extends PacketTranslator } ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking()); - session.sendDownstreamPacket(interactPacket); + session.sendDownstreamGamePacket(interactPacket); break; case DAMAGE: ServerboundInteractPacket attackPacket = new ServerboundInteractPacket(entity.getEntityId(), InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking()); - session.sendDownstreamPacket(attackPacket); + session.sendDownstreamGamePacket(attackPacket); break; case LEAVE_VEHICLE: ServerboundPlayerCommandPacket sneakPacket = new ServerboundPlayerCommandPacket(entity.getEntityId(), PlayerState.START_SNEAKING); - session.sendDownstreamPacket(sneakPacket); + session.sendDownstreamGamePacket(sneakPacket); Entity currentVehicle = session.getPlayerEntity().getVehicle(); if (currentVehicle != null) { @@ -123,7 +123,7 @@ public class BedrockInteractTranslator extends PacketTranslator if (ridingEntity instanceof AbstractHorseEntity || (ridingEntity != null && ridingEntity.getDefinition().entityType() == EntityType.CHEST_BOAT)) { // This mob has an inventory of its own that we should open instead. ServerboundPlayerCommandPacket openVehicleWindowPacket = new ServerboundPlayerCommandPacket(session.getPlayerEntity().getEntityId(), PlayerState.OPEN_VEHICLE_INVENTORY); - session.sendDownstreamPacket(openVehicleWindowPacket); + session.sendDownstreamGamePacket(openVehicleWindowPacket); } else { session.setOpenInventory(session.getPlayerInventory()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java index cae25e2a3..d81c0abab 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/player/BedrockMovePlayerTranslator.java @@ -83,7 +83,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator { ServerboundClientCommandPacket javaRespawnPacket = new ServerboundClientCommandPacket(ClientCommand.RESPAWN); - session.sendDownstreamPacket(javaRespawnPacket); + session.sendDownstreamGamePacket(javaRespawnPacket); } case FIRST_TIME -> { ShowCreditsPacket showCreditsPacket = new ShowCreditsPacket(); diff --git a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java index 9141ee7ab..0348eca11 100644 --- a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java @@ -260,7 +260,7 @@ public class InventoryUtils { // If this is the item we're looking for if (geyserItem.getJavaId() == itemStack.getId() && Objects.equals(geyserItem.getNbt(), itemStack.getNbt())) { ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item - session.sendDownstreamPacket(packetToSend); + session.sendDownstreamGamePacket(packetToSend); return; } } @@ -274,7 +274,7 @@ public class InventoryUtils { if ((slot - 36) != inventory.getHeldItemSlot()) { setHotbarItem(session, slot); } - session.sendDownstreamPacket(actionPacket); + session.sendDownstreamGamePacket(actionPacket); } } @@ -325,7 +325,7 @@ public class InventoryUtils { } ServerboundPickItemPacket packetToSend = new ServerboundPickItemPacket(i); // https://wiki.vg/Protocol#Pick_Item - session.sendDownstreamPacket(packetToSend); + session.sendDownstreamGamePacket(packetToSend); return; } @@ -340,7 +340,7 @@ public class InventoryUtils { if ((slot - 36) != inventory.getHeldItemSlot()) { setHotbarItem(session, slot); } - session.sendDownstreamPacket(actionPacket); + session.sendDownstreamGamePacket(actionPacket); } else { session.getGeyser().getLogger().debug("Cannot find item for block " + itemName); }