Class FakeEntity
java.lang.Object
me.deecaad.core.compatibility.entity.FakeEntity
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
FieldsModifier and TypeFieldDescriptionprotected intstatic final intstatic final intstatic final intstatic final intprotected org.bukkit.Locationprotected org.bukkit.util.Vectorprotected org.bukkit.Locationstatic final intstatic final intstatic final intprotected final org.bukkit.entity.EntityType -
Constructor Summary
ConstructorsConstructorDescriptionFakeEntity(@NotNull org.bukkit.Location location, @NotNull org.bukkit.entity.EntityType type) -
Method Summary
Modifier and TypeMethodDescriptionprotected final byteconvertPitch(float degrees) protected final byteconvertYaw(float degrees) abstract @Nullable ObjectgetData()Returns the data that was used in the constructor (or insetData(Object)).abstract booleangetMeta(int metaFlag) Gets the stored meta-data flag.floatgetPitch()org.bukkit.entity.EntityTypegetType()doublegetX()doublegetY()floatgetYaw()doublegetZ()final booleanfinal booleanfinal booleanisOnFire()abstract voidplayEffect(@NotNull org.bukkit.EntityEffect effect) Plays an entity effect for this entity.abstract voidremove()Hides the entity for all players that currently see it.abstract voidremove(@NotNull org.bukkit.entity.Player player) Hides the entity for the given player.abstract voidSets the data usually used in the constructor of aFakeEntity.abstract voidsetDisplay(@Nullable String display) Sets the display name of the entity.abstract voidsetEquipment(@NotNull org.bukkit.inventory.EquipmentSlot equipmentSlot, @Nullable org.bukkit.inventory.ItemStack itemStack) Sets new item to given equipment slot.final voidsetGlowing(boolean isGlowing) abstract voidsetGravity(boolean gravity) Disables entity gravity.final voidsetInvisible(boolean isInvisible) protected voidsetLocation(double x, double y, double z, float yaw, float pitch) abstract voidsetMeta(int metaFlag, boolean isEnabled) Sets this entity's meta-data at the givenmetaFlagindex.abstract voidsetMotion(double dx, double dy, double dz) Sends an entity velocity packet to all players who can see this entity.final voidsetMotion(@NotNull org.bukkit.util.Vector motion) Shorthand forsetMotion(double, double, double).voidsetOffset(org.bukkit.Location offset) Sets the location offset for this entity.final voidsetOnFire(boolean isOnFire) final voidsetPosition(double x, double y, double z) Shorthand for callingsetPosition(double, double, double, float, float, boolean).final voidsetPosition(double x, double y, double z, float yaw, float pitch) Shorthand for callingsetPosition(double, double, double, float, float, boolean).final voidsetPosition(double x, double y, double z, float yaw, float pitch, boolean raw) Sets position of this entity.final voidsetPosition(@NotNull org.bukkit.util.Vector pos, float yaw, float pitch) Shorthand for callingsetPosition(double, double, double, float, float).protected abstract voidsetPositionRaw(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 voidsetPositionRotation(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 voidsetRotation(float yaw, float pitch) Sends an entity rotation packet to all players who can see this entity.abstract voidshow()Shows this entity to all players within range of the entity.abstract voidshow(@NotNull org.bukkit.entity.Player player) Shows the entity to the given player.abstract voidUpdates the equipment for all players that currently see it.abstract voidUpdates the meta for all players that currently see it.
-
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 givenmetaFlagindex. You can toggle a meta flag by checkinggetMeta(int). smaller thanmetaFlagshould be one of the flag constants in theFakeEntity(this) class. After these modifications, callupdateMeta()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
Returns the data that was used in the constructor (or insetData(Object)). The data will either be anItemStack, or aBlockData- Returns:
- The nullable extra data (block or item).
-
setData
Sets the data usually used in the constructor of aFakeEntity. As of the time of writing,datamay only be anItemStack, and this method will only have any behavior for armorstands and dropped items.- Parameters:
data- The nullable data.
-
setDisplay
Sets the display name of the entity. Usenullto remove the any previous display name. Supports color codes usingChatColor. After calling this method, useupdateMeta()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 useupdateMeta()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) Shorthand forsetMotion(double, double, double).- 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.locationusingLocation.setYaw(float)andLocation.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) Shorthand for callingsetPosition(double, double, double, float, float).- 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) Shorthand for callingsetPosition(double, double, double, float, float, boolean).- 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) Shorthand for callingsetPosition(double, double, double, float, float, boolean).- 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()andgetPitch().- 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 callingshow(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 usingshow(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 usingshow(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'sgetType().- 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 modifyitemStack- 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 tosetEquipment(EquipmentSlot, ItemStack).
-