Improve and expand AsyncCatcher

Log when the async catcher is tripped
  The chunk system can swallow the exception given it's all
  built with completablefuture, so ensure it is at least printed.

Add/move several async catchers

Async catch modifications to critical entity state
  These used to be here from Spigot, but were dropped with 1.17.
  Now in 1.17, this state is _even more_ critical than it was before,
  so these must exist to catch stupid plugins.

Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
Spottedleaf 2021-08-25 20:17:12 -07:00
parent efb3bbf2bb
commit c593e8510e
6 changed files with 156 additions and 62 deletions

View file

@ -881,7 +881,7 @@
return true; return true;
} else { } else {
@@ -1147,23 +1604,90 @@ @@ -1147,23 +1604,91 @@
} }
public void teleport(double x, double y, double z, float yaw, float pitch) { public void teleport(double x, double y, double z, float yaw, float pitch) {
@ -933,6 +933,7 @@
+ } + }
+ +
+ public void internalTeleport(PositionMoveRotation positionmoverotation, Set<Relative> set) { + public void internalTeleport(PositionMoveRotation positionmoverotation, Set<Relative> set) {
+ org.spigotmc.AsyncCatcher.catchOp("teleport"); // Paper
+ // Paper start - Prevent teleporting dead entities + // Paper start - Prevent teleporting dead entities
+ if (player.isRemoved()) { + if (player.isRemoved()) {
+ LOGGER.info("Attempt to teleport removed player {} restricted", player.getScoreboardName()); + LOGGER.info("Attempt to teleport removed player {} restricted", player.getScoreboardName());
@ -975,7 +976,7 @@
if (this.player.hasClientLoaded()) { if (this.player.hasClientLoaded()) {
BlockPos blockposition = packet.getPos(); BlockPos blockposition = packet.getPos();
@@ -1175,14 +1699,46 @@ @@ -1175,14 +1700,46 @@
if (!this.player.isSpectator()) { if (!this.player.isSpectator()) {
ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND); ItemStack itemstack = this.player.getItemInHand(InteractionHand.OFF_HAND);
@ -1024,7 +1025,7 @@
this.player.drop(false); this.player.drop(false);
} }
@@ -1199,6 +1755,12 @@ @@ -1199,6 +1756,12 @@
case START_DESTROY_BLOCK: case START_DESTROY_BLOCK:
case ABORT_DESTROY_BLOCK: case ABORT_DESTROY_BLOCK:
case STOP_DESTROY_BLOCK: case STOP_DESTROY_BLOCK:
@ -1037,7 +1038,7 @@
this.player.gameMode.handleBlockBreakAction(blockposition, packetplayinblockdig_enumplayerdigtype, packet.getDirection(), this.player.level().getMaxY(), packet.getSequence()); this.player.gameMode.handleBlockBreakAction(blockposition, packetplayinblockdig_enumplayerdigtype, packet.getDirection(), this.player.level().getMaxY(), packet.getSequence());
this.player.connection.ackBlockChangesUpTo(packet.getSequence()); this.player.connection.ackBlockChangesUpTo(packet.getSequence());
return; return;
@@ -1218,9 +1780,31 @@ @@ -1218,9 +1781,31 @@
} }
} }
@ -1069,7 +1070,7 @@
if (this.player.hasClientLoaded()) { if (this.player.hasClientLoaded()) {
this.player.connection.ackBlockChangesUpTo(packet.getSequence()); this.player.connection.ackBlockChangesUpTo(packet.getSequence());
ServerLevel worldserver = this.player.serverLevel(); ServerLevel worldserver = this.player.serverLevel();
@@ -1230,6 +1814,11 @@ @@ -1230,6 +1815,11 @@
if (itemstack.isItemEnabled(worldserver.enabledFeatures())) { if (itemstack.isItemEnabled(worldserver.enabledFeatures())) {
BlockHitResult movingobjectpositionblock = packet.getHitResult(); BlockHitResult movingobjectpositionblock = packet.getHitResult();
Vec3 vec3d = movingobjectpositionblock.getLocation(); Vec3 vec3d = movingobjectpositionblock.getLocation();
@ -1081,7 +1082,7 @@
BlockPos blockposition = movingobjectpositionblock.getBlockPos(); BlockPos blockposition = movingobjectpositionblock.getBlockPos();
if (this.player.canInteractWithBlock(blockposition, 1.0D)) { if (this.player.canInteractWithBlock(blockposition, 1.0D)) {
@@ -1243,7 +1832,8 @@ @@ -1243,7 +1833,8 @@
int i = this.player.level().getMaxY(); int i = this.player.level().getMaxY();
if (blockposition.getY() <= i) { if (blockposition.getY() <= i) {
@ -1091,7 +1092,7 @@
InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock); InteractionResult enuminteractionresult = this.player.gameMode.useItemOn(this.player, worldserver, itemstack, enumhand, movingobjectpositionblock);
if (enuminteractionresult.consumesAction()) { if (enuminteractionresult.consumesAction()) {
@@ -1257,7 +1847,7 @@ @@ -1257,7 +1848,7 @@
} else if (enuminteractionresult instanceof InteractionResult.Success) { } else if (enuminteractionresult instanceof InteractionResult.Success) {
InteractionResult.Success enuminteractionresult_d = (InteractionResult.Success) enuminteractionresult; InteractionResult.Success enuminteractionresult_d = (InteractionResult.Success) enuminteractionresult;
@ -1100,7 +1101,7 @@
this.player.swing(enumhand, true); this.player.swing(enumhand, true);
} }
} }
@@ -1281,6 +1871,8 @@ @@ -1281,6 +1872,8 @@
@Override @Override
public void handleUseItem(ServerboundUseItemPacket packet) { public void handleUseItem(ServerboundUseItemPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1109,12 +1110,10 @@
if (this.player.hasClientLoaded()) { if (this.player.hasClientLoaded()) {
this.ackBlockChangesUpTo(packet.getSequence()); this.ackBlockChangesUpTo(packet.getSequence());
ServerLevel worldserver = this.player.serverLevel(); ServerLevel worldserver = this.player.serverLevel();
@@ -1294,8 +1886,49 @@ @@ -1296,6 +1889,47 @@
if (f1 != this.player.getXRot() || f != this.player.getYRot()) {
this.player.absRotateTo(f, f1); this.player.absRotateTo(f, f1);
+ } }
+
+ // CraftBukkit start + // CraftBukkit start
+ // Raytrace to look for 'rogue armswings' + // Raytrace to look for 'rogue armswings'
+ double d0 = this.player.getX(); + double d0 = this.player.getX();
@ -1145,8 +1144,8 @@
+ cancelled = event.useItemInHand() == Event.Result.DENY; + cancelled = event.useItemInHand() == Event.Result.DENY;
+ } + }
+ this.player.gameMode.firedInteract = false; + this.player.gameMode.firedInteract = false;
} + }
+
+ if (cancelled) { + if (cancelled) {
+ this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524 + this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
+ return; + return;
@ -1159,7 +1158,7 @@
InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand); InteractionResult enuminteractionresult = this.player.gameMode.useItem(this.player, worldserver, itemstack, enumhand);
if (enuminteractionresult instanceof InteractionResult.Success) { if (enuminteractionresult instanceof InteractionResult.Success) {
@@ -1321,7 +1954,7 @@ @@ -1321,7 +1955,7 @@
Entity entity = packet.getEntity(worldserver); Entity entity = packet.getEntity(worldserver);
if (entity != null) { if (entity != null) {
@ -1168,7 +1167,7 @@
return; return;
} }
} }
@@ -1342,17 +1975,46 @@ @@ -1342,17 +1976,46 @@
@Override @Override
public void onDisconnect(DisconnectionDetails info) { public void onDisconnect(DisconnectionDetails info) {
@ -1219,7 +1218,7 @@
this.player.getTextFilter().leave(); this.player.getTextFilter().leave();
} }
@@ -1367,7 +2029,17 @@ @@ -1367,7 +2030,17 @@
@Override @Override
public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1237,7 +1236,7 @@
if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) { if (this.player.getInventory().selected != packet.getSlot() && this.player.getUsedItemHand() == InteractionHand.MAIN_HAND) {
this.player.stopUsingItem(); this.player.stopUsingItem();
} }
@@ -1376,11 +2048,18 @@ @@ -1376,11 +2049,18 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
} else { } else {
ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString()); ServerGamePacketListenerImpl.LOGGER.warn("{} tried to set an invalid carried item", this.player.getName().getString());
@ -1256,7 +1255,7 @@
Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages()); Optional<LastSeenMessages> optional = this.unpackAndApplyLastSeen(packet.lastSeenMessages());
if (!optional.isEmpty()) { if (!optional.isEmpty()) {
@@ -1394,27 +2073,44 @@ @@ -1394,27 +2074,44 @@
return; return;
} }
@ -1308,7 +1307,7 @@
ParseResults<CommandSourceStack> parseresults = this.parseCommand(command); ParseResults<CommandSourceStack> parseresults = this.parseCommand(command);
if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) { if (this.server.enforceSecureProfile() && SignableCommand.hasSignableArguments(parseresults)) {
@@ -1431,19 +2127,37 @@ @@ -1431,19 +2128,37 @@
if (!optional.isEmpty()) { if (!optional.isEmpty()) {
this.tryHandleChat(packet.command(), () -> { this.tryHandleChat(packet.command(), () -> {
@ -1350,7 +1349,7 @@
} catch (SignedMessageChain.DecodeException signedmessagechain_a) { } catch (SignedMessageChain.DecodeException signedmessagechain_a) {
this.handleMessageDecodeFailure(signedmessagechain_a); this.handleMessageDecodeFailure(signedmessagechain_a);
return; return;
@@ -1451,10 +2165,10 @@ @@ -1451,10 +2166,10 @@
CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map); CommandSigningContext.SignedArguments commandsigningcontext_a = new CommandSigningContext.SignedArguments(map);
@ -1363,7 +1362,7 @@
} }
private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) { private void handleMessageDecodeFailure(SignedMessageChain.DecodeException exception) {
@@ -1530,14 +2244,20 @@ @@ -1530,14 +2245,20 @@
return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack()); return com_mojang_brigadier_commanddispatcher.parse(command, this.player.createCommandSourceStack());
} }
@ -1389,7 +1388,7 @@
} }
} }
@@ -1549,7 +2269,7 @@ @@ -1549,7 +2270,7 @@
if (optional.isEmpty()) { if (optional.isEmpty()) {
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString()); ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
@ -1398,7 +1397,7 @@
} }
return optional; return optional;
@@ -1566,6 +2286,127 @@ @@ -1566,6 +2287,127 @@
return false; return false;
} }
@ -1526,7 +1525,7 @@
private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException { private PlayerChatMessage getSignedMessage(ServerboundChatPacket packet, LastSeenMessages lastSeenMessages) throws SignedMessageChain.DecodeException {
SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages); SignedMessageBody signedmessagebody = new SignedMessageBody(packet.message(), packet.timeStamp(), packet.salt(), lastSeenMessages);
@@ -1573,15 +2414,44 @@ @@ -1573,15 +2415,44 @@
} }
private void broadcastChatMessage(PlayerChatMessage message) { private void broadcastChatMessage(PlayerChatMessage message) {
@ -1577,7 +1576,7 @@
} }
@@ -1592,7 +2462,7 @@ @@ -1592,7 +2463,7 @@
synchronized (this.lastSeenMessages) { synchronized (this.lastSeenMessages) {
if (!this.lastSeenMessages.applyOffset(packet.offset())) { if (!this.lastSeenMessages.applyOffset(packet.offset())) {
ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString()); ServerGamePacketListenerImpl.LOGGER.warn("Failed to validate message acknowledgements from {}", this.player.getName().getString());
@ -1586,7 +1585,7 @@
} }
} }
@@ -1601,7 +2471,40 @@ @@ -1601,7 +2472,40 @@
@Override @Override
public void handleAnimate(ServerboundSwingPacket packet) { public void handleAnimate(ServerboundSwingPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1627,7 +1626,7 @@
this.player.swing(packet.getHand()); this.player.swing(packet.getHand());
} }
@@ -1609,6 +2512,29 @@ @@ -1609,6 +2513,29 @@
public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (this.player.hasClientLoaded()) { if (this.player.hasClientLoaded()) {
@ -1657,7 +1656,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
Entity entity; Entity entity;
PlayerRideableJumping ijumpable; PlayerRideableJumping ijumpable;
@@ -1616,6 +2542,11 @@ @@ -1616,6 +2543,11 @@
switch (packet.getAction()) { switch (packet.getAction()) {
case PRESS_SHIFT_KEY: case PRESS_SHIFT_KEY:
this.player.setShiftKeyDown(true); this.player.setShiftKeyDown(true);
@ -1669,7 +1668,7 @@
break; break;
case RELEASE_SHIFT_KEY: case RELEASE_SHIFT_KEY:
this.player.setShiftKeyDown(false); this.player.setShiftKeyDown(false);
@@ -1684,13 +2615,19 @@ @@ -1684,13 +2616,19 @@
} }
if (i > 4096) { if (i > 4096) {
@ -1690,7 +1689,7 @@
this.send(new ClientboundPlayerChatPacket(message.link().sender(), message.link().index(), message.signature(), message.signedBody().pack(this.messageSignatureCache), message.unsignedContent(), message.filterMask(), params)); 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); this.addPendingMessage(message);
} }
@@ -1703,6 +2640,18 @@ @@ -1703,6 +2641,18 @@
return this.connection.getRemoteAddress(); return this.connection.getRemoteAddress();
} }
@ -1709,7 +1708,7 @@
public void switchToConfig() { public void switchToConfig() {
this.waitingForSwitchToConfig = true; this.waitingForSwitchToConfig = true;
this.removePlayerFromWorld(); this.removePlayerFromWorld();
@@ -1718,9 +2667,17 @@ @@ -1718,9 +2668,17 @@
@Override @Override
public void handleInteract(ServerboundInteractPacket packet) { public void handleInteract(ServerboundInteractPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -1727,7 +1726,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
this.player.setShiftKeyDown(packet.isUsingSecondaryAction()); this.player.setShiftKeyDown(packet.isUsingSecondaryAction());
@@ -1733,20 +2690,58 @@ @@ -1733,20 +2691,58 @@
if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) { if (this.player.canInteractWithEntity(axisalignedbb, 3.0D)) {
packet.dispatch(new ServerboundInteractPacket.Handler() { packet.dispatch(new ServerboundInteractPacket.Handler() {
@ -1790,7 +1789,7 @@
} }
} }
@@ -1755,19 +2750,20 @@ @@ -1755,19 +2751,20 @@
@Override @Override
public void onInteraction(InteractionHand hand) { public void onInteraction(InteractionHand hand) {
@ -1814,7 +1813,7 @@
label23: label23:
{ {
if (entity instanceof AbstractArrow) { if (entity instanceof AbstractArrow) {
@@ -1785,17 +2781,41 @@ @@ -1785,17 +2782,41 @@
} }
ServerGamePacketListenerImpl.this.player.attack(entity); ServerGamePacketListenerImpl.this.player.attack(entity);
@ -1857,7 +1856,7 @@
} }
} }
@@ -1809,7 +2829,7 @@ @@ -1809,7 +2830,7 @@
case PERFORM_RESPAWN: case PERFORM_RESPAWN:
if (this.player.wonGame) { if (this.player.wonGame) {
this.player.wonGame = false; this.player.wonGame = false;
@ -1866,7 +1865,7 @@
this.resetPosition(); this.resetPosition();
CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD); CriteriaTriggers.CHANGED_DIMENSION.trigger(this.player, Level.END, Level.OVERWORLD);
} else { } else {
@@ -1817,11 +2837,11 @@ @@ -1817,11 +2838,11 @@
return; return;
} }
@ -1881,7 +1880,7 @@
} }
} }
break; break;
@@ -1833,16 +2853,27 @@ @@ -1833,16 +2854,27 @@
@Override @Override
public void handleContainerClose(ServerboundContainerClosePacket packet) { public void handleContainerClose(ServerboundContainerClosePacket packet) {
@ -1911,7 +1910,7 @@
this.player.containerMenu.sendAllDataToRemote(); this.player.containerMenu.sendAllDataToRemote();
} else if (!this.player.containerMenu.stillValid(this.player)) { } else if (!this.player.containerMenu.stillValid(this.player)) {
ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu); ServerGamePacketListenerImpl.LOGGER.debug("Player {} interacted with invalid menu {}", this.player, this.player.containerMenu);
@@ -1855,7 +2886,284 @@ @@ -1855,7 +2887,284 @@
boolean flag = packet.getStateId() != this.player.containerMenu.getStateId(); boolean flag = packet.getStateId() != this.player.containerMenu.getStateId();
this.player.containerMenu.suppressRemoteUpdates(); this.player.containerMenu.suppressRemoteUpdates();
@ -2197,7 +2196,7 @@
ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator(); ObjectIterator objectiterator = Int2ObjectMaps.fastIterable(packet.getChangedSlots()).iterator();
while (objectiterator.hasNext()) { while (objectiterator.hasNext()) {
@@ -1879,6 +3187,14 @@ @@ -1879,6 +3188,14 @@
@Override @Override
public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) { public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) {
@ -2212,7 +2211,7 @@
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
this.player.resetLastActionTime(); this.player.resetLastActionTime();
if (!this.player.isSpectator() && this.player.containerMenu.containerId == packet.containerId()) { if (!this.player.isSpectator() && this.player.containerMenu.containerId == packet.containerId()) {
@@ -1900,9 +3216,43 @@ @@ -1900,9 +3217,43 @@
ServerGamePacketListenerImpl.LOGGER.debug("Player {} tried to place impossible recipe {}", this.player, recipeholder.id().location()); ServerGamePacketListenerImpl.LOGGER.debug("Player {} tried to place impossible recipe {}", this.player, recipeholder.id().location());
return; return;
} }
@ -2257,7 +2256,7 @@
if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) { if (containerrecipebook_a == RecipeBookMenu.PostPlaceAction.PLACE_GHOST_RECIPE) {
this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display())); this.player.connection.send(new ClientboundPlaceGhostRecipePacket(this.player.containerMenu.containerId, craftingmanager_d.display().display()));
} }
@@ -1917,6 +3267,7 @@ @@ -1917,6 +3268,7 @@
@Override @Override
public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -2265,7 +2264,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) { if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) { if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1945,7 +3296,44 @@ @@ -1945,7 +3297,44 @@
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45; boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize(); boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@ -2310,7 +2309,7 @@
if (flag1 && flag2) { if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack); this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack); this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
@@ -1964,7 +3352,19 @@ @@ -1964,7 +3353,19 @@
@Override @Override
public void handleSignUpdate(ServerboundSignUpdatePacket packet) { public void handleSignUpdate(ServerboundSignUpdatePacket packet) {
@ -2331,7 +2330,7 @@
this.filterTextPacket(list).thenAcceptAsync((list1) -> { this.filterTextPacket(list).thenAcceptAsync((list1) -> {
this.updateSignText(packet, list1); this.updateSignText(packet, list1);
@@ -1972,6 +3372,7 @@ @@ -1972,6 +3373,7 @@
} }
private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) { private void updateSignText(ServerboundSignUpdatePacket packet, List<FilteredText> signText) {
@ -2339,7 +2338,7 @@
this.player.resetLastActionTime(); this.player.resetLastActionTime();
ServerLevel worldserver = this.player.serverLevel(); ServerLevel worldserver = this.player.serverLevel();
BlockPos blockposition = packet.getPos(); BlockPos blockposition = packet.getPos();
@@ -1993,15 +3394,33 @@ @@ -1993,15 +3395,33 @@
@Override @Override
public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
@ -2374,7 +2373,7 @@
if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) { if (this.player.isModelPartShown(PlayerModelPart.HAT) != flag) {
this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player)); this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_HAT, this.player));
} }
@@ -2012,7 +3431,7 @@ @@ -2012,7 +3432,7 @@
public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) { if (this.player.hasPermissions(2) || this.isSingleplayerOwner()) {
@ -2383,7 +2382,7 @@
} }
} }
@@ -2033,7 +3452,7 @@ @@ -2033,7 +3453,7 @@
if (!Objects.equals(profilepublickey_a, profilepublickey_a1)) { if (!Objects.equals(profilepublickey_a, profilepublickey_a1)) {
if (profilepublickey_a != null && profilepublickey_a1.expiresAt().isBefore(profilepublickey_a.expiresAt())) { if (profilepublickey_a != null && profilepublickey_a1.expiresAt().isBefore(profilepublickey_a.expiresAt())) {
@ -2392,7 +2391,7 @@
} else { } else {
try { try {
SignatureValidator signaturevalidator = this.server.getProfileKeySignatureValidator(); SignatureValidator signaturevalidator = this.server.getProfileKeySignatureValidator();
@@ -2046,7 +3465,7 @@ @@ -2046,7 +3466,7 @@
this.resetPlayerChatState(remotechatsession_a.validate(this.player.getGameProfile(), signaturevalidator)); this.resetPlayerChatState(remotechatsession_a.validate(this.player.getGameProfile(), signaturevalidator));
} catch (ProfilePublicKey.ValidationException profilepublickey_b) { } catch (ProfilePublicKey.ValidationException profilepublickey_b) {
ServerGamePacketListenerImpl.LOGGER.error("Failed to validate profile key: {}", profilepublickey_b.getMessage()); ServerGamePacketListenerImpl.LOGGER.error("Failed to validate profile key: {}", profilepublickey_b.getMessage());
@ -2401,7 +2400,7 @@
} }
} }
@@ -2058,7 +3477,7 @@ @@ -2058,7 +3478,7 @@
if (!this.waitingForSwitchToConfig) { if (!this.waitingForSwitchToConfig) {
throw new IllegalStateException("Client acknowledged config, but none was requested"); throw new IllegalStateException("Client acknowledged config, but none was requested");
} else { } else {
@ -2410,7 +2409,7 @@
} }
} }
@@ -2083,8 +3502,10 @@ @@ -2083,8 +3503,10 @@
}); });
} }

View file

@ -398,7 +398,7 @@
+ } + }
+ +
+ public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause) { + public boolean addEffect(MobEffectInstance mobeffect, @Nullable Entity entity, EntityPotionEffectEvent.Cause cause) {
+ org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot + // org.spigotmc.AsyncCatcher.catchOp("effect add"); // Spigot // Paper - move to API
+ if (this.isTickingEffects) { + if (this.isTickingEffects) {
+ this.effectsToProcess.add(new ProcessableEffect(mobeffect, cause)); + this.effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
+ return true; + return true;

View file

@ -32,10 +32,19 @@
void removeSectionIfEmpty(long sectionPos, EntitySection<T> section) { void removeSectionIfEmpty(long sectionPos, EntitySection<T> section) {
if (section.isEmpty()) { if (section.isEmpty()) {
this.sectionStorage.remove(sectionPos); this.sectionStorage.remove(sectionPos);
@@ -76,6 +91,16 @@ @@ -63,6 +78,7 @@
}
private boolean addEntityUuid(T entity) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity add by UUID"); // Paper
if (!this.knownUuids.add(entity.getUUID())) {
PersistentEntitySectionManager.LOGGER.warn("UUID of added entity already exists: {}", entity);
return false;
@@ -76,6 +92,17 @@
} }
private boolean addEntity(T entity, boolean existing) { private boolean addEntity(T entity, boolean existing) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity add"); // Paper
+ // Paper start - chunk system hooks + // Paper start - chunk system hooks
+ // I don't want to know why this is a generic type. + // I don't want to know why this is a generic type.
+ Entity entityCasted = (Entity)entity; + Entity entityCasted = (Entity)entity;
@ -49,7 +58,47 @@
if (!this.addEntityUuid(entity)) { if (!this.addEntityUuid(entity)) {
return false; return false;
} else { } else {
@@ -196,27 +221,35 @@ @@ -119,19 +146,23 @@
}
void startTicking(T entity) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity start ticking"); // Paper
this.callbacks.onTickingStart(entity);
}
void stopTicking(T entity) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity stop ticking"); // Paper
this.callbacks.onTickingEnd(entity);
}
void startTracking(T entity) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity start tracking"); // Paper
this.visibleEntityStorage.add(entity);
this.callbacks.onTrackingStart(entity);
}
void stopTracking(T entity) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity stop tracking"); // Paper
this.callbacks.onTrackingEnd(entity);
this.visibleEntityStorage.remove(entity);
}
@@ -143,6 +174,7 @@
}
public void updateChunkStatus(ChunkPos chunkPos, Visibility trackingStatus) {
+ org.spigotmc.AsyncCatcher.catchOp("Update chunk status"); // Paper
long i = chunkPos.toLong();
if (trackingStatus == Visibility.HIDDEN) {
@@ -187,6 +219,7 @@
}
public void ensureChunkQueuedForLoad(long chunkPos) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity chunk save"); // Paper
PersistentEntitySectionManager.ChunkLoadStatus persistententitysectionmanager_b = (PersistentEntitySectionManager.ChunkLoadStatus) this.chunkLoadStatuses.get(chunkPos);
if (persistententitysectionmanager_b == PersistentEntitySectionManager.ChunkLoadStatus.FRESH) {
@@ -196,33 +229,42 @@
} }
private boolean storeChunkSections(long chunkPos, Consumer<T> action) { private boolean storeChunkSections(long chunkPos, Consumer<T> action) {
@ -91,8 +140,18 @@
return true; return true;
} }
} }
@@ -238,7 +271,7 @@ }
private void requestChunkLoad(long chunkPos) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity chunk load request"); // Paper
this.chunkLoadStatuses.put(chunkPos, PersistentEntitySectionManager.ChunkLoadStatus.PENDING);
ChunkPos chunkcoordintpair = new ChunkPos(chunkPos);
CompletableFuture completablefuture = this.permanentStorage.loadEntities(chunkcoordintpair);
@@ -236,9 +278,10 @@
}
private boolean processChunkUnload(long chunkPos) { private boolean processChunkUnload(long chunkPos) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity chunk unload process"); // Paper
boolean flag = this.storeChunkSections(chunkPos, (entityaccess) -> { boolean flag = this.storeChunkSections(chunkPos, (entityaccess) -> {
entityaccess.getPassengersAndSelf().forEach(this::unloadEntity); entityaccess.getPassengersAndSelf().forEach(this::unloadEntity);
- }); - });
@ -100,7 +159,7 @@
if (!flag) { if (!flag) {
return false; return false;
@@ -249,24 +282,28 @@ @@ -249,29 +292,35 @@
} }
private void unloadEntity(EntityAccess entity) { private void unloadEntity(EntityAccess entity) {
@ -118,6 +177,7 @@
private void processPendingLoads() { private void processPendingLoads() {
- ChunkEntities chunkentities; - ChunkEntities chunkentities;
+ org.spigotmc.AsyncCatcher.catchOp("Entity chunk process pending loads"); // Paper
+ ChunkEntities<T> chunkentities; // CraftBukkit - decompile error + ChunkEntities<T> chunkentities; // CraftBukkit - decompile error
while ((chunkentities = (ChunkEntities) this.loadingInbox.poll()) != null) { while ((chunkentities = (ChunkEntities) this.loadingInbox.poll()) != null) {
@ -132,16 +192,29 @@
} }
} }
@@ -292,7 +329,7 @@
public void tick() {
+ org.spigotmc.AsyncCatcher.catchOp("Entity manager tick"); // Paper
this.processPendingLoads();
this.processUnloads();
}
@@ -292,7 +341,8 @@
} }
public void autoSave() { public void autoSave() {
- this.getAllChunksToSave().forEach((i) -> { - this.getAllChunksToSave().forEach((i) -> {
+ org.spigotmc.AsyncCatcher.catchOp("Entity manager autosave"); // Paper
+ this.getAllChunksToSave().forEach((java.util.function.LongConsumer) (i) -> { // CraftBukkit - decompile error + this.getAllChunksToSave().forEach((java.util.function.LongConsumer) (i) -> { // CraftBukkit - decompile error
boolean flag = this.chunkVisibility.get(i) == Visibility.HIDDEN; boolean flag = this.chunkVisibility.get(i) == Visibility.HIDDEN;
if (flag) { if (flag) {
@@ -311,7 +348,7 @@ @@ -306,12 +356,13 @@
}
public void saveAll() {
+ org.spigotmc.AsyncCatcher.catchOp("Entity manager save"); // Paper
LongSet longset = this.getAllChunksToSave();
while (!longset.isEmpty()) { while (!longset.isEmpty()) {
this.permanentStorage.flush(false); this.permanentStorage.flush(false);
this.processPendingLoads(); this.processPendingLoads();
@ -150,7 +223,7 @@
boolean flag = this.chunkVisibility.get(i) == Visibility.HIDDEN; boolean flag = this.chunkVisibility.get(i) == Visibility.HIDDEN;
return flag ? this.processChunkUnload(i) : this.storeChunkSections(i, (entityaccess) -> { return flag ? this.processChunkUnload(i) : this.storeChunkSections(i, (entityaccess) -> {
@@ -323,7 +360,15 @@ @@ -323,7 +374,15 @@
} }
public void close() throws IOException { public void close() throws IOException {
@ -167,7 +240,7 @@
this.permanentStorage.close(); this.permanentStorage.close();
} }
@@ -350,7 +395,7 @@ @@ -350,7 +409,7 @@
public void dumpSections(Writer writer) throws IOException { public void dumpSections(Writer writer) throws IOException {
CsvOutput csvwriter = CsvOutput.builder().addColumn("x").addColumn("y").addColumn("z").addColumn("visibility").addColumn("load_status").addColumn("entity_count").build(writer); CsvOutput csvwriter = CsvOutput.builder().addColumn("x").addColumn("y").addColumn("z").addColumn("visibility").addColumn("load_status").addColumn("entity_count").build(writer);
@ -176,7 +249,7 @@
PersistentEntitySectionManager.ChunkLoadStatus persistententitysectionmanager_b = (PersistentEntitySectionManager.ChunkLoadStatus) this.chunkLoadStatuses.get(i); PersistentEntitySectionManager.ChunkLoadStatus persistententitysectionmanager_b = (PersistentEntitySectionManager.ChunkLoadStatus) this.chunkLoadStatuses.get(i);
this.sectionStorage.getExistingSectionPositionsInChunk(i).forEach((j) -> { this.sectionStorage.getExistingSectionPositionsInChunk(i).forEach((j) -> {
@@ -394,7 +439,7 @@ @@ -394,7 +453,7 @@
private EntitySection<T> currentSection; private EntitySection<T> currentSection;
Callback(final EntityAccess entityaccess, final long i, final EntitySection entitysection) { Callback(final EntityAccess entityaccess, final long i, final EntitySection entitysection) {
@ -185,3 +258,19 @@
this.currentSectionKey = i; this.currentSectionKey = i;
this.currentSection = entitysection; this.currentSection = entitysection;
} }
@@ -405,6 +464,7 @@
long i = SectionPos.asLong(blockposition);
if (i != this.currentSectionKey) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity move"); // Paper
Visibility visibility = this.currentSection.getStatus();
if (!this.currentSection.remove(this.entity)) {
@@ -459,6 +519,7 @@
@Override
public void onRemove(Entity.RemovalReason reason) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity remove"); // Paper
if (!this.currentSection.remove(this.entity)) {
PersistentEntitySectionManager.LOGGER.warn("Entity {} wasn't found in section {} (destroying due to {})", new Object[]{this.entity, SectionPos.of(this.currentSectionKey), reason});
}

View file

@ -1755,6 +1755,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
if (loc == null || sound == null || category == null) return; if (loc == null || sound == null || category == null) return;
double x = loc.getX(); double x = loc.getX();
@ -1766,6 +1767,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
if (loc == null || sound == null || category == null) return; if (loc == null || sound == null || category == null) return;
double x = loc.getX(); double x = loc.getX();
@ -1798,6 +1800,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { public void playSound(Entity entity, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed); ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
@ -1818,6 +1821,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) { public void playSound(Entity entity, String sound, org.bukkit.SoundCategory category, float volume, float pitch, long seed) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return; if (!(entity instanceof CraftEntity craftEntity) || entity.getWorld() != this || sound == null || category == null) return;
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(ResourceLocation.parse(sound))), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed); ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(ResourceLocation.parse(sound))), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);

View file

@ -534,6 +534,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@Override @Override
public boolean addPotionEffect(PotionEffect effect, boolean force) { public boolean addPotionEffect(PotionEffect effect, boolean force) {
org.spigotmc.AsyncCatcher.catchOp("effect add"); // Paper
this.getHandle().addEffect(org.bukkit.craftbukkit.potion.CraftPotionUtil.fromBukkit(effect), EntityPotionEffectEvent.Cause.PLUGIN); // Paper - Don't ignore icon this.getHandle().addEffect(org.bukkit.craftbukkit.potion.CraftPotionUtil.fromBukkit(effect), EntityPotionEffectEvent.Cause.PLUGIN); // Paper - Don't ignore icon
return true; return true;
} }

View file

@ -11,6 +11,7 @@ public class AsyncCatcher
{ {
if ( AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread ) if ( AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread )
{ {
MinecraftServer.LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); // Paper
throw new IllegalStateException( "Asynchronous " + reason + "!" ); throw new IllegalStateException( "Asynchronous " + reason + "!" );
} }
} }