diff --git a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch index e701b90a31..5e3d6711ce 100644 --- a/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/network/ServerGamePacketListenerImpl.java.patch @@ -277,7 +277,7 @@ ServerGamePacketListenerImpl.LOGGER.warn("{} (vehicle of {}) moved too quickly! {},{},{}", new Object[]{entity.getName().getString(), this.player.getName().getString(), d6, d7, d8}); this.send(ClientboundMoveVehiclePacket.fromEntity(entity)); return; -@@ -449,19 +582,72 @@ +@@ -449,20 +582,73 @@ d10 = d6 * d6 + d7 * d7 + d8 * d8; boolean flag2 = false; @@ -296,8 +296,8 @@ + this.player.absMoveTo(d0, d1, d2, this.player.getYRot(), this.player.getXRot()); // CraftBukkit this.send(ClientboundMoveVehiclePacket.fromEntity(entity)); return; -+ } -+ + } + + // CraftBukkit start - fire PlayerMoveEvent + Player player = this.getCraftPlayer(); + if (!this.hasMoved) { @@ -346,11 +346,12 @@ + this.justTeleported = false; + return; + } - } ++ } + // CraftBukkit end - ++ this.player.serverLevel().getChunkSource().move(this.player); entity.recordMovementThroughBlocks(new Vec3(d0, d1, d2), entity.position()); + Vec3 vec3d = new Vec3(entity.getX() - d0, entity.getY() - d1, entity.getZ() - d2); @@ -499,6 +685,7 @@ this.lastGoodZ = this.awaitingPositionFromClient.z; this.player.hasChangedDimension(); @@ -609,8 +610,8 @@ + if (i > Math.max(this.allowedPlayerTicks, 5)) { ServerGamePacketListenerImpl.LOGGER.debug("{} is sending move packets too frequently ({} packets since last tick)", this.player.getName().getString(), i); i = 1; -+ } -+ + } + + if (packet.hasRot || d10 > 0) { + this.allowedPlayerTicks -= 1; + } else { @@ -621,14 +622,14 @@ + speed = this.player.getAbilities().flyingSpeed * 20f; + } else { + speed = this.player.getAbilities().walkingSpeed * 10f; - } ++ } + // Paper start - Prevent moving into unloaded chunks + if (this.player.level().paperConfig().chunks.preventMovingIntoUnloadedChunks && (this.player.getX() != toX || this.player.getZ() != toZ) && !worldserver.areChunksLoadedForMove(this.player.getBoundingBox().expandTowards(new Vec3(toX, toY, toZ).subtract(this.player.position())))) { + this.internalTeleport(PositionMoveRotation.of(this.player), Collections.emptySet()); + return; + } + // Paper end - Prevent moving into unloaded chunks - ++ if (this.shouldCheckPlayerMovement(flag)) { float f2 = flag ? 300.0F : 100.0F; @@ -772,7 +773,7 @@ return true; } else { -@@ -1147,23 +1578,83 @@ +@@ -1147,23 +1578,90 @@ } public void teleport(double x, double y, double z, float yaw, float pitch) { @@ -824,6 +825,13 @@ + } + + public void internalTeleport(PositionMoveRotation positionmoverotation, Set set) { ++ // Paper start - Prevent teleporting dead entities ++ if (player.isRemoved()) { ++ LOGGER.info("Attempt to teleport removed player {} restricted", player.getScoreboardName()); ++ if (server.isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Attempt to teleport removed player"); ++ return; ++ } ++ // Paper end - Prevent teleporting dead entities + if (Float.isNaN(positionmoverotation.yRot())) { + positionmoverotation = new PositionMoveRotation(positionmoverotation.position(), positionmoverotation.deltaMovement(), 0, positionmoverotation.xRot()); + } @@ -859,7 +867,7 @@ if (this.player.hasClientLoaded()) { BlockPos blockposition = packet.getPos(); -@@ -1175,14 +1666,46 @@ +@@ -1175,14 +1673,46 @@ if (!this.player.isSpectator()) { ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND); @@ -908,7 +916,7 @@ this.player.drop(false); } -@@ -1199,6 +1722,12 @@ +@@ -1199,6 +1729,12 @@ case START_DESTROY_BLOCK: case ABORT_DESTROY_BLOCK: case STOP_DESTROY_BLOCK: @@ -921,7 +929,7 @@ this.player.gameMode.handleBlockBreakAction(blockposition, packetplayinblockdig_enumplayerdigtype, packet.getDirection(), this.player.level().getMaxY(), packet.getSequence()); this.player.connection.ackBlockChangesUpTo(packet.getSequence()); return; -@@ -1218,9 +1747,31 @@ +@@ -1218,9 +1754,31 @@ } } @@ -953,7 +961,7 @@ if (this.player.hasClientLoaded()) { this.player.connection.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1244,6 +1795,7 @@ +@@ -1244,6 +1802,7 @@ if (blockposition.getY() <= i) { if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) { @@ -961,7 +969,7 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); if (enuminteractionresult.consumesAction()) { -@@ -1281,6 +1833,8 @@ +@@ -1281,6 +1840,8 @@ @Override public void handleUseItem(ServerboundUseItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -970,12 +978,10 @@ if (this.player.hasClientLoaded()) { this.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1294,8 +1848,49 @@ - - if (f1 != this.player.getXRot() || f != this.player.getYRot()) { +@@ -1296,6 +1857,47 @@ this.player.absRotateTo(f, f1); -+ } -+ + } + + // CraftBukkit start + // Raytrace to look for 'rogue armswings' + double d0 = this.player.getX(); @@ -1006,8 +1012,8 @@ + cancelled = event.useItemInHand() == Event.Result.DENY; + } + this.player.gameMode.firedInteract = false; - } - ++ } ++ + if (cancelled) { + this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524 + return; @@ -1020,7 +1026,7 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); if (enuminteractionresult instanceof InteractionResult.Success) { -@@ -1321,7 +1916,7 @@ +@@ -1321,7 +1923,7 @@ Entity entity = packet.getEntity(worldserver); if (entity != null) { @@ -1029,7 +1035,7 @@ return; } } -@@ -1342,6 +1937,13 @@ +@@ -1342,6 +1944,13 @@ @Override public void onDisconnect(DisconnectionDetails info) { @@ -1043,7 +1049,7 @@ ServerGamePacketListenerImpl.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), info.reason().getString()); this.removePlayerFromWorld(); super.onDisconnect(info); -@@ -1349,10 +1951,20 @@ +@@ -1349,10 +1958,20 @@ private void removePlayerFromWorld() { this.chatMessageChain.close(); @@ -1066,7 +1072,7 @@ this.player.getTextFilter().leave(); } -@@ -1367,7 +1979,16 @@ +@@ -1367,7 +1986,16 @@ @Override public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1083,7 +1089,7 @@ if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) { this.player.stopUsingItem(); } -@@ -1376,11 +1997,18 @@ +@@ -1376,11 +2004,18 @@ this.player.resetLastActionTime(); } else { ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); @@ -1102,7 +1108,7 @@ Optional optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages()); if (!optional.isEmpty()) { -@@ -1394,27 +2022,44 @@ +@@ -1394,27 +2029,44 @@ return; } @@ -1154,7 +1160,7 @@ ParseResults parseresults = this.parseCommand(command); if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { -@@ -1431,19 +2076,37 @@ +@@ -1431,19 +2083,37 @@ if (!optional.isEmpty()) { this.tryHandleChat(packet.command(), () -> { @@ -1196,7 +1202,7 @@ } catch (SignedMessageChain.DecodeException signedmessagechain_a) { this.handleMessageDecodeFailure(signedmessagechain_a); return; -@@ -1451,10 +2114,10 @@ +@@ -1451,10 +2121,10 @@ CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map); @@ -1209,7 +1215,7 @@ } private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) { -@@ -1530,14 +2193,20 @@ +@@ -1530,14 +2200,20 @@ return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack()); } @@ -1234,7 +1240,7 @@ } } -@@ -1566,6 +2235,127 @@ +@@ -1566,6 +2242,127 @@ return false; } @@ -1362,7 +1368,7 @@ private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException { SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages); -@@ -1573,13 +2363,42 @@ +@@ -1573,13 +2370,42 @@ } private void broadcastChatMessage(PlayerChatMessage message) { @@ -1410,7 +1416,7 @@ this.disconnect((Component) Component.translatable("disconnect.spam")); } -@@ -1601,7 +2420,33 @@ +@@ -1601,7 +2427,33 @@ @Override public void handleAnimate(ServerboundSwingPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1444,7 +1450,7 @@ this.player.swing(packet.getHand()); } -@@ -1609,6 +2454,29 @@ +@@ -1609,6 +2461,29 @@ public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasClientLoaded()) { @@ -1474,7 +1480,7 @@ this.player.resetLastActionTime(); Entity entity; PlayerRideableJumping ijumpable; -@@ -1616,6 +2484,11 @@ +@@ -1616,6 +2491,11 @@ switch (packet.getAction()) { case PRESS_SHIFT_KEY: this.player.setShiftKeyDown(true); @@ -1486,7 +1492,7 @@ break; case RELEASE_SHIFT_KEY: this.player.setShiftKeyDown(false); -@@ -1691,6 +2564,12 @@ +@@ -1691,6 +2571,12 @@ } public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) { @@ -1499,7 +1505,7 @@ this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params)); this.addPendingMessage(message); } -@@ -1703,6 +2582,13 @@ +@@ -1703,6 +2589,13 @@ return this.connection.getRemoteAddress(); } @@ -1513,7 +1519,7 @@ public void switchToConfig() { this.waitingForSwitchToConfig = true; this.removePlayerFromWorld(); -@@ -1718,9 +2604,17 @@ +@@ -1718,9 +2611,17 @@ @Override public void handleInteract(ServerboundInteractPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1531,7 +1537,7 @@ this.player.resetLastActionTime(); this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); -@@ -1733,20 +2627,58 @@ +@@ -1733,20 +2634,58 @@ if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { packet.dispatch(new ServerboundInteractPacket.Handler() { @@ -1594,7 +1600,7 @@ } } -@@ -1755,19 +2687,20 @@ +@@ -1755,19 +2694,20 @@ @Override public void onInteraction(InteractionHand hand) { @@ -1618,7 +1624,7 @@ label23: { if (entity instanceof AbstractArrow) { -@@ -1785,6 +2718,11 @@ +@@ -1785,6 +2725,11 @@ } ServerGamePacketListenerImpl.this.player.attack(entity); @@ -1630,7 +1636,7 @@ return; } } -@@ -1795,7 +2733,26 @@ +@@ -1795,7 +2740,26 @@ }); } } @@ -1657,7 +1663,7 @@ } } -@@ -1809,7 +2766,7 @@ +@@ -1809,7 +2773,7 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; @@ -1666,7 +1672,7 @@ this.resetPosition(); CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD); } else { -@@ -1817,11 +2774,11 @@ +@@ -1817,11 +2781,11 @@ return; } @@ -1680,7 +1686,7 @@ } } break; -@@ -1833,16 +2790,27 @@ +@@ -1833,16 +2797,27 @@ @Override public void handleContainerClose(ServerboundContainerClosePacket packet) { @@ -1710,7 +1716,7 @@ this.player.containerMenu.sendAllDataToRemote(); } else if (!this.player.containerMenu.stillValid(this.player)) { ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); -@@ -1855,7 +2823,284 @@ +@@ -1855,7 +2830,284 @@ boolean flag = packet.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -1996,7 +2002,7 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1901,8 +3146,22 @@ +@@ -1901,8 +3153,22 @@ return; } @@ -2020,7 +2026,7 @@ if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) { this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display())); } -@@ -1917,6 +3176,7 @@ +@@ -1917,6 +3183,7 @@ @Override public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -2028,7 +2034,7 @@ this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1945,7 +3205,44 @@ +@@ -1945,7 +3212,44 @@ boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); @@ -2073,7 +2079,7 @@ if (flag1 && flag2) { this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack); this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack); -@@ -1964,7 +3261,19 @@ +@@ -1964,7 +3268,19 @@ @Override public void handleSignUpdate(ServerboundSignUpdatePacket packet) { @@ -2094,7 +2100,7 @@ this.filterTextPacket(list).thenAcceptAsync((list1) -> { this.updateSignText(packet, list1); -@@ -1972,6 +3281,7 @@ +@@ -1972,6 +3288,7 @@ } private void updateSignText(ServerboundSignUpdatePacket packet, List signText) { @@ -2102,7 +2108,7 @@ this.player.resetLastActionTime(); ServerLevel worldserver = this.player.serverLevel(); BlockPos blockposition = packet.getPos(); -@@ -1993,7 +3303,17 @@ +@@ -1993,7 +3310,17 @@ @Override public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -2121,7 +2127,7 @@ } @Override -@@ -2002,6 +3322,7 @@ +@@ -2002,6 +3329,7 @@ boolean flag = this.player.isModelPartShown(PlayerModelPart.HAT); this.player.updateOptions(packet.information()); @@ -2129,7 +2135,7 @@ if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) { this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player)); } -@@ -2058,7 +3379,7 @@ +@@ -2058,7 +3386,7 @@ if (!this.waitingForSwitchToConfig) { throw new IllegalStateException("Client acknowledged config, but none was requested"); } else { @@ -2138,7 +2144,7 @@ } } -@@ -2083,8 +3404,10 @@ +@@ -2083,8 +3411,10 @@ }); }