Class FakeEntity

java.lang.Object
me.deecaad.core.compatibility.entity.FakeEntity

public abstract class FakeEntity extends Object
Defines a packet based Entity with no server functions. Faked entities are not ticked, rendered, moved, or in any other way "handled" by the server.

Fake entities are usually used for visual effects, since faked entities can control appearances per player. After changing a visual effect (metadata + display name + gravity + etc), a metadata packet must be sent using updateMeta().

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    protected org.bukkit.Location
     
    protected org.bukkit.util.Vector
     
    protected org.bukkit.Location
     
    static final int
     
    static final int
     
    static final int
     
    protected final org.bukkit.entity.EntityType
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    FakeEntity(@NotNull org.bukkit.Location location, @NotNull org.bukkit.entity.EntityType type)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final byte
    convertPitch(float degrees)
     
    protected final byte
    convertYaw(float degrees)
     
    abstract @Nullable Object
    Returns the data that was used in the constructor (or in setData(Object)).
    abstract boolean
    getMeta(int metaFlag)
    Gets the stored meta-data flag.
    float
     
    org.bukkit.entity.EntityType
     
    double
     
    double
     
    float
     
    double
     
    final boolean
     
    final boolean
     
    final boolean
     
    abstract void
    playEffect(@NotNull org.bukkit.EntityEffect effect)
    Plays an entity effect for this entity.
    abstract void
    Hides the entity for all players that currently see it.
    abstract void
    remove(@NotNull org.bukkit.entity.Player player)
    Hides the entity for the given player.
    abstract void
    setData(@Nullable Object data)
    Sets the data usually used in the constructor of a FakeEntity.
    abstract void
    setDisplay(@Nullable String display)
    Sets the display name of the entity.
    abstract void
    setEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, @Nullable org.bukkit.inventory.ItemStack itemStack)
    Sets new item to given equipment slot.
    final void
    setGlowing(boolean isGlowing)
     
    abstract void
    setGravity(boolean gravity)
    Disables entity gravity.
    final void
    setInvisible(boolean isInvisible)
     
    protected void
    setLocation(double x, double y, double z, float yaw, float pitch)
     
    abstract void
    setMeta(int metaFlag, boolean isEnabled)
    Sets this entity's meta-data at the given metaFlag index.
    abstract void
    setMotion(double dx, double dy, double dz)
    Sends an entity velocity packet to all players who can see this entity.
    final void
    setMotion(@NotNull org.bukkit.util.Vector motion)
    void
    setOffset(org.bukkit.Location offset)
    Sets the location offset for this entity.
    final void
    setOnFire(boolean isOnFire)
     
    final void
    setPosition(double x, double y, double z)
    final void
    setPosition(double x, double y, double z, float yaw, float pitch)
    final void
    setPosition(double x, double y, double z, float yaw, float pitch, boolean raw)
    Sets position of this entity.
    final void
    setPosition(@NotNull org.bukkit.util.Vector pos, float yaw, float pitch)
    protected abstract void
    setPositionRaw(double x, double y, double z, float yaw, float pitch)
    Sends an entity teleport packet to all players who can see this entity.
    protected abstract void
    setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch)
    Sends an entity move-look packet to all players who can see this entity.
    abstract void
    setRotation(float yaw, float pitch)
    Sends an entity rotation packet to all players who can see this entity.
    abstract void
    Shows this entity to all players within range of the entity.
    abstract void
    show(@NotNull org.bukkit.entity.Player player)
    Shows the entity to the given player.
    abstract void
    Updates the equipment for all players that currently see it.
    abstract void
    Updates the meta for all players that currently see it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FIRE_FLAG

      public static final int FIRE_FLAG
      See Also:
    • SNEAKING_FLAG

      public static final int SNEAKING_FLAG
      See Also:
    • SPRINTING_FLAG

      public static final int SPRINTING_FLAG
      See Also:
    • SWIMMING_FLAG

      public static final int SWIMMING_FLAG
      See Also:
    • INVISIBLE_FLAG

      public static final int INVISIBLE_FLAG
      See Also:
    • GLOWING_FLAG

      public static final int GLOWING_FLAG
      See Also:
    • GLIDING_FLAG

      public static final int GLIDING_FLAG
      See Also:
    • type

      protected final org.bukkit.entity.EntityType type
    • location

      protected org.bukkit.Location location
    • offset

      protected org.bukkit.Location offset
    • motion

      protected org.bukkit.util.Vector motion
    • cache

      protected int cache
  • Constructor Details

    • FakeEntity

      public FakeEntity(@NotNull @NotNull org.bukkit.Location location, @NotNull @NotNull org.bukkit.entity.EntityType type)
  • Method Details

    • getType

      public org.bukkit.entity.EntityType getType()
    • isOnFire

      public final boolean isOnFire()
    • isGlowing

      public final boolean isGlowing()
    • isInvisible

      public final boolean isInvisible()
    • getMeta

      public abstract boolean getMeta(int metaFlag)
      Gets the stored meta-data flag.
      Parameters:
      metaFlag - The index location of which flag to edit.
      Returns:
      Whether the flag is enabled or disabled.
      See Also:
    • setOnFire

      public final void setOnFire(boolean isOnFire)
    • setGlowing

      public final void setGlowing(boolean isGlowing)
    • setInvisible

      public final void setInvisible(boolean isInvisible)
    • setMeta

      public abstract void setMeta(int metaFlag, boolean isEnabled)
      Sets this entity's meta-data at the given metaFlag index. You can toggle a meta flag by checking getMeta(int). smaller than metaFlag should be one of the flag constants in the FakeEntity (this) class. After these modifications, call updateMeta() to show player's changes.
      Parameters:
      metaFlag - The index location of which flag to edit.
      isEnabled - Whether to enable or disable the flag.
      See Also:
    • getData

      @Nullable public abstract @Nullable Object getData()
      Returns the data that was used in the constructor (or in setData(Object)). The data will either be an ItemStack, or a BlockData
      Returns:
      The nullable extra data (block or item).
    • setData

      public abstract void setData(@Nullable @Nullable Object data)
      Sets the data usually used in the constructor of a FakeEntity. As of the time of writing, data may only be an ItemStack, and this method will only have any behavior for armorstands and dropped items.
      Parameters:
      data - The nullable data.
    • setDisplay

      public abstract void setDisplay(@Nullable @Nullable String display)
      Sets the display name of the entity. Use null to remove the any previous display name. Supports color codes using ChatColor. After calling this method, use updateMeta() to show the information to clients.
      Parameters:
      display - The nullable entity display-name.
    • setGravity

      public abstract void setGravity(boolean gravity)
      Disables entity gravity. This has no effect server-side, and will not affect motion/position/rotation/anything. Instead, this method tells the client that the entity should not automatically have gravity applied. After calling this method use updateMeta() to show the information to clients.
      Parameters:
      gravity - true -> gravity, false -> no gravity.
    • getX

      public double getX()
    • getY

      public double getY()
    • getZ

      public double getZ()
    • getYaw

      public float getYaw()
    • getPitch

      public float getPitch()
    • setOffset

      public void setOffset(org.bukkit.Location offset)
      Sets the location offset for this entity. Entity yaw and pitch are also modified based on this value. This offset is applied to entity when any move packet or such is sent to the player.
      Parameters:
      offset - The vector changing FakeEntity position
    • setLocation

      protected void setLocation(double x, double y, double z, float yaw, float pitch)
    • setMotion

      public final void setMotion(@NotNull @NotNull org.bukkit.util.Vector motion)
      Parameters:
      motion - The motion the entity is moving with.
      See Also:
    • setMotion

      public abstract void setMotion(double dx, double dy, double dz)
      Sends an entity velocity packet to all players who can see this entity.
      Parameters:
      dx - The change of position in the x-axis.
      dy - The change of position in the y-axis.
      dz - The change of position in the z-axis.
    • setRotation

      public abstract void setRotation(float yaw, float pitch)
      Sends an entity rotation packet to all players who can see this entity.

      Implementing classes should set this.location using Location.setYaw(float) and Location.setPitch(float).

      Parameters:
      yaw - The absolute yaw rotation of the entity.
      pitch - The absolute pitch rotation of the entity.
    • setPosition

      public final void setPosition(@NotNull @NotNull org.bukkit.util.Vector pos, float yaw, float pitch)
      Parameters:
      pos - The non-null new position of the entity.
      yaw - The yaw to set the entity at.
      pitch - The pitch to set the entity at.
    • setPosition

      public final void setPosition(double x, double y, double z)
      Parameters:
      x - The new position on the x-axis.
      y - The new position on the y-axis.
      z - The new position on the z-axis.
    • setPosition

      public final void setPosition(double x, double y, double z, float yaw, float pitch)
      Parameters:
      x - The new position on the x-axis.
      y - The new position on the y-axis.
      z - The new position on the z-axis.
      yaw - The yaw to set the entity at.
      pitch - The pitch to set the entity at.
    • setPosition

      public final void setPosition(double x, double y, double z, float yaw, float pitch, boolean raw)
      Sets position of this entity. When the new location is within 8 blocks, a move-look packet is sent (using a relative position). Otherwise, a teleport packet is sent (using an absolute position).

      If you do not want to change the entity's yaw/pitch, you may use getYaw() and getPitch().

      Parameters:
      x - The new position on the x-axis.
      y - The new position on the y-axis.
      z - The new position on the z-axis.
      yaw - The yaw to set the entity at.
      pitch - The pitch to set the entity at.
      raw - true to always use a teleport packet.
    • setPositionRotation

      protected abstract void setPositionRotation(short dx, short dy, short dz, byte yaw, byte pitch)
      Sends an entity move-look packet to all players who can see this entity. Effectively sets the relative position of the entity.

      This method is protected to prevent accidental/improper usage.

      Parameters:
      dx - The change of position across the x-axis.
      dy - The change of position across the y-axis.
      dz - The change of position across the z-axis.
      yaw - The absolute yaw rotation of the entity.
      pitch - The absolute pitch rotation of the entity.
    • setPositionRaw

      protected abstract void setPositionRaw(double x, double y, double z, float yaw, float pitch)
      Sends an entity teleport packet to all players who can see this entity. Effectively sets the absolute position of the entity.

      This method is protected to prevent accidental/improper usage.

      Parameters:
      x - The absolute x position of the entity.
      y - The absolute y position of the entity.
      z - The absolute z position of the entity.
      yaw - The absolute yaw rotation of the entity.
      pitch - The absolute pitch rotation of the entity.
    • convertPitch

      protected final byte convertPitch(float degrees)
    • convertYaw

      protected final byte convertYaw(float degrees)
    • show

      public abstract void show()
      Shows this entity to all players within range of the entity. Effectively the same as calling show(Player) for each player. Sends an Add Entity packet and an Entity Meta packet.
    • show

      public abstract void show(@NotNull @NotNull org.bukkit.entity.Player player)
      Shows the entity to the given player. Sends an add Entity packet and an Entity Meta packet.
      Parameters:
      player - The non-null player to show the entity to.
    • updateMeta

      public abstract void updateMeta()
      Updates the meta for all players that currently see it. This method should be used after any modifications to entity meta.
    • remove

      public abstract void remove()
      Hides the entity for all players that currently see it. Sends an entity destroy packet. Players will not be able to see position or rotation or meta or velocity changes after calling this method (Unless they are added back using show(Player)).
    • remove

      public abstract void remove(@NotNull @NotNull org.bukkit.entity.Player player)
      Hides the entity for the given player. Sends an Entity Destroy packet. The player will not be able to see position or rotation or meta or velocity changes after calling this method (Unless they are added back using show(Player)).
      Parameters:
      player - The non-null player to hide the entity from.
    • playEffect

      public abstract void playEffect(@NotNull @NotNull org.bukkit.EntityEffect effect)
      Plays an entity effect for this entity. Make sure that the given effect can be used for this entity's getType().
      Parameters:
      effect - The non-null effect to play.
    • setEquipment

      public abstract void setEquipment(@NotNull @NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, @Nullable @Nullable org.bukkit.inventory.ItemStack itemStack)
      Sets new item to given equipment slot.
      Parameters:
      equipmentSlot - the equipment slot to modify
      itemStack - the item stack set to slot
    • updateEquipment

      public abstract void updateEquipment()
      Updates the equipment for all players that currently see it. This method should be used after any modifications to setEquipment(EquipmentSlot, ItemStack).