Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,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 @@ -283,7 +283,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 @@ -304,15 +304,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 @@ -646,7 +646,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 @@ -1139,7 +1139,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
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 @@ -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 @@ -1550,7 +1551,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 @@ -1562,7 +1563,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 @@ -1585,8 +1586,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 @@ -1606,8 +1607,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 @@ -1618,7 +1619,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
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.Preconditions;
import com.google.common.collect.ImmutableSet;
import io.papermc.paper.adventure.PaperAdventure;
Expand Down Expand Up @@ -326,6 +327,7 @@ public InventoryView getOpenInventory() {
@Override
public InventoryView openInventory(Inventory inventory) {
if (!(this.getHandle() instanceof ServerPlayer)) return null;
TickThread.ensureTickThread(this.entity, "Cannot open inventory async");
ServerPlayer player = (ServerPlayer) this.getHandle();
AbstractContainerMenu formerContainer = this.getHandle().containerMenu;

Expand Down Expand Up @@ -445,6 +447,7 @@ public void openInventory(InventoryView inventory) {
Preconditions.checkArgument(this.equals(inventory.getPlayer()), "InventoryView must belong to the opening player");
if (!(this.getHandle() instanceof ServerPlayer)) return; // TODO: NPC support?
if (((ServerPlayer) this.getHandle()).connection == null) return;
TickThread.ensureTickThread(this.entity, "Cannot open inventory view async");
if (this.getHandle().containerMenu != this.getHandle().inventoryMenu) {
// fire INVENTORY_CLOSE if one already open
((ServerPlayer) this.getHandle()).connection.handleContainerClose(new ServerboundContainerClosePacket(this.getHandle().containerMenu.containerId), org.bukkit.event.inventory.InventoryCloseEvent.Reason.OPEN_NEW); // Paper - Inventory close reason
Expand Down Expand Up @@ -501,6 +504,10 @@ private static int getMountInventoryColumns(final AbstractMountInventoryMenu mou
@Override
public InventoryView openMerchant(Merchant merchant, boolean force) {
Preconditions.checkNotNull(merchant, "merchant cannot be null");
if (merchant instanceof CraftEntity craftEntity) {
TickThread.ensureTickThread(craftEntity.entity, "Cannot open merchant screen async from merchant");
}
TickThread.ensureTickThread(this.entity, "Cannot open merchant screen async");

if (!force && merchant.isTrading()) {
return null;
Expand Down Expand Up @@ -562,7 +569,7 @@ public InventoryView openStonecutter(Location location, boolean force) {
}

private InventoryView openInventory(Location location, boolean force, Material material) {
org.spigotmc.AsyncCatcher.catchOp("open" + material);
TickThread.ensureTickThread(this.entity, "Cannot open " + material + " inventory async");
if (location == null) {
location = this.getLocation();
}
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.Preconditions;
import com.google.common.collect.Sets;
import io.papermc.paper.adventure.PaperAdventure;
Expand Down Expand Up @@ -505,7 +506,7 @@ public void setKiller(Player killer) {

@Override
public boolean addPotionEffect(PotionEffect effect) {
org.spigotmc.AsyncCatcher.catchOp("effect add"); // Paper
TickThread.ensureTickThread(this.entity, "Cannot add potion effect async");
return this.getHandle().addEffect(org.bukkit.craftbukkit.potion.CraftPotionUtil.fromBukkit(effect), EntityPotionEffectEvent.Cause.PLUGIN); // Paper - Don't ignore icon
}

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.destroystokyo.paper.event.player.PlayerSetSpawnEvent;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -1340,13 +1341,15 @@ public void setSprinting(boolean sprinting) {

@Override
public void loadData() {
TickThread.ensureTickThread(this.entity, "Cannot load data async");
this.server.getHandle().playerIo.load(this.getHandle().nameAndId())
.map(tag -> TagValueInput.create(ProblemReporter.DISCARDING, this.server.getServer().registryAccess(), tag))
.ifPresent(this.getHandle()::load);
}

@Override
public void saveData() {
TickThread.ensureTickThread(this.entity, "Cannot save data async");
this.server.getHandle().playerIo.save(this.getHandle());
}

Expand Down Expand Up @@ -1663,6 +1666,7 @@ public void setGameMode(GameMode mode) {
Preconditions.checkArgument(mode != null, "GameMode cannot be null");
if (this.getHandle().connection == null) return;

TickThread.ensureTickThread(this.entity, "Cannot set gamemode async");
this.getHandle().setGameMode(GameType.byId(mode.getValue()), org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.PLUGIN, null); // Paper - Expand PlayerGameModeChangeEvent
}

Expand Down
Loading