diff --git a/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemOnPacket.java.patch b/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemOnPacket.java.patch index 8569d7ec7a..1e2cc2dc52 100644 --- a/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemOnPacket.java.patch +++ b/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemOnPacket.java.patch @@ -5,3 +5,19 @@ package net.minecraft.network.protocol.game; import net.minecraft.network.FriendlyByteBuf; +@@ -13,6 +14,7 @@ + private final BlockHitResult blockHit; + private final InteractionHand hand; + private final int sequence; ++ public long timestamp; // Spigot + + public ServerboundUseItemOnPacket(InteractionHand hand, BlockHitResult blockHitResult, int sequence) { + this.hand = hand; +@@ -21,6 +23,7 @@ + } + + private ServerboundUseItemOnPacket(FriendlyByteBuf buf) { ++ this.timestamp = System.currentTimeMillis(); // Spigot + this.hand = (InteractionHand) buf.readEnum(InteractionHand.class); + this.blockHit = buf.readBlockHitResult(); + this.sequence = buf.readVarInt(); diff --git a/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemPacket.java.patch b/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemPacket.java.patch index 9560378696..45ba3ec19d 100644 --- a/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemPacket.java.patch +++ b/paper-server/patches/sources/net/minecraft/network/protocol/game/ServerboundUseItemPacket.java.patch @@ -5,3 +5,19 @@ package net.minecraft.network.protocol.game; import net.minecraft.network.FriendlyByteBuf; +@@ -13,6 +14,7 @@ + private final int sequence; + private final float yRot; + private final float xRot; ++ public long timestamp; // Spigot + + public ServerboundUseItemPacket(InteractionHand hand, int sequence, float yaw, float pitch) { + this.hand = hand; +@@ -22,6 +24,7 @@ + } + + private ServerboundUseItemPacket(FriendlyByteBuf buf) { ++ this.timestamp = System.currentTimeMillis(); // Spigot + this.hand = (InteractionHand) buf.readEnum(InteractionHand.class); + this.sequence = buf.readVarInt(); + this.yRot = buf.readFloat(); 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 47657cfcce..74a240713c 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 @@ -40,7 +40,7 @@ import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; -@@ -192,12 +195,70 @@ +@@ -192,11 +195,69 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; @@ -50,7 +50,7 @@ import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; import org.slf4j.Logger; - ++ +// CraftBukkit start +import com.mojang.datafixers.util.Pair; +import java.util.Arrays; @@ -107,10 +107,9 @@ +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.SmithingInventory; +// CraftBukkit end -+ + public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener { - static final Logger LOGGER = LogUtils.getLogger(); @@ -247,7 +308,7 @@ private boolean waitingForSwitchToConfig; @@ -127,7 +126,7 @@ - this.chatMessageChain = new FutureChain(server); + this.chatMessageChain = new FutureChain(server.chatExecutor); // CraftBukkit - async chat } -+ + + // CraftBukkit start - add fields and methods + private int lastTick = MinecraftServer.currentTick; + private int allowedPlayerTicks = 1; @@ -143,7 +142,7 @@ + private float lastYaw = Float.MAX_VALUE; + private boolean justTeleported = false; + // CraftBukkit end - ++ @Override public void tick() { + org.bukkit.craftbukkit.SpigotTimings.playerConnectionTimer.startTiming(); // Spigot @@ -223,7 +222,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; -@@ -455,14 +574,67 @@ +@@ -455,13 +574,66 @@ } entity.absMoveTo(d3, d4, d5, f, f1); @@ -235,8 +234,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) { @@ -285,12 +284,11 @@ + 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 +671,7 @@ this.lastGoodZ = this.awaitingPositionFromClient.z; this.player.hasChangedDimension(); @@ -428,20 +426,20 @@ + 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 { + this.allowedPlayerTicks = 20; -+ } + } + double speed; + if (this.player.getAbilities().flying) { + speed = this.player.getAbilities().flyingSpeed * 20f; + } else { + speed = this.player.getAbilities().walkingSpeed * 10f; + } -+ + if (this.shouldCheckPlayerMovement(flag)) { float f2 = flag ? 300.0F : 100.0F; @@ -680,15 +678,38 @@ this.player.drop(false); } -@@ -1221,6 +1607,7 @@ +@@ -1218,9 +1604,30 @@ + } + } + ++ // Spigot start - limit place/interactions ++ private int limitedPackets; ++ private long lastLimitedPacket = -1; ++ ++ private boolean checkLimit(long timestamp) { ++ if (this.lastLimitedPacket != -1 && timestamp - this.lastLimitedPacket < 30 && this.limitedPackets++ >= 4) { ++ return false; ++ } ++ ++ if (this.lastLimitedPacket == -1 || timestamp - this.lastLimitedPacket >= 30) { ++ this.lastLimitedPacket = timestamp; ++ this.limitedPackets = 0; ++ return true; ++ } ++ ++ return true; ++ } ++ // Spigot end ++ @Override public void handleUseItemOn(ServerboundUseItemOnPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); + if (this.player.isImmobile()) return; // CraftBukkit ++ if (!this.checkLimit(packet.timestamp)) return; // Spigot - check limit if (this.player.hasClientLoaded()) { this.player.connection.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1244,6 +1631,7 @@ +@@ -1244,6 +1651,7 @@ if (blockposition.getY() <= i) { if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) { @@ -696,18 +717,21 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); if (enuminteractionresult.consumesAction()) { -@@ -1281,6 +1669,7 @@ +@@ -1281,6 +1689,8 @@ @Override public void handleUseItem(ServerboundUseItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); + if (this.player.isImmobile()) return; // CraftBukkit ++ if (!this.checkLimit(packet.timestamp)) return; // Spigot - check limit if (this.player.hasClientLoaded()) { this.ackBlockChangesUpTo(packet.getSequence()); ServerLevel worldserver = this.player.serverLevel(); -@@ -1296,6 +1685,47 @@ - this.player.absRotateTo(f, f1); - } +@@ -1294,8 +1704,49 @@ + if (f1 != this.player.getXRot() || f != this.player.getYRot()) { + this.player.absRotateTo(f, f1); ++ } ++ + // CraftBukkit start + // Raytrace to look for 'rogue armswings' + double d0 = this.player.getX(); @@ -738,8 +762,8 @@ + cancelled = event.useItemInHand() == Event.Result.DENY; + } + this.player.gameMode.firedInteract = false; -+ } -+ + } + + if (cancelled) { + this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524 + return; @@ -752,7 +776,7 @@ InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); if (enuminteractionresult instanceof InteractionResult.Success) { -@@ -1321,7 +1751,7 @@ +@@ -1321,7 +1772,7 @@ Entity entity = packet.getEntity(worldserver); if (entity != null) { @@ -761,7 +785,7 @@ return; } } -@@ -1342,6 +1772,13 @@ +@@ -1342,6 +1793,13 @@ @Override public void onDisconnect(DisconnectionDetails info) { @@ -775,7 +799,7 @@ ServerGamePacketListenerImpl.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), info.reason().getString()); this.removePlayerFromWorld(); super.onDisconnect(info); -@@ -1349,10 +1786,18 @@ +@@ -1349,10 +1807,18 @@ private void removePlayerFromWorld() { this.chatMessageChain.close(); @@ -796,7 +820,7 @@ this.player.getTextFilter().leave(); } -@@ -1367,7 +1812,16 @@ +@@ -1367,7 +1833,16 @@ @Override public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -813,7 +837,7 @@ if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) { this.player.stopUsingItem(); } -@@ -1376,11 +1830,18 @@ +@@ -1376,11 +1851,18 @@ this.player.resetLastActionTime(); } else { ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); @@ -832,7 +856,7 @@ Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages()); if (!optional.isEmpty()) { -@@ -1394,7 +1855,7 @@ +@@ -1394,7 +1876,7 @@ return; } @@ -841,7 +865,7 @@ Component ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent()); this.chatMessageChain.append(completablefuture, (filteredtext) -> { -@@ -1402,19 +1863,36 @@ +@@ -1402,19 +1884,36 @@ this.broadcastChatMessage(playerchatmessage1); }); @@ -881,7 +905,7 @@ ParseResults<CommandSourceStack> parseresults = this.parseCommand(command); if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { -@@ -1431,19 +1909,37 @@ +@@ -1431,19 +1930,37 @@ if (!optional.isEmpty()) { this.tryHandleChat(packet.command(), () -> { @@ -923,7 +947,7 @@ } catch (SignedMessageChain.DecodeException signedmessagechain_a) { this.handleMessageDecodeFailure(signedmessagechain_a); return; -@@ -1451,10 +1947,10 @@ +@@ -1451,10 +1968,10 @@ CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map); @@ -936,7 +960,7 @@ } private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) { -@@ -1530,14 +2026,20 @@ +@@ -1530,14 +2047,20 @@ return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack()); } @@ -961,12 +985,10 @@ } } -@@ -1564,8 +2066,123 @@ - } - +@@ -1566,6 +2089,121 @@ return false; -+ } -+ + } + + // CraftBukkit start - add method + public void chat(String s, PlayerChatMessage original, boolean async) { + if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) { @@ -1051,8 +1073,8 @@ + this.server.console.sendMessage(s); + } + } - } - ++ } ++ + private void handleCommand(String s) { + org.bukkit.craftbukkit.SpigotTimings.playerCommandTimer.startTiming(); // Spigot + if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot @@ -1085,7 +1107,7 @@ private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException { SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages); -@@ -1573,13 +2190,42 @@ +@@ -1573,13 +2211,42 @@ } private void broadcastChatMessage(PlayerChatMessage message) { @@ -1133,7 +1155,7 @@ this.disconnect((Component) Component.translatable("disconnect.spam")); } -@@ -1601,7 +2247,33 @@ +@@ -1601,7 +2268,33 @@ @Override public void handleAnimate(ServerboundSwingPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1167,7 +1189,7 @@ this.player.swing(packet.getHand()); } -@@ -1609,6 +2281,29 @@ +@@ -1609,6 +2302,29 @@ public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); if (this.player.hasClientLoaded()) { @@ -1197,7 +1219,7 @@ this.player.resetLastActionTime(); Entity entity; PlayerRideableJumping ijumpable; -@@ -1691,6 +2386,12 @@ +@@ -1691,6 +2407,12 @@ } public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) { @@ -1210,7 +1232,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 +2404,13 @@ +@@ -1703,6 +2425,13 @@ return this.connection.getRemoteAddress(); } @@ -1224,7 +1246,7 @@ public void switchToConfig() { this.waitingForSwitchToConfig = true; this.removePlayerFromWorld(); -@@ -1718,9 +2426,17 @@ +@@ -1718,9 +2447,17 @@ @Override public void handleInteract(ServerboundInteractPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1242,7 +1264,7 @@ this.player.resetLastActionTime(); this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); -@@ -1733,20 +2449,58 @@ +@@ -1733,12 +2470,50 @@ if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { packet.dispatch(new ServerboundInteractPacket.Handler() { @@ -1258,7 +1280,7 @@ + ItemStack itemInHand = ServerGamePacketListenerImpl.this.player.getItemInHand(enumhand); + boolean triggerLeashUpdate = itemInHand != null && itemInHand.getItem() == Items.LEAD && entity instanceof Mob; + Item origItem = ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null ? null : ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem(); - ++ + ServerGamePacketListenerImpl.this.cserver.getPluginManager().callEvent(event); + + // Entity in bucket - SPIGOT-4048 and SPIGOT-6859a @@ -1293,10 +1315,10 @@ + ServerGamePacketListenerImpl.this.player.containerMenu.sendAllDataToRemote(); + } + // CraftBukkit end -+ + if (enuminteractionresult instanceof InteractionResult.Success) { InteractionResult.Success enuminteractionresult_d = (InteractionResult.Success) enuminteractionresult; - ItemStack itemstack2 = enuminteractionresult_d.wasItemInteraction() ? itemstack1 : ItemStack.EMPTY; +@@ -1746,7 +2521,7 @@ CriteriaTriggers.PLAYER_INTERACTED_WITH_ENTITY.trigger(ServerGamePacketListenerImpl.this.player, itemstack2, entity); if (enuminteractionresult_d.swingSource() == InteractionResult.SwingSource.SERVER) { @@ -1305,7 +1327,7 @@ } } -@@ -1755,19 +2509,20 @@ +@@ -1755,19 +2530,20 @@ @Override public void onInteraction(InteractionHand hand) { @@ -1329,7 +1351,7 @@ label23: { if (entity instanceof AbstractArrow) { -@@ -1785,6 +2540,11 @@ +@@ -1785,6 +2561,11 @@ } ServerGamePacketListenerImpl.this.player.attack(entity); @@ -1341,7 +1363,7 @@ return; } } -@@ -1809,7 +2569,7 @@ +@@ -1809,7 +2590,7 @@ case PERFORM_RESPAWN: if (this.player.wonGame) { this.player.wonGame = false; @@ -1350,7 +1372,7 @@ this.resetPosition(); CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD); } else { -@@ -1817,11 +2577,11 @@ +@@ -1817,11 +2598,11 @@ return; } @@ -1364,7 +1386,7 @@ } } break; -@@ -1834,15 +2594,21 @@ +@@ -1834,15 +2615,21 @@ @Override public void handleContainerClose(ServerboundContainerClosePacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1388,7 +1410,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 +2621,284 @@ +@@ -1855,7 +2642,284 @@ boolean flag = packet.getStateId() != this.player.containerMenu.getStateId(); this.player.containerMenu.suppressRemoteUpdates(); @@ -1674,7 +1696,7 @@ ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator(); while (objectiterator.hasNext()) { -@@ -1901,8 +2944,22 @@ +@@ -1901,8 +2965,22 @@ return; } @@ -1698,7 +1720,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 +2974,7 @@ +@@ -1917,6 +2995,7 @@ @Override public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1706,7 +1728,7 @@ this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) { if (!this.player.containerMenu.stillValid(this.player)) { -@@ -1945,7 +3003,44 @@ +@@ -1945,6 +3024,43 @@ boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45; boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); @@ -1714,7 +1736,7 @@ + // CraftBukkit start - Call click event + InventoryView inventory = this.player.inventoryMenu.getBukkitView(); + org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packet.itemStack()); - ++ + SlotType type = SlotType.QUICKBAR; + if (flag) { + type = SlotType.OUTSIDE; @@ -1747,11 +1769,10 @@ + } + } + // CraftBukkit end -+ + if (flag1 && flag2) { this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack); - this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack); -@@ -1972,6 +3067,7 @@ +@@ -1972,6 +3088,7 @@ } private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) { @@ -1759,7 +1780,7 @@ this.player.resetLastActionTime(); ServerLevel worldserver = this.player.serverLevel(); BlockPos blockposition = packet.getPos(); -@@ -1993,7 +3089,17 @@ +@@ -1993,7 +3110,17 @@ @Override public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); @@ -1778,7 +1799,7 @@ } @Override -@@ -2058,7 +3164,7 @@ +@@ -2058,7 +3185,7 @@ if (!this.waitingForSwitchToConfig) { throw new IllegalStateException("Client acknowledged config, but none was requested"); } else { @@ -1787,7 +1808,7 @@ } } -@@ -2083,8 +3189,10 @@ +@@ -2083,8 +3210,10 @@ }); }