2021-11-01 05:35:47 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
2023-04-09 20:38:32 +02:00
Date: Wed, 25 Aug 2021 20:17:12 -0700
Subject: [PATCH] Improve and expand AsyncCatcher
2021-11-01 05:35:47 +01:00
2023-04-09 20:38:32 +02:00
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.
2021-11-01 05:35:47 +01:00
2023-04-09 20:38:32 +02:00
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>
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-02-05 12:31:51 +01:00
index 935cb7d0529134115fdda73f1bcaf538b7dc7c94..4ab3f9321f37956420549e63ce65b955ca9c3b94 100644
2023-04-09 20:38:32 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-02-05 12:31:51 +01:00
@@ -1570,6 +1570,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-04-09 20:38:32 +02:00
}
public void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set) { // Paper
+ org.spigotmc.AsyncCatcher.catchOp("teleport"); // Paper
2024-01-21 12:11:43 +01:00
// Paper start - Prevent teleporting dead entities
2023-04-09 20:38:32 +02:00
if (player.isRemoved()) {
LOGGER.info("Attempt to teleport removed player {} restricted", player.getScoreboardName());
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2024-02-01 10:15:57 +01:00
index 8dcebc2b6e8baf4ed5f269a1b9cec9e5cd754047..f1ac4256878bd5737ded1f7d3e8b51416887f545 100644
2023-04-09 20:38:32 +02:00
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
2024-02-01 10:15:57 +01:00
@@ -1117,7 +1117,7 @@ public abstract class LivingEntity extends Entity implements Attackable {
2023-04-09 20:38:32 +02:00
}
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) {
this.effectsToProcess.add(new ProcessableEffect(mobeffect, cause));
return true;
2021-11-01 05:35:47 +01:00
diff --git a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
2023-12-06 05:49:31 +01:00
index bbbf6dd8e566ecdca8794e3b03765fe7e426a2bd..66ab901956ca394c251c420338643d39817a1b7e 100644
2021-11-01 05:35:47 +01:00
--- a/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
+++ b/src/main/java/net/minecraft/world/level/entity/PersistentEntitySectionManager.java
2022-09-26 10:02:51 +02:00
@@ -77,6 +77,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
private boolean addEntityUuid(T entity) {
2021-11-04 01:54:11 +01:00
+ org.spigotmc.AsyncCatcher.catchOp("Entity add by UUID"); // Paper
2021-11-01 05:35:47 +01:00
if (!this.knownUuids.add(entity.getUUID())) {
2022-09-26 10:02:51 +02:00
PersistentEntitySectionManager.LOGGER.warn("UUID of added entity already exists: {}", entity);
return false;
@@ -90,6 +91,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
private boolean addEntity(T entity, boolean existing) {
2021-11-04 01:54:11 +01:00
+ org.spigotmc.AsyncCatcher.catchOp("Entity add"); // Paper
2022-09-01 18:51:59 +02:00
// Paper start - chunk system hooks
if (existing) {
// I don't want to know why this is a generic type.
2022-09-26 10:02:51 +02:00
@@ -145,19 +147,23 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
void startTicking(T entity) {
2021-11-04 01:54:11 +01:00
+ org.spigotmc.AsyncCatcher.catchOp("Entity start ticking"); // Paper
2021-11-01 05:35:47 +01:00
this.callbacks.onTickingStart(entity);
}
void stopTicking(T entity) {
2021-11-04 01:54:11 +01:00
+ org.spigotmc.AsyncCatcher.catchOp("Entity stop ticking"); // Paper
2021-11-01 05:35:47 +01:00
this.callbacks.onTickingEnd(entity);
}
void startTracking(T entity) {
2021-11-04 01:54:11 +01:00
+ org.spigotmc.AsyncCatcher.catchOp("Entity start tracking"); // Paper
2021-11-01 05:35:47 +01:00
this.visibleEntityStorage.add(entity);
this.callbacks.onTrackingStart(entity);
}
void stopTracking(T entity) {
2021-11-04 01:54:11 +01:00
+ org.spigotmc.AsyncCatcher.catchOp("Entity stop tracking"); // Paper
2021-11-01 05:35:47 +01:00
this.callbacks.onTrackingEnd(entity);
this.visibleEntityStorage.remove(entity);
}
2022-09-26 10:02:51 +02:00
@@ -169,6 +175,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
public void updateChunkStatus(ChunkPos chunkPos, Visibility trackingStatus) {
+ org.spigotmc.AsyncCatcher.catchOp("Update chunk status"); // Paper
long i = chunkPos.toLong();
if (trackingStatus == Visibility.HIDDEN) {
2022-09-26 10:02:51 +02:00
@@ -213,6 +220,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-25 09:10:26 +01:00
}
2021-11-04 19:20:14 +01:00
2021-11-25 09:10:26 +01:00
public void ensureChunkQueuedForLoad(long chunkPos) {
2021-11-01 05:35:47 +01:00
+ org.spigotmc.AsyncCatcher.catchOp("Entity chunk save"); // Paper
2021-11-04 19:20:14 +01:00
PersistentEntitySectionManager.ChunkLoadStatus persistententitysectionmanager_b = (PersistentEntitySectionManager.ChunkLoadStatus) this.chunkLoadStatuses.get(chunkPos);
2021-11-01 05:35:47 +01:00
2021-11-25 09:10:26 +01:00
if (persistententitysectionmanager_b == PersistentEntitySectionManager.ChunkLoadStatus.FRESH) {
2022-09-26 10:02:51 +02:00
@@ -257,6 +265,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
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);
2022-09-26 10:02:51 +02:00
@@ -270,6 +279,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-04 19:20:14 +01:00
}
2021-11-01 05:35:47 +01:00
private boolean processChunkUnload(long chunkPos) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity chunk unload process"); // Paper
2021-11-04 19:20:14 +01:00
boolean flag = this.storeChunkSections(chunkPos, (entityaccess) -> {
2021-11-01 05:35:47 +01:00
entityaccess.getPassengersAndSelf().forEach(this::unloadEntity);
}, true); // CraftBukkit - add boolean for event call
2022-09-26 10:02:51 +02:00
@@ -294,6 +304,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
private void processPendingLoads() {
+ org.spigotmc.AsyncCatcher.catchOp("Entity chunk process pending loads"); // Paper
ChunkEntities<T> chunkentities; // CraftBukkit - decompile error
while ((chunkentities = (ChunkEntities) this.loadingInbox.poll()) != null) {
2022-09-26 10:02:51 +02:00
@@ -310,6 +321,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
public void tick() {
+ org.spigotmc.AsyncCatcher.catchOp("Entity manager tick"); // Paper
this.processPendingLoads();
this.processUnloads();
}
2022-09-26 10:02:51 +02:00
@@ -330,6 +342,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
public void autoSave() {
+ org.spigotmc.AsyncCatcher.catchOp("Entity manager autosave"); // Paper
this.getAllChunksToSave().forEach((java.util.function.LongConsumer) (i) -> { // CraftBukkit - decompile error
boolean flag = this.chunkVisibility.get(i) == Visibility.HIDDEN;
2022-09-26 10:02:51 +02:00
@@ -344,6 +357,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
}
public void saveAll() {
+ org.spigotmc.AsyncCatcher.catchOp("Entity manager save"); // Paper
LongSet longset = this.getAllChunksToSave();
while (!longset.isEmpty()) {
2023-12-06 05:49:31 +01:00
@@ -451,6 +465,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2022-09-26 10:02:51 +02:00
long i = SectionPos.asLong(blockposition);
2021-11-01 05:35:47 +01:00
if (i != this.currentSectionKey) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity move"); // Paper
2022-09-26 10:02:51 +02:00
Visibility visibility = this.currentSection.getStatus();
if (!this.currentSection.remove(this.entity)) {
2023-12-06 05:49:31 +01:00
@@ -505,6 +520,7 @@ public class PersistentEntitySectionManager<T extends EntityAccess> implements A
2021-11-01 05:35:47 +01:00
@Override
public void onRemove(Entity.RemovalReason reason) {
+ org.spigotmc.AsyncCatcher.catchOp("Entity remove"); // Paper
if (!this.currentSection.remove(this.entity)) {
2022-03-01 06:43:03 +01:00
PersistentEntitySectionManager.LOGGER.warn("Entity {} wasn't found in section {} (destroying due to {})", new Object[]{this.entity, SectionPos.of(this.currentSectionKey), reason});
2021-11-01 05:35:47 +01:00
}
2023-12-26 21:00:21 +01:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2024-02-01 10:15:57 +01:00
index 8a37dd71f1551ce27c1a729eab2a11c465b684e3..b58788161b758eee5fbaee3280c8551116e82566 100644
2023-12-26 21:00:21 +01:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2024-01-24 15:57:53 +01:00
@@ -1724,6 +1724,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2023-12-26 21:00:21 +01:00
@Override
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;
double x = loc.getX();
2024-01-24 15:57:53 +01:00
@@ -1735,6 +1736,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2023-12-26 21:00:21 +01:00
@Override
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;
double x = loc.getX();
2024-01-24 15:57:53 +01:00
@@ -1767,6 +1769,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2023-12-26 21:00:21 +01:00
@Override
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;
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
2024-01-24 15:57:53 +01:00
@@ -1778,6 +1781,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2023-12-26 21:00:21 +01:00
@Override
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;
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(new ResourceLocation(sound))), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
2023-04-09 20:38:32 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
2024-01-20 12:50:16 +01:00
index 711f4ca8ee42a14e40af86d93a9685b4b9a2ba99..269664d3894835e5bafc39e65ee5245ae1d74d78 100644
2023-04-09 20:38:32 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
2023-12-25 23:51:56 +01:00
@@ -463,6 +463,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
2023-04-09 20:38:32 +02:00
@Override
public boolean addPotionEffect(PotionEffect effect, boolean force) {
+ org.spigotmc.AsyncCatcher.catchOp("effect add"); // Paper
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
this.getHandle().addEffect(org.bukkit.craftbukkit.potion.CraftPotionUtil.fromBukkit(effect), EntityPotionEffectEvent.Cause.PLUGIN); // Paper - Don't ignore icon
2023-04-09 20:38:32 +02:00
return true;
}
diff --git a/src/main/java/org/spigotmc/AsyncCatcher.java b/src/main/java/org/spigotmc/AsyncCatcher.java
2024-01-24 15:57:53 +01:00
index 78669fa035b7537ff7e533cf32aaf2995625424f..e8e3cc48cf1c58bd8151d1f28df28781859cd0e3 100644
2023-04-09 20:38:32 +02:00
--- a/src/main/java/org/spigotmc/AsyncCatcher.java
+++ b/src/main/java/org/spigotmc/AsyncCatcher.java
2023-09-17 00:54:33 +02:00
@@ -11,6 +11,7 @@ public class AsyncCatcher
2023-04-09 20:38:32 +02:00
{
2024-01-24 15:57:53 +01:00
if ( (AsyncCatcher.enabled || io.papermc.paper.util.TickThread.STRICT_THREAD_CHECKS) && Thread.currentThread() != MinecraftServer.getServer().serverThread ) // Paper
2023-04-09 20:38:32 +02:00
{
+ MinecraftServer.LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable()); // Paper
throw new IllegalStateException( "Asynchronous " + reason + "!" );
}
}