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-01-14 13:33:47 +01:00
index 28fdf5f4df4b61383e6d132f603c50ec35f62024..b203c945e7c013e202013f7bce6b3c7077bf2d42 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
2023-12-28 21:47:57 +01:00
@@ -1575,6 +1575,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
// Paper start
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
2023-12-25 23:51:56 +01:00
index b137ce3be71fa92cb196f5725dd7cfc71f93fcf7..1f3363da6642673d286cb7704aa61cb910c5d23f 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
2023-12-06 05:49:31 +01:00
@@ -1118,7 +1118,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-01-14 13:33:47 +01:00
index 095fa9e4c4d367a3cdd343ca71bef7a6564759be..b52d3413cfe725ff5778c897a0ba06ca834e533f 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
@@ -1803,6 +1803,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@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();
@@ -1814,6 +1815,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@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();
@@ -1846,6 +1848,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@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);
@@ -1857,6 +1860,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@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
2023-12-25 23:51:56 +01:00
index bd5e80a04a035f670160a5eef94805ab90372cf6..3e79a73e42875936e373f797dcde6a60a904a880 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
2023-09-22 22:13:57 +02:00
index 05e94702e42b8f5c35d2a112c486d57948a3acba..d678ca116f9b81ab9d7d99a698e0ce066c132f34 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
{
2023-09-22 22:13:57 +02:00
if ( !io.papermc.paper.util.TickThread.isTickThread() ) // Paper // Paper - rewrite chunk system
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 + "!" );
}
}