Limit recipe packets

This commit is contained in:
Shane Freeder 2020-12-12 23:45:28 +00:00
parent 661fc1e52e
commit 1f21f3032b

View file

@ -48,7 +48,7 @@
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
@@ -192,12 +196,73 @@
@@ -192,11 +196,72 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
@ -59,7 +59,7 @@
import net.minecraft.world.phys.shapes.VoxelShape;
+import org.bukkit.NamespacedKey;
import org.slf4j.Logger;
+
+// CraftBukkit start
+import io.papermc.paper.adventure.ChatProcessor; // Paper
+import io.papermc.paper.adventure.PaperAdventure; // Paper
@ -118,19 +118,20 @@
+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();
@@ -212,6 +277,7 @@
@@ -212,7 +277,9 @@
private int tickCount;
private int ackBlockChangesUpTo = -1;
private final TickThrottler chatSpamThrottler = new TickThrottler(20, 200);
+ private final TickThrottler tabSpamThrottler = new TickThrottler(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamIncrement, io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamLimit); // Paper - configurable tab spam limits
private final TickThrottler dropSpamThrottler = new TickThrottler(20, 1480);
+ private final TickThrottler recipeSpamPackets = new TickThrottler(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamIncrement, io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamLimit);
private double firstGoodX;
private double firstGoodY;
@@ -245,9 +311,10 @@
private double firstGoodZ;
@@ -245,9 +312,10 @@
private final MessageSignatureCache messageSignatureCache = MessageSignatureCache.createDefault();
private final FutureChain chatMessageChain;
private boolean waitingForSwitchToConfig;
@ -142,7 +143,7 @@
this.chunkSender = new PlayerChunkSender(connection.isMemoryConnection());
this.player = player;
player.connection = this;
@@ -256,9 +323,25 @@
@@ -256,9 +324,25 @@
Objects.requireNonNull(server);
this.signedMessageDecoder = SignedMessageChain.Decoder.unsigned(uuid, server::enforceSecureProfile);
@ -169,7 +170,7 @@
@Override
public void tick() {
if (this.ackBlockChangesUpTo > -1) {
@@ -277,7 +360,7 @@
@@ -277,7 +361,7 @@
if (this.clientIsFloating && !this.player.isSleeping() && !this.player.isPassenger() && !this.player.isDeadOrDying()) {
if (++this.aboveGroundTickCount > this.getMaximumFlyingTicks(this.player)) {
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked for floating too long!", this.player.getName().getString());
@ -178,7 +179,7 @@
return;
}
} else {
@@ -296,7 +379,7 @@
@@ -296,7 +380,7 @@
if (this.clientVehicleIsFloating && this.lastVehicle.getControllingPassenger() == this.player) {
if (++this.aboveGroundVehicleTickCount > this.getMaximumFlyingTicks(this.lastVehicle)) {
ServerGamePacketListenerImpl.LOGGER.warn("{} was kicked for floating a vehicle too long!", this.player.getName().getString());
@ -187,18 +188,19 @@
return;
}
} else {
@@ -311,8 +394,10 @@
@@ -311,8 +395,11 @@
this.keepConnectionAlive();
this.chatSpamThrottler.tick();
+ this.tabSpamThrottler.tick(); // Paper - configurable tab spam limits
+ this.recipeSpamPackets.tick(); // Paper - auto recipe limit
this.dropSpamThrottler.tick();
if (this.player.getLastActionTime() > 0L && this.server.getPlayerIdleTimeout() > 0 && Util.getMillis() - this.player.getLastActionTime() > (long) this.server.getPlayerIdleTimeout() * 1000L * 60L) {
+ this.player.resetLastActionTime(); // CraftBukkit - SPIGOT-854
this.disconnect((Component) Component.translatable("multiplayer.disconnect.idling"));
}
@@ -376,6 +461,12 @@
@@ -376,6 +463,12 @@
@Override
public void handlePlayerInput(ServerboundPlayerInputPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -211,7 +213,7 @@
this.player.setLastClientInput(packet.input());
}
@@ -401,21 +492,73 @@
@@ -401,21 +494,73 @@
if (entity != this.player && entity.getControllingPassenger() == this.player && entity == this.lastVehicle) {
ServerLevel worldserver = this.player.serverLevel();
@ -293,7 +295,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;
@@ -423,9 +566,9 @@
@@ -423,9 +568,9 @@
boolean flag = worldserver.noCollision(entity, entity.getBoundingBox().deflate(0.0625D));
@ -306,7 +308,7 @@
boolean flag1 = entity.verticalCollisionBelow;
if (entity instanceof LivingEntity) {
@@ -449,20 +592,73 @@
@@ -449,19 +594,72 @@
d10 = d6 * d6 + d7 * d7 + d8 * d8;
boolean flag2 = false;
@ -325,8 +327,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) {
@ -375,13 +377,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);
@@ -493,12 +689,13 @@
@@ -493,12 +691,13 @@
return;
}
@ -396,7 +397,7 @@
}
}
@@ -528,6 +725,7 @@
@@ -528,6 +727,7 @@
@Override
public void handleRecipeBookChangeSettingsPacket(ServerboundRecipeBookChangeSettingsPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -404,7 +405,7 @@
this.player.getRecipeBook().setBookSetting(packet.getBookType(), packet.isOpen(), packet.isFiltering());
}
@@ -545,21 +743,80 @@
@@ -545,21 +745,80 @@
}
@ -489,7 +490,7 @@
});
}
@@ -568,7 +825,7 @@
@@ -568,7 +827,7 @@
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (!this.server.isCommandBlockEnabled()) {
this.player.sendSystemMessage(Component.translatable("advMode.notEnabled"));
@ -498,7 +499,7 @@
this.player.sendSystemMessage(Component.translatable("advMode.notAllowed"));
} else {
BaseCommandBlock commandblocklistenerabstract = null;
@@ -635,7 +892,7 @@
@@ -635,7 +894,7 @@
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (!this.server.isCommandBlockEnabled()) {
this.player.sendSystemMessage(Component.translatable("advMode.notEnabled"));
@ -507,7 +508,7 @@
this.player.sendSystemMessage(Component.translatable("advMode.notAllowed"));
} else {
BaseCommandBlock commandblocklistenerabstract = packet.getCommandBlock(this.player.level());
@@ -668,7 +925,7 @@
@@ -668,7 +927,7 @@
ItemStack itemstack = iblockdata.getCloneItemStack(worldserver, blockposition, flag);
if (!itemstack.isEmpty()) {
@ -516,7 +517,7 @@
ServerGamePacketListenerImpl.addBlockDataToItem(iblockdata, worldserver, blockposition, itemstack);
}
@@ -866,6 +1123,13 @@
@@ -866,6 +1125,13 @@
AbstractContainerMenu container = this.player.containerMenu;
if (container instanceof MerchantMenu containermerchant) {
@ -530,7 +531,7 @@
if (!containermerchant.stillValid(this.player)) {
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, containermerchant);
return;
@@ -879,6 +1143,51 @@
@@ -879,6 +1145,51 @@
@Override
public void handleEditBook(ServerboundEditBookPacket packet) {
@ -582,7 +583,7 @@
int i = packet.slot();
if (Inventory.isHotbarSlot(i) || i == 40) {
@@ -899,12 +1208,16 @@
@@ -899,12 +1210,16 @@
}
private void updateBookContents(List<FilteredText> pages, int slotId) {
@ -600,7 +601,7 @@
}
}
@@ -915,12 +1228,13 @@
@@ -915,12 +1230,13 @@
ItemStack itemstack1 = itemstack.transmuteCopy(Items.WRITTEN_BOOK);
itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT);
@ -616,7 +617,7 @@
}
}
@@ -982,22 +1296,30 @@
@@ -982,22 +1298,30 @@
} else {
ServerLevel worldserver = this.player.serverLevel();
@ -651,7 +652,7 @@
double d3 = this.player.getX();
double d4 = this.player.getY();
double d5 = this.player.getZ();
@@ -1005,7 +1327,16 @@
@@ -1005,7 +1329,16 @@
double d7 = d1 - this.firstGoodY;
double d8 = d2 - this.firstGoodZ;
double d9 = this.player.getDeltaMovement().lengthSqr();
@ -669,7 +670,7 @@
if (this.player.isSleeping()) {
if (d10 > 1.0D) {
@@ -1019,15 +1350,39 @@
@@ -1019,15 +1352,39 @@
++this.receivedMovePacketCount;
int i = this.receivedMovePacketCount - this.knownMovePacketCount;
@ -711,7 +712,7 @@
ServerGamePacketListenerImpl.LOGGER.warn("{} moved too quickly! {},{},{}", new Object[]{this.player.getName().getString(), d6, d7, d8});
this.teleport(this.player.getX(), this.player.getY(), this.player.getZ(), this.player.getYRot(), this.player.getXRot());
return;
@@ -1037,18 +1392,51 @@
@@ -1037,18 +1394,51 @@
AABB axisalignedbb = this.player.getBoundingBox();
@ -767,7 +768,7 @@
double d11 = d7;
d6 = d0 - this.player.getX();
@@ -1061,15 +1449,81 @@
@@ -1061,15 +1451,81 @@
d10 = d6 * d6 + d7 * d7 + d8 * d8;
boolean flag3 = false;
@ -851,7 +852,7 @@
this.player.absMoveTo(d0, d1, d2, f, f1);
boolean flag4 = this.player.isAutoSpinAttack();
@@ -1119,6 +1573,7 @@
@@ -1119,6 +1575,7 @@
this.awaitingTeleportTime = this.tickCount;
this.teleport(this.awaitingPositionFromClient.x, this.awaitingPositionFromClient.y, this.awaitingPositionFromClient.z, this.player.getYRot(), this.player.getXRot());
}
@ -859,7 +860,7 @@
return true;
} else {
@@ -1147,23 +1602,90 @@
@@ -1147,23 +1604,90 @@
}
public void teleport(double x, double y, double z, float yaw, float pitch) {
@ -953,7 +954,7 @@
if (this.player.hasClientLoaded()) {
BlockPos blockposition = packet.getPos();
@@ -1175,14 +1697,46 @@
@@ -1175,14 +1699,46 @@
if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND);
@ -1002,7 +1003,7 @@
this.player.drop(false);
}
@@ -1199,6 +1753,12 @@
@@ -1199,6 +1755,12 @@
case START_DESTROY_BLOCK:
case ABORT_DESTROY_BLOCK:
case STOP_DESTROY_BLOCK:
@ -1015,7 +1016,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 +1778,31 @@
@@ -1218,9 +1780,31 @@
}
}
@ -1047,7 +1048,7 @@
if (this.player.hasClientLoaded()) {
this.player.connection.ackBlockChangesUpTo(packet.getSequence());
ServerLevel worldserver = this.player.serverLevel();
@@ -1244,6 +1826,7 @@
@@ -1244,6 +1828,7 @@
if (blockposition.getY() <= i) {
if (this.awaitingPositionFromClient == null && worldserver.mayInteract(this.player, blockposition)) {
@ -1055,7 +1056,7 @@
InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enuminteractionresult.consumesAction()) {
@@ -1281,6 +1864,8 @@
@@ -1281,6 +1866,8 @@
@Override
public void handleUseItem(ServerboundUseItemPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1064,12 +1065,10 @@
if (this.player.hasClientLoaded()) {
this.ackBlockChangesUpTo(packet.getSequence());
ServerLevel worldserver = this.player.serverLevel();
@@ -1294,8 +1879,49 @@
if (f1 != this.player.getXRot() || f != this.player.getYRot()) {
@@ -1296,6 +1883,47 @@
this.player.absRotateTo(f, f1);
+ }
+
}
+ // CraftBukkit start
+ // Raytrace to look for 'rogue armswings'
+ double d0 = this.player.getX();
@ -1100,8 +1099,8 @@
+ cancelled = event.useItemInHand() == Event.Result.DENY;
+ }
+ this.player.gameMode.firedInteract = false;
}
+ }
+
+ if (cancelled) {
+ this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
+ return;
@ -1114,7 +1113,7 @@
InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult instanceof InteractionResult.Success) {
@@ -1321,7 +1947,7 @@
@@ -1321,7 +1949,7 @@
Entity entity = packet.getEntity(worldserver);
if (entity != null) {
@ -1123,7 +1122,7 @@
return;
}
}
@@ -1342,6 +1968,13 @@
@@ -1342,6 +1970,13 @@
@Override
public void onDisconnect(DisconnectionDetails info) {
@ -1137,7 +1136,7 @@
ServerGamePacketListenerImpl.LOGGER.info("{} lost connection: {}", this.player.getName().getString(), info.reason().getString());
this.removePlayerFromWorld();
super.onDisconnect(info);
@@ -1349,10 +1982,20 @@
@@ -1349,10 +1984,20 @@
private void removePlayerFromWorld() {
this.chatMessageChain.close();
@ -1160,7 +1159,7 @@
this.player.getTextFilter().leave();
}
@@ -1367,7 +2010,16 @@
@@ -1367,7 +2012,16 @@
@Override
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1177,7 +1176,7 @@
if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) {
this.player.stopUsingItem();
}
@@ -1376,11 +2028,18 @@
@@ -1376,11 +2030,18 @@
this.player.resetLastActionTime();
} else {
ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
@ -1196,7 +1195,7 @@
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
if (!optional.isEmpty()) {
@@ -1394,27 +2053,44 @@
@@ -1394,27 +2055,44 @@
return;
}
@ -1248,7 +1247,7 @@
ParseResults<CommandSourceStack> parseresults = this.parseCommand(command);
if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) {
@@ -1431,19 +2107,37 @@
@@ -1431,19 +2109,37 @@
if (!optional.isEmpty()) {
this.tryHandleChat(packet.command(), () -> {
@ -1290,7 +1289,7 @@
} catch (SignedMessageChain.DecodeException signedmessagechain_a) {
this.handleMessageDecodeFailure(signedmessagechain_a);
return;
@@ -1451,10 +2145,10 @@
@@ -1451,10 +2147,10 @@
CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map);
@ -1303,7 +1302,7 @@
}
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
@@ -1530,14 +2224,20 @@
@@ -1530,14 +2226,20 @@
return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack());
}
@ -1328,7 +1327,7 @@
}
}
@@ -1566,6 +2266,127 @@
@@ -1566,6 +2268,127 @@
return false;
}
@ -1456,7 +1455,7 @@
private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException {
SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages);
@@ -1573,13 +2394,42 @@
@@ -1573,13 +2396,42 @@
}
private void broadcastChatMessage(PlayerChatMessage message) {
@ -1504,7 +1503,7 @@
this.disconnect((Component) Component.translatable("disconnect.spam"));
}
@@ -1601,7 +2451,33 @@
@@ -1601,7 +2453,33 @@
@Override
public void handleAnimate(ServerboundSwingPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1538,7 +1537,7 @@
this.player.swing(packet.getHand());
}
@@ -1609,6 +2485,29 @@
@@ -1609,6 +2487,29 @@
public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (this.player.hasClientLoaded()) {
@ -1568,7 +1567,7 @@
this.player.resetLastActionTime();
Entity entity;
PlayerRideableJumping ijumpable;
@@ -1616,6 +2515,11 @@
@@ -1616,6 +2517,11 @@
switch (packet.getAction()) {
case PRESS_SHIFT_KEY:
this.player.setShiftKeyDown(true);
@ -1580,7 +1579,7 @@
break;
case RELEASE_SHIFT_KEY:
this.player.setShiftKeyDown(false);
@@ -1691,6 +2595,12 @@
@@ -1691,6 +2597,12 @@
}
public void sendPlayerChatMessage(PlayerChatMessage message, ChatType.Bound params) {
@ -1593,7 +1592,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 +2613,13 @@
@@ -1703,6 +2615,13 @@
return this.connection.getRemoteAddress();
}
@ -1607,7 +1606,7 @@
public void switchToConfig() {
this.waitingForSwitchToConfig = true;
this.removePlayerFromWorld();
@@ -1718,9 +2635,17 @@
@@ -1718,9 +2637,17 @@
@Override
public void handleInteract(ServerboundInteractPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1625,7 +1624,7 @@
this.player.resetLastActionTime();
this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
@@ -1733,20 +2658,58 @@
@@ -1733,20 +2660,58 @@
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
packet.dispatch(new ServerboundInteractPacket.Handler() {
@ -1641,7 +1640,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
@ -1649,7 +1648,7 @@
+ entity.getBukkitEntity().update(ServerGamePacketListenerImpl.this.player);
+ ServerGamePacketListenerImpl.this.player.containerMenu.sendAllDataToRemote();
+ }
+
+ if (triggerLeashUpdate && (event.isCancelled() || ServerGamePacketListenerImpl.this.player.getInventory().getSelected() == null || ServerGamePacketListenerImpl.this.player.getInventory().getSelected().getItem() != origItem)) {
+ // Refresh the current leash state
+ ServerGamePacketListenerImpl.this.send(new ClientboundSetEntityLinkPacket(entity, ((Mob) entity).getLeashHolder()));
@ -1688,7 +1687,7 @@
}
}
@@ -1755,19 +2718,20 @@
@@ -1755,19 +2720,20 @@
@Override
public void onInteraction(InteractionHand hand) {
@ -1712,7 +1711,7 @@
label23:
{
if (entity instanceof AbstractArrow) {
@@ -1785,6 +2749,11 @@
@@ -1785,6 +2751,11 @@
}
ServerGamePacketListenerImpl.this.player.attack(entity);
@ -1724,7 +1723,7 @@
return;
}
}
@@ -1795,7 +2764,26 @@
@@ -1795,7 +2766,26 @@
});
}
}
@ -1751,7 +1750,7 @@
}
}
@@ -1809,7 +2797,7 @@
@@ -1809,7 +2799,7 @@
case PERFORM_RESPAWN:
if (this.player.wonGame) {
this.player.wonGame = false;
@ -1760,7 +1759,7 @@
this.resetPosition();
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
} else {
@@ -1817,11 +2805,11 @@
@@ -1817,11 +2807,11 @@
return;
}
@ -1774,7 +1773,7 @@
}
}
break;
@@ -1833,16 +2821,27 @@
@@ -1833,16 +2823,27 @@
@Override
public void handleContainerClose(ServerboundContainerClosePacket packet) {
@ -1804,7 +1803,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 +2854,284 @@
@@ -1855,7 +2856,284 @@
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates();
@ -2090,7 +2089,22 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
while (objectiterator.hasNext()) {
@@ -1900,9 +3176,43 @@
@@ -1879,6 +3157,14 @@
@Override
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
+ // Paper start - auto recipe limit
+ if (!org.bukkit.Bukkit.isPrimaryThread()) {
+ if (!this.recipeSpamPackets.isIncrementAndUnderThreshold()) {
+ this.disconnect(net.minecraft.network.chat.Component.translatable("disconnect.spam"));
+ return;
+ }
+ }
+ // Paper end - auto recipe limit
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
this.player.resetLastActionTime();
if (!this.player.isSpectator() && this.player.containerMenu.containerId == packet.containerId()) {
@@ -1900,9 +3186,43 @@
ServerGamePacketListenerImpl.LOGGER.debug("Player {} tried to place impossible recipe {}", this.player, recipeholder.id().location());
return;
}
@ -2135,7 +2149,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 +3227,7 @@
@@ -1917,6 +3237,7 @@
@Override
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -2143,7 +2157,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1945,6 +3256,43 @@
@@ -1945,7 +3266,44 @@
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@ -2151,7 +2165,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;
@ -2184,10 +2198,11 @@
+ }
+ }
+ // CraftBukkit end
+
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
@@ -1964,7 +3312,19 @@
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
@@ -1964,7 +3322,19 @@
@Override
public void handleSignUpdate(ServerboundSignUpdatePacket packet) {
@ -2208,7 +2223,7 @@
this.filterTextPacket(list).thenAcceptAsync((list1) -> {
this.updateSignText(packet, list1);
@@ -1972,6 +3332,7 @@
@@ -1972,6 +3342,7 @@
}
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
@ -2216,7 +2231,7 @@
this.player.resetLastActionTime();
ServerLevel worldserver = this.player.serverLevel();
BlockPos blockposition = packet.getPos();
@@ -1993,15 +3354,33 @@
@@ -1993,15 +3364,33 @@
@Override
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -2251,7 +2266,7 @@
if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) {
this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player));
}
@@ -2012,7 +3391,7 @@
@@ -2012,7 +3401,7 @@
public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) {
@ -2260,7 +2275,7 @@
}
}
@@ -2058,7 +3437,7 @@
@@ -2058,7 +3447,7 @@
if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested");
} else {
@ -2269,7 +2284,7 @@
}
}
@@ -2083,8 +3462,10 @@
@@ -2083,8 +3472,10 @@
});
}