Files
Paper/paper-api/src/main/java/org/bukkit/entity/Entity.java
Bukkit/Spigot dd1bee786b [Bleeding] Added a Metadata framework for Entities, Blocks, and Worlds
This metadata implementation has the following features:

- All metadata is lazy. Metadata values are not actually computed until another plugin requests them. Memory and CPU are conserved by not computing and storing unnecessary metadata values.

- All metadata is cached. Once a metadata value is computed its value is cached in the metadata store to prevent further unnecessary computation. An invalidation mechanism is provided to flush the cache and force recompilation of metadata values.

- All metadata is stored in basic data types. Convenience methods in the MetadataValue class allow for the conversion of metadata data types when possible. Restricting metadata to basic data types prevents the accidental linking of large object graphs into metadata. Metadata is persistent across the lifetime of the application and adding large object graphs would damage garbage collector performance.

- Metadata access is thread safe. Care has been taken to protect the internal data structures and access them in a thread safe manner.

- Metadata is exposed for all objects that descend from Entity, Block, and World. All Entity and World metadata is stored at the Server  level and all Block metadata is stored at the World level.

- Metadata is NOT keyed on references to original objects - instead metadata is keyed off of unique fields within those objects. Doing this allows metadata to exist for blocks that are in chunks not currently in memory. Additionally, Player objects are keyed off of player name so that Player metadata remains consistent between logins.

- Metadata convenience methods have been added to all Entities, Players, Blocks, BlockStates, and World allowing direct access to an individual instance's metadata.

- Players and OfflinePlayers share a single metadata store, allowing player metadata to be manipulated regardless of the player's current online status.

By: rmichela <deltahat@gmail.com>
2011-12-08 00:33:33 -05:00

237 lines
6.0 KiB
Java

package org.bukkit.entity;
import org.bukkit.Location;
import org.bukkit.EntityEffect;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.metadata.Metadatable;
import org.bukkit.util.Vector;
import java.util.List;
import java.util.UUID;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
/**
* Represents a base entity in the world
*/
public interface Entity extends Metadatable {
/**
* Gets the entity's current position
*
* @return Location containing the position of this entity
*/
public Location getLocation();
/**
* Sets this entity's velocity
*
* @param velocity New velocity to travel with
*/
public void setVelocity(Vector velocity);
/**
* Gets this entity's current velocity
*
* @return Current travelling velocity of this entity
*/
public Vector getVelocity();
/**
* Gets the current world this entity resides in
*
* @return World
*/
public World getWorld();
/**
* Teleports this entity to the given location
*
* @param location New location to teleport this entity to
* @return <code>true</code> if the teleport was successful
*/
public boolean teleport(Location location);
/**
* Teleports this entity to the given location
*
* @param location New location to teleport this entity to
* @praram cause The cause of this teleportation
* @return <code>true</code> if the teleport was successful
*/
public boolean teleport(Location location, TeleportCause cause);
/**
* Teleports this entity to the target Entity
*
* @param destination Entity to teleport this entity to
* @return <code>true</code> if the teleport was successful
*/
public boolean teleport(Entity destination);
/**
* Teleports this entity to the target Entity
*
* @param destination Entity to teleport this entity to
* @praram cause The cause of this teleportation
* @return <code>true</code> if the teleport was successful
*/
public boolean teleport(Entity destination, TeleportCause cause);
/**
* Returns a list of entities within a bounding box centered around this entity
*
* @param x 1/2 the size of the box along x axis
* @param y 1/2 the size of the box along y axis
* @param z 1/2 the size of the box along z axis
* @return List<Entity> List of entities nearby
*/
public List<org.bukkit.entity.Entity> getNearbyEntities(double x, double y, double z);
/**
* Returns a unique id for this entity
*
* @return Entity id
*/
public int getEntityId();
/**
* Returns the entity's current fire ticks (ticks before the entity stops being on fire).
*
* @return int fireTicks
*/
public int getFireTicks();
/**
* Returns the entity's maximum fire ticks.
*
* @return int maxFireTicks
*/
public int getMaxFireTicks();
/**
* Sets the entity's current fire ticks (ticks before the entity stops being on fire).
*
* @param ticks Current ticks remaining
*/
public void setFireTicks(int ticks);
/**
* Mark the entity's removal.
*/
public void remove();
/**
* Returns true if this entity has been marked for removal.
*
* @return True if it is dead.
*/
public boolean isDead();
/**
* Gets the {@link Server} that contains this Entity
*
* @return Server instance running this Entity
*/
public Server getServer();
/**
* Gets the primary passenger of a vehicle. For vehicles that could have
* multiple passengers, this will only return the primary passenger.
*
* @return an entity
*/
public abstract Entity getPassenger();
/**
* Set the passenger of a vehicle.
*
* @param passenger The new passenger.
* @return false if it could not be done for whatever reason
*/
public abstract boolean setPassenger(Entity passenger);
/**
* Check if a vehicle has passengers.
*
* @return True if the vehicle has no passengers.
*/
public abstract boolean isEmpty();
/**
* Eject any passenger.
*
* @return True if there was a passenger.
*/
public abstract boolean eject();
/**
* Returns the distance this entity has fallen
*
* @return The distance.
*/
public float getFallDistance();
/**
* Sets the fall distance for this entity
*
* @param distance The new distance.
*/
public void setFallDistance(float distance);
/**
* Record the last {@link EntityDamageEvent} inflicted on this entity
*
* @param event a {@link EntityDamageEvent}
*/
public void setLastDamageCause(EntityDamageEvent event);
/**
* Retrieve the last {@link EntityDamageEvent} inflicted on this entity. This event may have been cancelled.
*
* @return the last known {@link EntityDamageEvent} or null if hitherto unharmed
*/
public EntityDamageEvent getLastDamageCause();
/**
* Returns a unique and persistent id for this entity
*
* @return unique id
*/
public UUID getUniqueId();
/**
* Gets the amount of ticks this entity has lived for.
* <p>
* This is the equivalent to "age" in entities.
*
* @return Age of entity
*/
public int getTicksLived();
/**
* Sets the amount of ticks this entity has lived for.
* <p>
* This is the equivalent to "age" in entities. May not be less than one tick.
*
* @param value Age of entity
*/
public void setTicksLived(int value);
/**
* Performs the specified {@link EntityEffect} for this entity.
* <p>
* This will be viewable to all players near the entity.
*
* @param type Effect to play.
*/
public void playEffect(EntityEffect type);
/**
* Get the type of the entity.
* @return The entity type.
*/
public EntityType getType();
}