bukkitEntities

Teleporting an entity to another entity

Entity entity;     //The entity you want to teleport
Entity teleportTo; //The entity where you want <entity> to be teleported to

boolean success = entity.teleport(teleportTo);   //Attempting to teleport.

if(success) {
//Teleport was successful
}else {
//Teleport wasn't successful
}

You can also add a cause to your teleport, so you can customize how your cause will be treated by your plugin or by others:

Entity entity;     //The entity you want to teleport
Entity teleportTo; //The entity where you want <entity> to be teleported to
PlayerTeleportEvent.TeleportCause cause;    //The cause you want the teleport to be of

boolean success = entity.teleport(teleportTo, cause);   //Attempting to teleport.

if(success) {
//Teleport was successful
}else {
//Teleport wasn't successful
}

Teleporting an entity to a location

Entity toBeTeleported;    //The entity you want to teleport
Location teleportTo = new Location(world,x,y,z,yaw,pitch);    //The location to teleport to


boolean success = toBeTeleported.teleport(teleportTo);

if(success) {
    //Teleport was successful
}else {
    //Teleport wasn't successful
}

You can also add a cause to your teleport, so you can customize how your cause will be treated by your plugin or by others:

Entity toBeTeleported;    //The entity you want to teleport
Location teleportTo = new Location(world,x,y,z,yaw,pitch);    //The location to teleport to
PlayerTeleportEvent.TeleportCause cause;    //The cause you want the teleport to be of


boolean success = toBeTeleported.teleport(teleportTo, cause);

if(success) {
    //Teleport was successful
}else {
    //Teleport wasn't successful
}

EntityType

The EntityType enum represents all the entities from Bukkit/Spigot.

All its values can be found below.

ValueDescription
AREA_EFFECT_CLOUDN/A
ARMOR_STANDMechanical entity with an inventory for placing weapons / armor into.
ARROWAn arrow projectile; may get stuck in the ground.
BATN/A
BLAZEN/A
BOATA place boat
CAVE_SPIDERN/A
CHICKENN/A
COMPLEX_PARTN/A
COWN/A
CREEPERN/A
DRAGON_FIREBALLLike FIREBALL, but with extra effects
DROPPED_ITEMAn item resting on the ground.
EGGA flying chicken egg.
ENDER_CRYSTALN/A
ENDER_DRAGONN/A
ENDER_PEARLA flying ender pearl.
ENDER_SIGNALAn ender eye signal.
ENDERMANN/A
ENDERMITEN/A
EXPERIENCE_ORBAn experience orb.
FALLING_BLOCKA block that is going to or is about to fall.
FIREBALLA flying large fireball, as thrown by a Ghast for example.
FIREWORKInternal representation of a Firework once it has been launched.
FISHING_HOOKA fishing line and bobber.
GHASTN/A
GIANTN/A
GUARDIANN/A
HORSEN/A
IRON_GOLEMN/A
ITEM_FRAMEAn item frame on a wall.
LEASH_HITCHA leash attached to a fencepost.
LIGHTNINGA bolt of lightning.
LINGERING_POTIONA flying lingering potion
MAGMA_CUBEN/A
MINECARTN/A
MINECART_CHESTN/A
MINECART_COMMANDN/A
MINECART_FURNACEN/A
MINECART_HOPPERN/A
MINECART_MOB_SPAWNERN/A
MINECART_TNTN/A
MUSHROOM_COWN/A
OCELOTN/A
PAINTINGA painting on a wall.
PIGN/A
PIG_ZOMBIEN/A
PLAYERN/A
POLAR_BEARN/A
PRIMED_TNTPrimed TNT that is about to explode.
RABBITN/A
SHEEPN/A
SHULKERN/A
SHULKER_BULLETBullet fired by SHULKER.
SILVERFISHN/A
SKELETONN/A
SLIMEN/A
SMALL_FIREBALLA flying small fireball, such as thrown by a Blaze or player.
SNOWBALLA flying snowball.
SNOWMANN/A
SPECTRAL_ARROWLike TIPPED_ARROW but causes the PotionEffectType.GLOWING effect on all team members.
SPIDERN/A
SPLASH_POTIONA flying splash potion
SQUIDN/A
THROWN_EXP_BOTTLEA flying experience bottle.
TIPPED_ARROWLike ARROW but tipped with a specific potion which is applied on contact.
UNKNOWNAn unknown entity without an Entity Class
VILLAGERN/A
WEATHERN/A
WITCHN/A
WITHERN/A
WITHER_SKULLA flying wither skull projectile.
WOLFN/A
ZOMBIEN/A

Passenger

Entities can have passengers. A good example of a passenger is a Player riding a saddled pig, or a zombie inside a minecart.

Although there are specific vehicles, any entity can be a vehicle for any other entity with the SetPassenger method.

Entity vehicle;
Entity passenger;
boolean result = vehicle.setPassenger(passenger);   //False if couldn't be done for whatever reason

The passenger should now be attached to the vehicle


You can check if an entity has a passenger using

boolean hasPassenger =  entity.isEmpty()

If the entity has a passenger, you can retrieve the passenger entity with

Entity passenger = entity.getPassenger();

Will only return the primary passenger if the vehicle can have multiples.


Finally, you can eject an entity's passenger with

boolean b = entity.eject();   //Eject all passengers - returns true if there was a passenger to be ejected

Nearby Entities

To retrieve a list of nearby entities of an entity, one can use

List<Entity> nearby = entity.getNearbyEntities(double x, double y, double z);

Bukkit will then calculate a bounding box centered around entity, having as 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

The list may be empty, meaning that there are no nearby entities with the parameters.

This approach can be used to detect entities near custom projectiles, for example launching an Itemstack and detecting when it collides with a player