Class EntityData<E extends org.bukkit.entity.Entity>
- All Implemented Interfaces:
SyntaxElement
,YggdrasilSerializable
,YggdrasilSerializable.YggdrasilExtendedSerializable
- Direct Known Subclasses:
AxolotlData
,BeeData
,BoatChestData
,BoatData
,CatData
,ChickenData
,CowData
,CreeperData
,DisplayData
,DroppedItemData
,EndermanData
,FallingBlockData
,FoxData
,FrogData
,GoatData
,LlamaData
,MinecartData
,MooshroomData
,OcelotData
,PandaData
,ParrotData
,PigData
,RabbitData
,SalmonData
,SheepData
,SimpleEntityData
,StriderData
,ThrownPotionData
,TropicalFishData
,VillagerData
,WolfData
,XpOrbData
,ZombieVillagerData
-
Nested Class Summary
Nested classes/interfaces inherited from interface ch.njol.yggdrasil.YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final Adjective
static final Message
static final Adjective
protected int
static Serializer
<EntityData> protected static boolean
protected static @Nullable Method
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canSpawn
(@Nullable org.bukkit.World world) Checks whether this entity type is allowed to spawn in the givenWorld
.create()
Creates an entity in the server but does not spawn itcreate
(org.bukkit.Location location) Creates an entity at the provided location, but does not spawn it NOTE: IfRegionAccessor.createEntity(Location, Class)
does not exist, will returnspawn(Location)
protected static <E extends org.bukkit.entity.Entity>
Evoid
deserialize
(Fields fields) Deserializes this object.protected boolean
deserialize
(String string) Deprecated, for removal: This API element is subject to removal in a future version.final boolean
protected abstract boolean
equals_i
(EntityData<?> obj) Internal helper forequals(Object)
to compare the specific data of thisEntityData
with another.static <E extends org.bukkit.entity.Entity>
EntityData<? super E> Creates anEntityData
that represents the given entity class.static <E extends org.bukkit.entity.Entity>
EntityData<? super E> fromEntity
(E entity) Creates anEntityData
that represents the given entity instance.protected @Nullable Adjective
static <E extends org.bukkit.entity.Entity>
E[]getAll
(EntityData<?>[] types, Class<E> type, org.bukkit.Chunk[] chunks) static <E extends org.bukkit.entity.Entity>
E[]getAll
(EntityData<?>[] types, Class<E> type, org.bukkit.World @Nullable [] worlds) E[]
getAll
(org.bukkit.World... worlds) static ch.njol.skript.entity.EntityData.EntityDataInfo
<?> getInfo
(Class<? extends EntityData<?>> entityDataClass) Retrieves theEntityData.EntityDataInfo
registered for the givenentityDataClass
.static @Nullable ch.njol.skript.entity.EntityData.EntityDataInfo
<?> Retrieves theEntityData.EntityDataInfo
associated with the givencodeName
.protected Noun
getName()
abstract @NotNull EntityData
Returns a more general version of thisEntityData
with specific data removed.@NotNull String
getType()
final int
hashCode()
protected abstract int
Internal method used byhashCode()
to include subclass-specific fields in the hash calculation for thisEntityData
.final boolean
init
(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) Performs initial setup for thisEntityData
before passing control to the more specificinit(Expression[], int, Kleenean, ParseResult)
.protected abstract boolean
init
(Literal<?>[] exprs, int matchedPattern, SkriptParser.ParseResult parseResult) Initializes thisEntityData
from the matched pattern and its associated literals.protected abstract boolean
Initializes thisEntityData
from either an entity class or a specificEntity
.isBaby()
final boolean
isInstance
(@Nullable org.bukkit.entity.Entity entity) isPlural()
abstract boolean
isSupertypeOf
(EntityData<?> entityData) Determines whether thisEntityData
is a supertype of the givenentityData
.protected abstract boolean
Determines whether the givenEntity
matches thisEntityData
data.static void
static @Nullable EntityData
<?> Prints errors.static @Nullable EntityData
<?> parseWithoutIndefiniteArticle
(String string) Prints errors.static <E extends org.bukkit.entity.Entity,
T extends EntityData<E>>
voidregister
(Class<T> dataClass, String name, Class<E> entityClass, int defaultName, String... codeNames) static <E extends org.bukkit.entity.Entity,
T extends EntityData<E>>
voidSerialises this object.abstract void
Applies thisEntityData
to a newly spawnedEntity
.final E
spawn
(org.bukkit.Location location) Spawn this entity data at a location.protected static <E extends org.bukkit.entity.Entity>
ESpawn this entity data at a location.Deprecated, for removal: This API element is subject to removal in a future version.final String
toString()
toString
(int flags) static String
static String
static String
toString
(org.bukkit.entity.Entity entity) static String
toString
(org.bukkit.entity.Entity entity, int flags) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.njol.skript.lang.SyntaxElement
getParser, preInit
-
Field Details
-
WORLD_1_17_CONSUMER_METHOD
-
WORLD_1_17_CONSUMER
protected static boolean WORLD_1_17_CONSUMER -
LANGUAGE_NODE
- See Also:
-
m_age_pattern
-
m_baby
-
m_adult
-
serializer
-
matchedPattern
protected int matchedPattern
-
-
Constructor Details
-
EntityData
public EntityData()
-
-
Method Details
-
onRegistrationStop
public static void onRegistrationStop() -
register
public static <E extends org.bukkit.entity.Entity,T extends EntityData<E>> void register(Class<T> dataClass, String name, Class<E> entityClass, String codeName) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
register
public static <E extends org.bukkit.entity.Entity,T extends EntityData<E>> void register(Class<T> dataClass, String name, Class<E> entityClass, int defaultName, String... codeNames) throws IllegalArgumentException - Throws:
IllegalArgumentException
-
init
public final boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) Performs initial setup for thisEntityData
before passing control to the more specificinit(Expression[], int, Kleenean, ParseResult)
.This method handles common behaviors such as tracking plurality (e.g. "a pig" vs "all pigs") and entity age (e.g. "baby zombie") based on the
Called just after the constructor andSkriptParser.ParseResult
's marker value.SyntaxElement.preInit()
.- Specified by:
init
in interfaceSyntaxElement
- Parameters:
exprs
- all %expr%s included in the matching pattern in the order they appear in the pattern. If an optional value was left out, it will still be included in this list holding the default value of the desired type, which usually depends on the event.matchedPattern
- The index of the pattern which matchedisDelayed
- Whether this expression is used after a delay or not (i.e. if the event has already passed when this expression will be called)parseResult
- Additional information about the match.- Returns:
- Whether this expression was initialised successfully. An error should be printed prior to returning false to specify the cause.
- See Also:
-
init
protected abstract boolean init(Literal<?>[] exprs, int matchedPattern, SkriptParser.ParseResult parseResult) Initializes thisEntityData
from the matched pattern and its associated literals.This is used when parsing entity data from user-written patterns such as "a saddled pig".
- Parameters:
exprs
- An array ofLiteral
expressions from the matched pattern, in the order they appear. If an optional value was omitted by the user, it will still be present in the array with a value ofnull
.matchedPattern
- The index of the pattern which matched.parseResult
- Additional information from the parser.- Returns:
true
if initialization was successful, otherwisefalse
.
-
init
protected abstract boolean init(@Nullable @Nullable Class<? extends E> entityClass, @Nullable E entity) Initializes thisEntityData
from either an entity class or a specificEntity
.Example usage:
spawn a pig at location(0, 0, 0): set {_entity} to event-entity spawn {_entity} at location(0, 0, 0)
- Parameters:
entityClass
- An entity's class, e.g. Playerentity
- An actual entity, or null to get an entity data for an entity class- Returns:
true
if initialization was successful, otherwisefalse
.
-
set
Applies thisEntityData
to a newly spawnedEntity
.This is used during entity spawning to set additional data, such as a saddled pig.
- Parameters:
entity
- The spawned entity.
-
match
Determines whether the givenEntity
matches thisEntityData
data.For example:
spawn a pig at location(0, 0, 0): set {_entity} to event-entity if {_entity} is a pig: # will pass if {_entity} is a saddled pig: # will not pass
- Parameters:
entity
- TheEntity
to match.- Returns:
true
if the entity matches, otherwisefalse
.
-
getType
- Returns:
- The entity's
Class
, such asPig.class
.
-
getSuperType
Returns a more general version of thisEntityData
with specific data removed.For example, calling this on
"a saddled pig"
would return"a pig"
. This is typically used to obtain the base entity type without any modifiers or traits.- Returns:
- A generalized
EntityData
representing the base entity type.
-
toString
-
getName
-
getAgeAdjective
-
toString
-
isPlural
- Returns:
Kleenean
determining whether thisEntityData
is representing plurality.
-
isBaby
- Returns:
Kleenean
determining whether thisEntityData
is representing baby type.
-
hashCode_i
protected abstract int hashCode_i()Internal method used byhashCode()
to include subclass-specific fields in the hash calculation for thisEntityData
.- Returns:
- A hash code representing subclass-specific data.
-
hashCode
public final int hashCode() -
equals_i
Internal helper forequals(Object)
to compare the specific data of thisEntityData
with another.- Parameters:
obj
- TheEntityData
to compare with.- Returns:
true
if the data is considered equal, otherwisefalse
.
-
equals
-
getInfo
public static ch.njol.skript.entity.EntityData.EntityDataInfo<?> getInfo(Class<? extends EntityData<?>> entityDataClass) Retrieves theEntityData.EntityDataInfo
registered for the givenentityDataClass
.- Parameters:
entityDataClass
- TheEntityData
class to look up.- Returns:
- The corresponding
EntityData.EntityDataInfo
instance. - Throws:
SkriptAPIException
- if the class has not been registered.
-
getInfo
@Nullable public static @Nullable ch.njol.skript.entity.EntityData.EntityDataInfo<?> getInfo(String codeName) Retrieves theEntityData.EntityDataInfo
associated with the givencodeName
.- Parameters:
codeName
- The code name used to register the entity data.- Returns:
- The corresponding
EntityData.EntityDataInfo
, ornull
if not found.
-
parse
Prints errors.- Parameters:
string
- String with optional indefinite article at the beginning- Returns:
- The parsed entity data
-
parseWithoutIndefiniteArticle
Prints errors.- Parameters:
string
-- Returns:
- The parsed entity data
-
canSpawn
public boolean canSpawn(@Nullable @Nullable org.bukkit.World world) Checks whether this entity type is allowed to spawn in the givenWorld
.Some entity types may be restricted from spawning due to experimental datapacks.
- Parameters:
world
- The world to check spawning permissions in.- Returns:
true
if the entity can be spawned in the given world, or in general if world isnull
; otherwisefalse
.
-
spawn
Spawn this entity data at a location.- Parameters:
location
- TheLocation
to spawn the entity at.- Returns:
- The Entity object that is spawned.
-
spawn
@Deprecated(since="2.8.0", forRemoval=true) @Nullable public E spawn(org.bukkit.Location location, @Nullable org.bukkit.util.Consumer<E> consumer) Deprecated, for removal: This API element is subject to removal in a future version.Spawn this entity data at a location. The consumer allows for modification to the entity before it actually gets spawned.Bukkit's own
Consumer
is deprecated. Usespawn(Location, Consumer)
- Parameters:
location
- TheLocation
to spawn the entity at.consumer
- AConsumer
to apply the entity changes to.- Returns:
- The Entity object that is spawned.
-
spawn
Spawn this entity data at a location. The consumer allows for modification to the entity before it actually gets spawned.- Parameters:
location
- TheLocation
to spawn the entity at.consumer
- AConsumer
to apply the entity changes to.- Returns:
- The Entity object that is spawned.
-
getAll
-
getAll
public static <E extends org.bukkit.entity.Entity> E[] getAll(EntityData<?>[] types, Class<E> type, org.bukkit.World @Nullable [] worlds) - Parameters:
types
-type
-worlds
- worlds or null for all- Returns:
- All entities of this type in the given worlds
-
getAll
public static <E extends org.bukkit.entity.Entity> E[] getAll(EntityData<?>[] types, Class<E> type, org.bukkit.Chunk[] chunks) -
fromClass
public static <E extends org.bukkit.entity.Entity> EntityData<? super E> fromClass(Class<E> entityClass) Creates anEntityData
that represents the given entity class.- Parameters:
entityClass
- The class of the entity (e.g.Pig.class
).- Returns:
- An
EntityData
representing the provided class.
-
fromEntity
Creates anEntityData
that represents the given entity instance.- Parameters:
entity
- The entity to represent.- Returns:
- An
EntityData
representing the provided entity.
-
toString
-
toString
-
toString
-
toString
-
isInstance
public final boolean isInstance(@Nullable @Nullable org.bukkit.entity.Entity entity) -
isSupertypeOf
Determines whether thisEntityData
is a supertype of the givenentityData
.This is used to check whether the current entity data represents a broader category than another. For example:
if a zombie is a monster: # passes: "monster" is a supertype of "zombie" if a monster is a zombie: # fails: "zombie" is not a supertype of "monster"
- Parameters:
entityData
- TheEntityData
to compare against.- Returns:
true
if this is a supertype of the given entity data, otherwisefalse
.
-
serialize
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializable
Serialises this object. Only fields contained in the returned Fields object will be written to stream.You can use return new
Fields
(this); to emulate the default behaviour.- Specified by:
serialize
in interfaceYggdrasilSerializable.YggdrasilExtendedSerializable
- Returns:
- A Fields object containing all fields that should be written to stream
- Throws:
NotSerializableException
- If this object or one of its fields is not serializable
-
deserialize
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializable
Deserializes this object. No fields have been set when this method is called, use fields.setFields
(this, yggdrasil) to set all compatible non-transient and non-static fields (and call incompatible/missing field handlers if applicable – this implies that errors will be thrown if the fields object is invalid).You can use fields.
setFields
(this); to emulate the default behaviour.- Specified by:
deserialize
in interfaceYggdrasilSerializable.YggdrasilExtendedSerializable
- Parameters:
fields
- A Fields object containing all fields read from stream- Throws:
StreamCorruptedException
- If the Fields object is invalid, i.e. was not written byYggdrasilSerializable.YggdrasilExtendedSerializable.serialize()
or Yggdrasil's default serialisation.NotSerializableException
-
deserialize
Deprecated, for removal: This API element is subject to removal in a future version. -
getSyntaxTypeName
- Specified by:
getSyntaxTypeName
in interfaceSyntaxElement
- Returns:
- A string naming the type of syntax this is. e.g. "expression", "section".
-
spawn
-
create
Creates an entity in the server but does not spawn it- Returns:
- The created entity
-
create
Creates an entity at the provided location, but does not spawn it NOTE: IfRegionAccessor.createEntity(Location, Class)
does not exist, will returnspawn(Location)
- Parameters:
location
- TheLocation
to create the entity at- Returns:
- The created entity
-
create
@Nullable protected static <E extends org.bukkit.entity.Entity> E create(org.bukkit.Location location, Class<E> type)
-