Add and use FeatureHooks.getAllEntities

The ServerLevel#getAllEntities function only returns entities which
are accessible. FeatureHooks#getAllEntities will return all
entities, whether or not they are accessible.

Use the new hook in the EntityCommand, which allows server admins
to inspect entities in unloaded chunks.

Use the hook as well for ticking the EntityScheduler. This fixes
an issue whether unloaded entities did not have their scheduler ticked.
This commit is contained in:
Spottedleaf
2025-06-24 04:55:58 -07:00
parent 46b4b0b8d5
commit 38c1ddb52a
8 changed files with 68 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package io.papermc.paper.command.subcommands;
import com.google.common.collect.Maps;
import io.papermc.paper.FeatureHooks;
import io.papermc.paper.command.CommandUtil;
import io.papermc.paper.command.PaperSubcommand;
import java.util.Collections;
@@ -9,7 +10,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
@@ -102,7 +102,7 @@ public final class EntityCommand implements PaperSubcommand {
ServerLevel world = ((CraftWorld) bukkitWorld).getHandle();
Map<ResourceLocation, Integer> nonEntityTicking = Maps.newHashMap();
ServerChunkCache chunkProviderServer = world.getChunkSource();
world.getAllEntities().forEach(e -> {
FeatureHooks.getAllEntities(world).forEach(e -> {
ResourceLocation key = EntityType.getKey(e.getType());
MutablePair<Integer, Map<ChunkPos, Integer>> info = list.computeIfAbsent(key, k -> MutablePair.of(0, Maps.newHashMap()));