Skip to content
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
--- a/net/minecraft/advancements/triggers/SimpleCriterionTrigger.java
+++ b/net/minecraft/advancements/triggers/SimpleCriterionTrigger.java
@@ -20,14 +_,14 @@
@@ -17,17 +_,18 @@

public abstract class SimpleCriterionTrigger<T extends SimpleCriterionTrigger.SimpleInstance> implements CriterionTrigger<T> {
protected void trigger(final ServerPlayer player, final Predicate<T> matcher) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(player, "Cannot trigger criterion async"); // Paper - block async calls
PlayerAdvancements advancements = player.getAdvancements();
Map<PlayerAdvancements.TriggerInstanceKey, T> listenersForType = advancements.getTriggerMapForType(this);
if (listenersForType != null && !listenersForType.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
LOGGER.warn("Ignored advancement '{}' in progress file {} - it doesn't exist anymore?", id, this.playerSavePath);
} else {
this.startProgress(advancement, progress);
@@ -168,14 +_,31 @@
@@ -164,18 +_,36 @@
}

public boolean award(final AdvancementHolder holder, final String criterion) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.player, "Cannot award advancement async"); // Paper - block async calls
boolean result = false;
AdvancementProgress progress = this.getOrStartProgress(holder);
boolean wasDone = progress.isDone();
if (progress.grantProgress(criterion)) {
Expand Down Expand Up @@ -59,6 +64,14 @@
}
});
}
@@ -189,6 +_,7 @@
}

public boolean revoke(final AdvancementHolder advancement, final String criterion) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.player, "Cannot revoke advancement async"); // Paper - block async calls
boolean result = false;
AdvancementProgress progress = this.getOrStartProgress(advancement);
boolean wasDone = progress.isDone();
@@ -238,7 +_,7 @@
public void flushDirty(final ServerPlayer player, final boolean showAdvancements) {
if (this.isFirstPacket || !this.rootsToUpdate.isEmpty() || !this.progressChanged.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
}

protected void addEntity(final Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity track"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(entity, "Cannot track entity async"); // Paper - block async calls
+ // Paper start - ignore and warn about illegal addEntity calls instead of crashing server
+ if (!entity.valid || entity.level() != this.level || this.entityMap.containsKey(entity.getId())) {
+ LOGGER.error("Illegal ChunkMap::addEntity for world " + io.papermc.paper.util.MCUtil.getLevelName(this.level)
Expand All @@ -284,7 +284,7 @@
}

protected void removeEntity(final Entity entity) {
+ org.spigotmc.AsyncCatcher.catchOp("entity untrack"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(entity, "Cannot untrack entity async"); // Paper - block async calls
if (entity instanceof ServerPlayer player) {
this.updatePlayerStatus(player, false);

Expand All @@ -305,15 +305,15 @@
}

public void removePlayer(final ServerPlayer player) {
+ org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Cannot remove tracking player async"); // Paper - block async calls
if (this.seenBy.remove(player.connection)) {
this.serverEntity.removePairing(player);
if (this.seenBy.isEmpty()) {
@@ -1387,23 +_,47 @@
}

public void updatePlayer(final ServerPlayer player) {
+ org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this.entity, "Cannot update tracking player async"); // Paper - block async calls
if (player != this.entity) {
- Vec3 deltaToPlayer = player.position().subtract(this.entity.position());
+ // Paper start - remove allocation of Vec3D here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@
- private boolean addEntity(final Entity entity) {
+ // CraftBukkit start
+ private boolean addEntity(final Entity entity, final org.bukkit.event.entity.CreatureSpawnEvent.@Nullable SpawnReason spawnReason) {
+ org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(entity, "Cannot add entity async"); // Paper - block async calls
+ entity.generation = false; // Paper - Don't fire sync event during generation; Reset flag if it was added during a ServerLevel generation process
+ // Paper start - extra debug info
+ if (entity.valid) {
Expand Down Expand Up @@ -1135,7 +1135,7 @@
@Override
public void onTrackingStart(final Entity entity) {
- ServerLevel.this.getChunkSource().addEntity(entity);
+ org.spigotmc.AsyncCatcher.catchOp("entity register"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(entity, "Cannot start tracking entity async"); // Paper - block async calls
+ // ServerLevel.this.getChunkSource().addEntity(entity); // Paper - ignore and warn about illegal addEntity calls instead of crashing server; moved down below valid=true
if (entity instanceof ServerPlayer player) {
ServerLevel.this.players.add(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
if (enderPearl.isRemoved()) {
LOGGER.warn("Trying to save removed ender pearl, skipping");
} else {
@@ -548,6 +_,7 @@
}

public void initMenu(final AbstractContainerMenu container) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this, "Cannot init menu async"); // Paper - block async calls
container.addSlotListener(this.containerListener);
container.setSynchronizer(this.containerSynchronizer);
}
@@ -580,6 +_,11 @@

@Override
Expand Down Expand Up @@ -432,7 +440,7 @@
this.connection
.send(
new ClientboundPlayerCombatKillPacket(this.getId(), deathMessage),
@@ -903,6 +_,65 @@
@@ -903,6 +_,66 @@
}
)
);
Expand All @@ -443,6 +451,7 @@
+ // Paper end - Expand PlayerDeathEvent API
+ @Override
+ public void die(final DamageSource source) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this, "Cannot die async"); // Paper - block async calls
+ // this.gameEvent(GameEvent.ENTITY_DIE); // Paper - move below event cancellation check
+ boolean showDeathMessage = this.level().getGameRules().get(GameRules.SHOW_DEATH_MESSAGES);
+ // CraftBukkit start - fire PlayerDeathEvent
Expand Down Expand Up @@ -963,7 +972,7 @@
}

@Override
@@ -1323,8 +_,9 @@
@@ -1323,22 +_,51 @@
this.connection.send(new ClientboundShowDialogPacket(dialog));
}

Expand All @@ -974,7 +983,9 @@
}

@Override
@@ -1333,12 +_,39 @@
public OptionalInt openMenu(final @Nullable MenuProvider provider) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this, "Cannot open menu async"); // Paper - block async calls
if (provider == null) {
return OptionalInt.empty();
}

Expand Down Expand Up @@ -1087,7 +1098,7 @@
this.initMenu(this.containerMenu);
}

@@ -1409,10 +_,30 @@
@@ -1409,10 +_,31 @@

@Override
public void closeContainer() {
Expand All @@ -1096,6 +1107,7 @@
+ }
+ @Override
+ public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this, "Cannot close container async"); // Paper - block async calls
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(this, reason); // CraftBukkit
+ // Paper end - Inventory close reason
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
--- a/net/minecraft/stats/ServerRecipeBook.java
+++ b/net/minecraft/stats/ServerRecipeBook.java
@@ -64,17 +_,21 @@
@@ -59,22 +_,27 @@
}

public int addRecipes(final Collection<RecipeHolder<?>> recipes, final ServerPlayer player) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(player, "Cannot add recipes async"); // Paper - block async calls
List<ClientboundRecipeBookAddPacket.Entry> recipesToAdd = new ArrayList<>();

for (RecipeHolder<?> recipe : recipes) {
ResourceKey<Recipe<?>> id = recipe.id();
if (!this.known.contains(id) && !recipe.value().isSpecial()) {
Expand All @@ -24,6 +30,14 @@
player.connection.send(new ClientboundRecipeBookAddPacket(recipesToAdd, false));
}

@@ -82,6 +_,7 @@
}

public int removeRecipes(final Collection<RecipeHolder<?>> recipes, final ServerPlayer player) {
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(player, "Cannot remove recipes async"); // Paper - block async calls
List<RecipeDisplayId> recipesToRemove = Lists.newArrayList();

for (RecipeHolder<?> recipe : recipes) {
@@ -92,7 +_,7 @@
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

protected void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
+ org.spigotmc.AsyncCatcher.catchOp("block onPlace"); // Spigot
+ ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(level, pos, "Cannot place block async"); // Paper - block async calls
}

protected void affectNeighborsAfterRemoval(final BlockState state, final ServerLevel level, final BlockPos pos, final boolean movedByPiston) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import ca.spottedleaf.moonrise.common.util.TickThread;
import net.minecraft.world.entity.ai.goal.GoalSelector;
import net.minecraft.world.entity.ai.goal.WrappedGoal;
import org.bukkit.craftbukkit.entity.CraftMob;
Expand All @@ -18,6 +19,7 @@ public class PaperMobGoals implements MobGoals {
@Override
public <T extends Mob> void addGoal(T mob, int priority, Goal<T> goal) {
CraftMob craftMob = (CraftMob) mob;
TickThread.ensureTickThread(craftMob.getHandleRaw(), "Cannot add goal async");
net.minecraft.world.entity.ai.goal.Goal mojangGoal;

if (goal instanceof PaperGoal<?> paperGoal) {
Expand All @@ -32,6 +34,7 @@ public <T extends Mob> void addGoal(T mob, int priority, Goal<T> goal) {
@Override
public <T extends Mob> void removeGoal(T mob, Goal<T> goal) {
CraftMob craftMob = (CraftMob) mob;
TickThread.ensureTickThread(craftMob.getHandleRaw(), "Cannot remove goal async");
if (goal instanceof PaperCustomGoal) {
getHandle(craftMob, goal.getTypes()).removeGoal((net.minecraft.world.entity.ai.goal.Goal) goal);
} else if (goal instanceof PaperGoal) {
Expand Down Expand Up @@ -117,6 +120,7 @@ public <T extends Mob> Collection<Goal<T>> getAllGoals(T mob) {
@Override
public <T extends Mob> Collection<Goal<T>> getAllGoals(T mob, GoalType type) {
CraftMob craftMob = (CraftMob) mob;
TickThread.ensureTickThread(craftMob.getHandleRaw(), "Cannot get all goals async");
Set<Goal<T>> goals = new HashSet<>();
for (WrappedGoal item : getHandle(craftMob, type).getAvailableGoals()) {
if (!item.getGoal().hasFlag(MobGoalHelper.paperToVanilla(type))) {
Expand All @@ -136,6 +140,7 @@ public <T extends Mob> Collection<Goal<T>> getAllGoals(T mob, GoalType type) {
@Override
public <T extends Mob> Collection<Goal<T>> getAllGoalsWithout(T mob, GoalType type) {
CraftMob craftMob = (CraftMob) mob;
TickThread.ensureTickThread(craftMob.getHandleRaw(), "Cannot get all goals async");
Set<Goal<T>> goals = new HashSet<>();
for (GoalType internalType : GoalType.values()) {
if (internalType == type) {
Expand Down Expand Up @@ -169,6 +174,7 @@ public <T extends Mob> Collection<Goal<T>> getRunningGoals(T mob) {
@Override
public <T extends Mob> Collection<Goal<T>> getRunningGoals(T mob, GoalType type) {
CraftMob craftMob = (CraftMob) mob;
TickThread.ensureTickThread(craftMob.getHandleRaw(), "Cannot get running goals async");
Set<Goal<T>> goals = new HashSet<>();
getHandle(craftMob, type).getAvailableGoals()
.stream().filter(WrappedGoal::isRunning)
Expand All @@ -187,6 +193,7 @@ public <T extends Mob> Collection<Goal<T>> getRunningGoals(T mob, GoalType type)
@Override
public <T extends Mob> Collection<Goal<T>> getRunningGoalsWithout(T mob, GoalType type) {
CraftMob craftMob = (CraftMob) mob;
TickThread.ensureTickThread(craftMob.getHandleRaw(), "Cannot get running goals async");
Set<Goal<T>> goals = new HashSet<>();
for (GoalType internalType : GoalType.values()) {
if (internalType == type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ca.spottedleaf.moonrise.common.list.ReferenceList;
import ca.spottedleaf.moonrise.common.util.CoordinateUtils;
import ca.spottedleaf.moonrise.common.util.TickThread;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -1555,7 +1556,7 @@ public void playSound(Location loc, String sound, org.bukkit.SoundCategory categ

@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
TickThread.ensureTickThread(this.getHandle(), CraftLocation.toBlockPos(loc), "Cannot play sound async");
if (loc == null || sound == null || category == null) return;

double x = loc.getX();
Expand All @@ -1567,7 +1568,7 @@ public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory catego

@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
TickThread.ensureTickThread(this.getHandle(), CraftLocation.toBlockPos(loc), "Cannot play sound async");
if (loc == null || sound == null || category == null) return;

double x = loc.getX();
Expand All @@ -1590,8 +1591,8 @@ public void playSound(Entity entity, String sound, org.bukkit.SoundCategory cate

@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;
TickThread.ensureTickThread(craftEntity.getHandleRaw(), "Cannot play sound async");

ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(CraftSound.bukkitToMinecraftHolder(sound), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
ChunkMap.TrackedEntity entityTracker = this.getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
Expand All @@ -1611,8 +1612,8 @@ public void playSound(final net.kyori.adventure.sound.Sound sound) {

@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;
TickThread.ensureTickThread(craftEntity.getHandleRaw(), "Cannot play sound async");

ClientboundSoundEntityPacket packet = new ClientboundSoundEntityPacket(Holder.direct(SoundEvent.createVariableRangeEvent(Identifier.parse(sound))), net.minecraft.sounds.SoundSource.valueOf(category.name()), craftEntity.getHandle(), volume, pitch, seed);
ChunkMap.TrackedEntity entityTracker = this.getHandle().getChunkSource().chunkMap.entityMap.get(entity.getEntityId());
Expand All @@ -1623,7 +1624,7 @@ public void playSound(Entity entity, String sound, org.bukkit.SoundCategory cate

@Override
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
org.spigotmc.AsyncCatcher.catchOp("play sound"); // Paper
TickThread.ensureTickThread(this.getHandle(), Mth.floor(x) >> 4, Mth.floor(z) >> 4, "Cannot play sound async");
io.papermc.paper.adventure.PaperAdventure.asSoundPacket(sound, x, y, z, sound.seed().orElseGet(this.world.getRandom()::nextLong), this.playSound0(x, y, z));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.entity;

import ca.spottedleaf.moonrise.common.util.TickThread;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
Expand Down Expand Up @@ -371,7 +372,7 @@ public static LookAnchor toApiAnchor(net.minecraft.commands.arguments.EntityAnch
@Override
public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z) {
Preconditions.checkState(!this.entity.generation, "Cannot get nearby entities during world generation");
org.spigotmc.AsyncCatcher.catchOp("getNearbyEntities"); // Spigot
TickThread.ensureTickThread(this.entity, "Cannot get nearby entities async");

List<Entity> entities = this.getHandle().level().getEntities(this.entity, this.entity.getBoundingBox().inflate(x, y, z), Predicates.alwaysTrue());
List<org.bukkit.entity.Entity> result = new java.util.ArrayList<>(entities.size());
Expand Down
Loading
Loading