Class EntityCache

java.lang.Object
org.geysermc.geyser.session.cache.EntityCache

public class EntityCache extends Object
Each session has its own EntityCache in the occasion that an entity packet is sent specifically for that player (e.g. seeing vanished players from /vanish)
  • Constructor Details

  • Method Details

    • nextEntityId

      public long nextEntityId()
    • getEntitiesUnsafe

      public it.unimi.dsi.fastutil.longs.Long2ObjectMap<Entity> getEntitiesUnsafe()
      Returns the raw, mutable backing entity map. This bypasses the read/write lock that guards the map, so it must only be accessed on the session's event loop thread, where it is sequential with all mutations. You should never mutate it directly, use spawnEntity(Entity) or removeEntity(Entity) and related methods instead. Off-thread callers - mainly API users - must instead use getEntityByGeyserId(long), getEntityByJavaId(int) or getEntityByUuid(UUID).
    • spawnEntity

      public void spawnEntity(Entity entity)
    • cacheEntity

      public boolean cacheEntity(Entity entity)
    • reassignGeyserId

      public long reassignGeyserId(Entity entity)
      Moves a cached entity to a fresh Geyser id and returns the new id. For an entity the Bedrock client removed on its own while Java still has it: the client ignores a spawn for an id it already removed, so the entity has to be spawned again under a new one. The caller stores the id and sends the spawn.
    • removeEntity

      public void removeEntity(Entity entity)
    • markDirty

      public void markDirty(Entity entity)
    • removeAllEntities

      public void removeAllEntities()
    • getEntityByGeyserId

      public Entity getEntityByGeyserId(long geyserId)
      Safe to call from any thread. When called off the session's event loop thread, the lookup is guarded by the read lock; on the event loop it reads directly since it is sequential with all writes there.
    • getEntityByJavaId

      public Entity getEntityByJavaId(int javaId)
      Safe to call from any thread. When called off the session's event loop thread, the lookup is guarded by the read lock; on the event loop it reads directly since it is sequential with all writes there.
    • getEntityByUuid

      public Entity getEntityByUuid(UUID uuid)
      Safe to call from any thread. When called off the session's event loop thread, the lookup is guarded by the read lock; on the event loop it reads directly since it is sequential with all writes there.
    • addPlayerEntity

      public void addPlayerEntity(PlayerEntity entity)
    • getPlayerEntity

      public PlayerEntity getPlayerEntity(UUID uuid)
    • getPlayersByName

      public List<PlayerEntity> getPlayersByName(String name)
    • removePlayerEntity

      public PlayerEntity removePlayerEntity(UUID uuid)
    • forEachPlayerEntity

      public void forEachPlayerEntity(Consumer<PlayerEntity> player)
      Run a specific bit of code for each cached player entity. As usual with synchronized, try to minimize the amount of work you because you block the PlayerList collection.
    • removeAllPlayerEntities

      public void removeAllPlayerEntities()
    • addBossBar

      public void addBossBar(UUID uuid, BossBar bossBar)
    • getBossBar

      public BossBar getBossBar(UUID uuid)
    • removeBossBar

      public void removeBossBar(UUID uuid)
    • updateBossBars

      public void updateBossBars()
    • removeAllBossBars

      public void removeAllBossBars()
    • getTickableEntities

      public List<Tickable> getTickableEntities()
      A list of all entities that must be ticked.
    • getDirtyEntities

      public Set<Entity> getDirtyEntities()
    • getNextEntityId

      public AtomicLong getNextEntityId()