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-10-27 18:11:15 +01:00
index 70b891bd018029eda8cda4fb9f919e77524dbc5e..a4abcbc69ccd023a936d02d359ba4c08198ed31e 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-10-24 19:29:35 +02:00
@@ -1597,6 +1597,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2023-04-09 20:38:32 +02:00
}
2024-10-23 21:43:06 +02:00
public void internalTeleport(PositionMoveRotation positionmoverotation, Set<Relative> set) {
2023-04-09 20:38:32 +02:00
+ 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-11-11 20:17:36 +01:00
index 5415cade10ab36709f722cabc20ea3f1b9c285d9..924db96764ef1d0b9596be01f344065f8e1a721e 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-10-27 18:11:15 +01:00
@@ -1143,7 +1143,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
2024-10-25 21:24:15 +02:00
index 4eb0b0969325f39a7ae65492cccd482515a50142..5aa74c00a61282830d82359eae2b114e2a48b6d9 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
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:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
@@ -78,6 +78,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;
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
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:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
@@ -91,6 +92,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
2024-10-25 21:24:15 +02:00
// I don't want to know why this is a generic type.
Entity entityCasted = (Entity)entity;
@@ -144,19 +146,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);
}
2024-10-25 21:24:15 +02:00
@@ -168,6 +174,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) {
2024-10-25 21:24:15 +02:00
@@ -212,6 +219,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) {
2024-10-25 21:24:15 +02:00
@@ -256,6 +264,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);
2024-10-25 21:24:15 +02:00
@@ -269,6 +278,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
2024-10-25 21:24:15 +02:00
@@ -293,6 +303,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) {
2024-10-25 21:24:15 +02:00
@@ -309,6 +320,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();
}
2024-10-25 21:24:15 +02:00
@@ -329,6 +341,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;
2024-10-25 21:24:15 +02:00
@@ -343,6 +356,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()) {
2024-10-25 21:24:15 +02:00
@@ -450,6 +464,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)) {
2024-10-25 21:24:15 +02:00
@@ -504,6 +519,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-11-11 20:17:36 +01:00
index bb61295b8ae44eee9d0c7b12152a7d93d191bdfa..38febc623ee84d7eeeb7359c299ad0dbd5086e5b 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-11-11 20:17:36 +01:00
@@ -1762,6 +1762,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-11-11 20:17:36 +01:00
@@ -1773,6 +1774,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-11-11 20:17:36 +01:00
@@ -1805,6 +1807,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-11-11 20:17:36 +01:00
@@ -1825,6 +1828,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;
2024-06-14 02:08:12 +02:00
ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(ResourceLocation.parse(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-10-23 21:43:06 +02:00
index 9870222cc1c46bcc37f9d3d44881606f2b9d038e..e148239d4930e5cbb000beed4de386f992f28d88 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
2024-10-23 21:43:06 +02:00
@@ -534,6 +534,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-07-17 19:24:53 +02:00
index bbf0d9d9c44fe8d7add2f978994ec129420814c7..ef2598760458833021ef1bee92137f42c9fe591f 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-07-17 19:24:53 +02:00
if ( AsyncCatcher.enabled && Thread.currentThread() != MinecraftServer.getServer().serverThread )
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 + "!" );
}
}