Interface Entity

All Superinterfaces:
CommandSender, Metadatable, Nameable, Permissible, PersistentDataHolder, ServerOperator
All Known Subinterfaces:
AbstractArrow, AbstractCow, AbstractHorse, AbstractSkeleton, AbstractVillager, AbstractWindCharge, AcaciaBoat, AcaciaChestBoat, Ageable, Allay, Ambient, Animals, AreaEffectCloud, Armadillo, ArmorStand, Arrow, Axolotl, BambooChestRaft, BambooRaft, Bat, Bee, BirchBoat, BirchChestBoat, Blaze, BlockDisplay, Boat, Bogged, Boss, Breedable, Breeze, BreezeWindCharge, Camel, Cat, CaveSpider, CherryBoat, CherryChestBoat, ChestBoat, ChestedHorse, Chicken, Cod, CommandMinecart, ComplexEntityPart, ComplexLivingEntity, Cow, Creaking, Creature, Creeper, Damageable, DarkOakBoat, DarkOakChestBoat, Display, Dolphin, Donkey, DragonFireball, Drowned, Egg, ElderGuardian, EnderCrystal, EnderDragon, EnderDragonPart, Enderman, Endermite, EnderPearl, EnderSignal, Enemy, Evoker, EvokerFangs, ExperienceOrb, Explosive, ExplosiveMinecart, FallingBlock, Fireball, Firework, Fish, FishHook, Flying, Fox, Frog, Ghast, Giant, GlowItemFrame, GlowSquid, Goat, Golem, Guardian, Hanging, Hoglin, HopperMinecart, Horse, HumanEntity, Husk, Illager, Illusioner, Interaction, IronGolem, Item, ItemDisplay, ItemFrame, JungleBoat, JungleChestBoat, LargeFireball, LeashHitch, LightningStrike, LingeringPotion, LivingEntity, Llama, LlamaSpit, MagmaCube, MangroveBoat, MangroveChestBoat, Marker, Minecart, Mob, Monster, Mule, MushroomCow, NPC, OakBoat, OakChestBoat, Ocelot, OminousItemSpawner, Painting, PaleOakBoat, PaleOakChestBoat, Panda, Parrot, Phantom, Pig, Piglin, PiglinAbstract, PiglinBrute, PigZombie, Pillager, Player, PolarBear, PoweredMinecart, Projectile, PufferFish, Rabbit, Raider, Ravager, RideableMinecart, Salmon, Sheep, Shulker, ShulkerBullet, Silverfish, SizedFireball, Skeleton, SkeletonHorse, Slime, SmallFireball, Sniffer, Snowball, Snowman, SpawnerMinecart, SpectralArrow, Spellcaster, Spider, SplashPotion, SpruceBoat, SpruceChestBoat, Squid, Steerable, StorageMinecart, Stray, Strider, Tadpole, Tameable, TextDisplay, ThrowableProjectile, ThrownExpBottle, ThrownPotion, TippedArrow, TNTPrimed, TraderLlama, Trident, TropicalFish, Turtle, Vehicle, Vex, Villager, Vindicator, WanderingTrader, Warden, WaterMob, WindCharge, Witch, Wither, WitherSkeleton, WitherSkull, Wolf, Zoglin, Zombie, ZombieHorse, ZombieVillager

public interface Entity extends Metadatable, CommandSender, Nameable, PersistentDataHolder
Represents a base entity in the world

Not all methods are guaranteed to work/may have side effects when isInWorld() is false.

  • Method Details Link icon

    • getLocation Link icon

      @NotNull Location getLocation()
      Gets the entity's current position
      Returns:
      a new copy of Location containing the position of this entity
    • getLocation Link icon

      @Contract("null -> null; !null -> !null") @Nullable Location getLocation(@Nullable Location loc)
      Stores the entity's current position in the provided Location object.

      If the provided Location is null this method does nothing and returns null.

      Parameters:
      loc - the location to copy into
      Returns:
      The Location object provided or null
    • setVelocity Link icon

      void setVelocity(@NotNull Vector velocity)
      Sets this entity's velocity in meters per tick
      Parameters:
      velocity - New velocity to travel with
    • getVelocity Link icon

      @NotNull Vector getVelocity()
      Gets this entity's current velocity
      Returns:
      Current traveling velocity of this entity
    • getHeight Link icon

      double getHeight()
      Gets the entity's height
      Returns:
      height of entity
    • getWidth Link icon

      double getWidth()
      Gets the entity's width
      Returns:
      width of entity
    • getBoundingBox Link icon

      @NotNull BoundingBox getBoundingBox()
      Gets the entity's current bounding box.

      The returned bounding box reflects the entity's current location and size.

      Returns:
      the entity's current bounding box
    • isOnGround Link icon

      boolean isOnGround()
      Returns true if the entity is supported by a block. This value is a state updated by the server and is not recalculated unless the entity moves.
      Returns:
      True if entity is on ground.
      See Also:
    • isInWater Link icon

      boolean isInWater()
      Returns true if the entity is in water.
      Returns:
      true if the entity is in water.
    • getWorld Link icon

      @NotNull World getWorld()
      Gets the current world this entity resides in
      Returns:
      World
    • setRotation Link icon

      void setRotation(float yaw, float pitch)
      Sets the entity's rotation.

      Note that if the entity is affected by AI, it may override this rotation.

      Parameters:
      yaw - the yaw
      pitch - the pitch
      Throws:
      UnsupportedOperationException - if used for players
    • teleport Link icon

      boolean teleport(@NotNull Location location)
      Teleports this entity to the given location. If this entity is riding a vehicle, it will be dismounted prior to teleportation.
      Parameters:
      location - New location to teleport this entity to
      Returns:
      true if the teleport was successful
    • teleport Link icon

      boolean teleport(@NotNull Location location, @NotNull PlayerTeleportEvent.TeleportCause cause)
      Teleports this entity to the given location. If this entity is riding a vehicle, it will be dismounted prior to teleportation.
      Parameters:
      location - New location to teleport this entity to
      cause - The cause of this teleportation
      Returns:
      true if the teleport was successful
    • teleport Link icon

      boolean teleport(@NotNull Entity destination)
      Teleports this entity to the target Entity. If this entity is riding a vehicle, it will be dismounted prior to teleportation.
      Parameters:
      destination - Entity to teleport this entity to
      Returns:
      true if the teleport was successful
    • teleport Link icon

      boolean teleport(@NotNull Entity destination, @NotNull PlayerTeleportEvent.TeleportCause cause)
      Teleports this entity to the target Entity. If this entity is riding a vehicle, it will be dismounted prior to teleportation.
      Parameters:
      destination - Entity to teleport this entity to
      cause - The cause of this teleportation
      Returns:
      true if the teleport was successful
    • getNearbyEntities Link icon

      @NotNull List<Entity> getNearbyEntities(double x, double y, double z)
      Returns a list of entities within a bounding box centered around this entity
      Parameters:
      x - 1/2 the size of the box along x axis
      y - 1/2 the size of the box along y axis
      z - 1/2 the size of the box along z axis
      Returns:
      List<Entity> List of entities nearby
    • getEntityId Link icon

      int getEntityId()
      Returns a unique id for this entity
      Returns:
      Entity id
    • getFireTicks Link icon

      int getFireTicks()
      Returns the entity's current fire ticks (ticks before the entity stops being on fire).
      Returns:
      int fireTicks
    • getMaxFireTicks Link icon

      int getMaxFireTicks()
      Returns the entity's maximum fire ticks.
      Returns:
      int maxFireTicks
    • setFireTicks Link icon

      void setFireTicks(int ticks)
      Sets the entity's current fire ticks (ticks before the entity stops being on fire).
      Parameters:
      ticks - Current ticks remaining
    • setVisualFire Link icon

      void setVisualFire(boolean fire)
      Sets if the entity has visual fire (it will always appear to be on fire).
      Parameters:
      fire - whether visual fire is enabled
    • isVisualFire Link icon

      boolean isVisualFire()
      Gets if the entity has visual fire (it will always appear to be on fire).
      Returns:
      whether visual fire is enabled
    • getFreezeTicks Link icon

      int getFreezeTicks()
      Returns the entity's current freeze ticks (amount of ticks the entity has been in powdered snow).
      Returns:
      int freeze ticks
    • getMaxFreezeTicks Link icon

      int getMaxFreezeTicks()
      Returns the entity's maximum freeze ticks (amount of ticks before it will be fully frozen)
      Returns:
      int max freeze ticks
    • setFreezeTicks Link icon

      void setFreezeTicks(int ticks)
      Sets the entity's current freeze ticks (amount of ticks the entity has been in powdered snow).
      Parameters:
      ticks - Current ticks
    • isFrozen Link icon

      boolean isFrozen()
      Gets if the entity is fully frozen (it has been in powdered snow for max freeze ticks).
      Returns:
      freeze status
    • remove Link icon

      void remove()
      Mark the entity's removal.
      Throws:
      UnsupportedOperationException - if you try to remove a Player use Player.kickPlayer(String) in this case instead
    • isDead Link icon

      boolean isDead()
      Returns true if this entity has been marked for removal.
      Returns:
      True if it is dead.
    • isValid Link icon

      boolean isValid()
      Returns false if the entity has died, been despawned for some other reason, or has not been added to the world.
      Returns:
      True if valid.
    • getServer Link icon

      @NotNull Server getServer()
      Gets the Server that contains this Entity
      Specified by:
      getServer in interface CommandSender
      Returns:
      Server instance running this Entity
    • isPersistent Link icon

      boolean isPersistent()
      Returns true if the entity gets persisted.

      By default all entities are persistent. An entity will also not get persisted, if it is riding an entity that is not persistent.

      The persistent flag on players controls whether or not to save their playerdata file when they quit. If a player is directly or indirectly riding a non-persistent entity, the vehicle at the root and all its passengers won't get persisted.

      This should not be confused with LivingEntity.setRemoveWhenFarAway(boolean) which controls despawning of living entities.

      Returns:
      true if this entity is persistent
    • setPersistent Link icon

      void setPersistent(boolean persistent)
      Sets whether or not the entity gets persisted.
      Parameters:
      persistent - the persistence status
      See Also:
    • getPassenger Link icon

      @Deprecated(since="1.11.2") @Nullable Entity getPassenger()
      Deprecated.
      entities may have multiple passengers, use getPassengers()
      Gets the primary passenger of a vehicle. For vehicles that could have multiple passengers, this will only return the primary passenger.
      Returns:
      an entity
    • setPassenger Link icon

      @Deprecated(since="1.11.2") boolean setPassenger(@NotNull Entity passenger)
      Deprecated.
      entities may have multiple passengers, use addPassenger(org.bukkit.entity.Entity)
      Set the passenger of a vehicle.
      Parameters:
      passenger - The new passenger.
      Returns:
      false if it could not be done for whatever reason
    • getPassengers Link icon

      @NotNull List<Entity> getPassengers()
      Gets a list of passengers of this vehicle.

      The returned list will not be directly linked to the entity's current passengers, and no guarantees are made as to its mutability.

      Returns:
      list of entities corresponding to current passengers.
    • addPassenger Link icon

      boolean addPassenger(@NotNull Entity passenger)
      Add a passenger to the vehicle.
      Parameters:
      passenger - The passenger to add
      Returns:
      false if it could not be done for whatever reason
    • removePassenger Link icon

      boolean removePassenger(@NotNull Entity passenger)
      Remove a passenger from the vehicle.
      Parameters:
      passenger - The passenger to remove
      Returns:
      false if it could not be done for whatever reason
    • isEmpty Link icon

      boolean isEmpty()
      Check if a vehicle has passengers.
      Returns:
      True if the vehicle has no passengers.
    • eject Link icon

      boolean eject()
      Eject any passenger.
      Returns:
      True if there was a passenger.
    • getFallDistance Link icon

      float getFallDistance()
      Returns the distance this entity has fallen
      Returns:
      The distance.
    • setFallDistance Link icon

      void setFallDistance(float distance)
      Sets the fall distance for this entity
      Parameters:
      distance - The new distance.
    • setLastDamageCause Link icon

      @Deprecated(since="1.20.4", forRemoval=true) void setLastDamageCause(@Nullable EntityDamageEvent event)
      Deprecated, for removal: This API element is subject to removal in a future version.
      method is for internal use only and will be removed
      Record the last EntityDamageEvent inflicted on this entity
      Parameters:
      event - a EntityDamageEvent
    • getLastDamageCause Link icon

      @Nullable EntityDamageEvent getLastDamageCause()
      Retrieve the last EntityDamageEvent inflicted on this entity. This event may have been cancelled.
      Returns:
      the last known EntityDamageEvent or null if hitherto unharmed
    • getUniqueId Link icon

      @NotNull UUID getUniqueId()
      Returns a unique and persistent id for this entity
      Returns:
      unique id
    • getTicksLived Link icon

      int getTicksLived()
      Gets the amount of ticks this entity has lived for.

      This is the equivalent to "age" in entities.

      Returns:
      Age of entity
    • setTicksLived Link icon

      void setTicksLived(int value)
      Sets the amount of ticks this entity has lived for.

      This is the equivalent to "age" in entities. May not be less than one tick.

      Parameters:
      value - Age of entity
    • playEffect Link icon

      void playEffect(@NotNull EntityEffect type)
      Performs the specified EntityEffect for this entity.

      This will be viewable to all players near the entity.

      If the effect is not applicable to this class of entity, it will not play.

      Parameters:
      type - Effect to play.
    • getType Link icon

      @NotNull EntityType getType()
      Get the type of the entity.
      Returns:
      The entity type.
    • getSwimSound Link icon

      @NotNull Sound getSwimSound()
      Get the Sound this entity makes while swimming.
      Returns:
      the swimming sound
    • getSwimSplashSound Link icon

      @NotNull Sound getSwimSplashSound()
      Get the Sound this entity makes when splashing in water. For most entities, this is just Sound.ENTITY_GENERIC_SPLASH.
      Returns:
      the splash sound
    • getSwimHighSpeedSplashSound Link icon

      @NotNull Sound getSwimHighSpeedSplashSound()
      Get the Sound this entity makes when splashing in water at high speeds. For most entities, this is just Sound.ENTITY_GENERIC_SPLASH.
      Returns:
      the splash sound
    • isInsideVehicle Link icon

      boolean isInsideVehicle()
      Returns whether this entity is inside a vehicle.
      Returns:
      True if the entity is in a vehicle.
    • leaveVehicle Link icon

      boolean leaveVehicle()
      Leave the current vehicle. If the entity is currently in a vehicle (and is removed from it), true will be returned, otherwise false will be returned.
      Returns:
      True if the entity was in a vehicle.
    • getVehicle Link icon

      @Nullable Entity getVehicle()
      Get the vehicle that this entity is inside. If there is no vehicle, null will be returned.
      Returns:
      The current vehicle.
    • setCustomNameVisible Link icon

      void setCustomNameVisible(boolean flag)
      Sets whether or not to display the mob's custom name client side. The name will be displayed above the mob similarly to a player.

      This value has no effect on players, they will always display their name.

      Parameters:
      flag - custom name or not
    • isCustomNameVisible Link icon

      boolean isCustomNameVisible()
      Gets whether or not the mob's custom name is displayed client side.

      This value has no effect on players, they will always display their name.

      Returns:
      if the custom name is displayed
    • setVisibleByDefault Link icon

      void setVisibleByDefault(boolean visible)
      Sets whether or not this entity is visible by default. If this entity is not visible by default, then Player.showEntity(org.bukkit.plugin.Plugin, org.bukkit.entity.Entity) will need to be called before the entity is visible to a given player.
      Parameters:
      visible - default visibility status
    • isVisibleByDefault Link icon

      boolean isVisibleByDefault()
      Gets whether or not this entity is visible by default. If this entity is not visible by default, then Player.showEntity(org.bukkit.plugin.Plugin, org.bukkit.entity.Entity) will need to be called before the entity is visible to a given player.
      Returns:
      default visibility status
    • getTrackedBy Link icon

      @NotNull Set<Player> getTrackedBy()
      Get all players that are currently tracking this entity.

      'Tracking' means that this entity has been sent to the player and that they are receiving updates on its state. Note that the client's 'Entity Distance' setting does not affect the range at which entities are tracked.

      Returns:
      the players tracking this entity, or an empty set if none
    • setGlowing Link icon

      void setGlowing(boolean flag)
      Sets whether the entity has a team colored (default: white) glow. nb: this refers to the 'Glowing' entity property, not whether a glowing potion effect is applied
      Parameters:
      flag - if the entity is glowing
    • isGlowing Link icon

      boolean isGlowing()
      Gets whether the entity is glowing or not. nb: this refers to the 'Glowing' entity property, not whether a glowing potion effect is applied
      Returns:
      whether the entity is glowing
    • setInvulnerable Link icon

      void setInvulnerable(boolean flag)
      Sets whether the entity is invulnerable or not.

      When an entity is invulnerable it can only be damaged by players in creative mode.

      Parameters:
      flag - if the entity is invulnerable
    • isInvulnerable Link icon

      boolean isInvulnerable()
      Gets whether the entity is invulnerable or not.
      Returns:
      whether the entity is
    • isSilent Link icon

      boolean isSilent()
      Gets whether the entity is silent or not.
      Returns:
      whether the entity is silent.
    • setSilent Link icon

      void setSilent(boolean flag)
      Sets whether the entity is silent or not.

      When an entity is silent it will not produce any sound.

      Parameters:
      flag - if the entity is silent
    • hasGravity Link icon

      boolean hasGravity()
      Returns whether gravity applies to this entity.
      Returns:
      whether gravity applies
    • setGravity Link icon

      void setGravity(boolean gravity)
      Sets whether gravity applies to this entity.
      Parameters:
      gravity - whether gravity should apply
    • getPortalCooldown Link icon

      int getPortalCooldown()
      Gets the period of time (in ticks) before this entity can use a portal.
      Returns:
      portal cooldown ticks
    • setPortalCooldown Link icon

      void setPortalCooldown(int cooldown)
      Sets the period of time (in ticks) before this entity can use a portal.
      Parameters:
      cooldown - portal cooldown ticks
    • getScoreboardTags Link icon

      @NotNull Set<String> getScoreboardTags()
      Returns a set of tags for this entity.
      Entities can have no more than 1024 tags.
      Returns:
      a set of tags for this entity
    • addScoreboardTag Link icon

      boolean addScoreboardTag(@NotNull String tag)
      Add a tag to this entity.
      Entities can have no more than 1024 tags.
      Parameters:
      tag - the tag to add
      Returns:
      true if the tag was successfully added
    • removeScoreboardTag Link icon

      boolean removeScoreboardTag(@NotNull String tag)
      Removes a given tag from this entity.
      Parameters:
      tag - the tag to remove
      Returns:
      true if the tag was successfully removed
    • getPistonMoveReaction Link icon

      @NotNull PistonMoveReaction getPistonMoveReaction()
      Returns the reaction of the entity when moved by a piston.
      Returns:
      reaction
    • getFacing Link icon

      @NotNull BlockFace getFacing()
      Get the closest cardinal BlockFace direction an entity is currently facing.
      This will not return any non-cardinal directions such as BlockFace.UP or BlockFace.DOWN.
      Hanging entities will override this call and thus their behavior may be different.
      Returns:
      the entity's current cardinal facing.
      See Also:
    • getPose Link icon

      @NotNull Pose getPose()
      Gets the entity's current pose. Note that the pose is only updated at the end of a tick, so may be inconsistent with other methods. eg Player.isSneaking() being true does not imply the current pose will be Pose.SNEAKING
      Returns:
      current pose
    • getSpawnCategory Link icon

      @NotNull SpawnCategory getSpawnCategory()
      Get the category of spawn to which this entity belongs.
      Returns:
      the entity´s category spawn
    • isInWorld Link icon

      boolean isInWorld()
      Checks if this entity has been spawned in a world.
      Entities not spawned in a world will not tick, be sent to players, or be saved to the server files.
      Returns:
      whether the entity has been spawned in a world
    • getAsString Link icon

      @Nullable @Experimental String getAsString()
      Get this entity as an NBT string.

      This string should not be relied upon as a serializable value.

      Returns:
      the NBT string or null if one cannot be made
    • createSnapshot Link icon

      @Nullable @Experimental EntitySnapshot createSnapshot()
      Crates an EntitySnapshot representing the current state of this entity.
      Returns:
      a snapshot representing this entity or null if one cannot be made
    • copy Link icon

      @NotNull @Experimental Entity copy()
      Creates a copy of this entity and all its data. Does not spawn the copy in the world.
      Note: Players cannot be copied.
      Returns:
      a copy of this entity.
    • copy Link icon

      @NotNull @Experimental Entity copy(@NotNull Location to)
      Creates a copy of this entity and all its data. Spawns the copy at the given location.
      Note: Players cannot be copied.
      Parameters:
      to - the location to copy to
      Returns:
      a copy of this entity.
    • spigot Link icon

      @NotNull Entity.Spigot spigot()
      Specified by:
      spigot in interface CommandSender