Class EntityData<E extends org.bukkit.entity.Entity>
- Type Parameters:
E- The type ofEntity.
- All Implemented Interfaces:
SyntaxElement, YggdrasilSerializable, YggdrasilSerializable.YggdrasilExtendedSerializable
- Direct Known Subclasses:
AxolotlData, BeeData, CatData, ChickenData, ColorableEntityData, CowData, CreeperData, DisplayData, DroppedItemData, EndermanData, FallingBlockData, FoxData, FrogData, GoatData, LlamaData, MinecartData, MooshroomData, NautilusData, PandaData, ParrotData, PigData, RabbitData, SalmonData, SheepData, SimpleEntityData, StriderData, ThrownPotionData, TropicalFishData, VillagerData, WolfData, XpOrbData, ZombieNautilusData, ZombieVillagerData
Entity for comparison, changing data, matching data, and spawning with initial data.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCollection ofEntityData.PatternGroups to be parsed and retrieved.static final recordGrouping of data for an entity that is to be parsed and retrieved.Nested classes/interfaces inherited from interface YggdrasilSerializable
YggdrasilSerializable.YggdrasilExtendedSerializable, YggdrasilSerializable.YggdrasilRobustEnum, YggdrasilSerializable.YggdrasilRobustSerializable -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GeneralNounstatic final GeneralNounstatic final Stringprotected intReferences the corresponding group in the order they're registered.Fields inherited from class EntityData
LANGUAGE_NODE, serializer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanSpawn(@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>
Eprotected <T> booleandataMatch(T from, T to) Checks iffromisnullor is equal toto.voiddeserialize(Fields fields) Deserializes this object.final booleanprotected abstract booleanequals_i(EntityData<?> entityData) Internal helper forequals(Object)to compare the specific data of thisEntityDatawith another.static <E extends org.bukkit.entity.Entity>
EntityData<? super E> Creates anEntityDatathat represents the given entity class.static <E extends org.bukkit.entity.Entity>
EntityData<? super E> fromEntity(E entity) Creates anEntityDatathat represents the given entity instance.protected @Nullable GeneralNounE[]getAll(org.bukkit.World... worlds) static <E extends org.bukkit.entity.Entity>
E[]getAll(EntityData<?>[] types, Class<E> type, org.bukkit.Chunk[] chunks) Gets all entities that match any of the providedtypesand is a subclass oftype, within the providedchunks.static <E extends org.bukkit.entity.Entity>
E[]getAll(EntityData<?>[] types, Class<E> type, org.bukkit.World @Nullable [] worlds) Gets all entities that match any of the providedtypesand is a subclass oftype.static EntityDataInfo<?, ?> getInfo(Class<? extends EntityData<?>> entityDataClass) Retrieves theEntityDataInforegistered for the givenentityDataClass.static @Nullable EntityDataInfo<?, ?> Retrieves theEntityDataInfoassociated with the givencodeName.protected GeneralNoungetName()abstract @NotNull EntityData<?> Returns a more general version of thisEntityDatawith specific data removed.@NotNull StringgetType()final inthashCode()protected abstract intInternal method used byhashCode()to include subclass-specific fields in the hash calculation for thisEntityData.protected static <Data extends EntityData<E>, E extends org.bukkit.entity.Entity>
EntityDataInfo.Builder<? extends EntityDataInfo.Builder<?, Data, E>, Data, E> infoBuilder(Class<Data> dataClass, String dataName) Helper method for getting a newly constructedEntityDataInfo.Builder.final booleaninit(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) Performs initial setup for thisEntityDatabefore passing control to the more specificinit(Expression[], int, Kleenean, ParseResult).protected abstract booleaninit(Literal<?>[] exprs, int matchedGroup, int matchedPattern, SkriptParser.ParseResult parseResult) Initializes thisEntityData.protected abstract booleanInitializes thisEntityDatafrom either an entity class or a specificEntity.isBaby()final booleanisInstance(@Nullable org.bukkit.entity.Entity entity) Whether the providedentityis an instance of the entity class and matches,isPlural()static booleanisRegistered(Class<? extends org.bukkit.entity.Entity> entityClass) Whether theentityClassis already registered.booleanisSupertypeOf(EntityData<?> entityData) Deprecated, for removal: This API element is subject to removal in a future version.abstract booleanisSupertypeOf(EntityData<?> entityData) Determines whether thisEntityDatais a supertype of the givenentityData.protected booleankleeneanMatch(Kleenean from, boolean to) protected booleankleeneanMatch(Kleenean from, Kleenean to) protected abstract booleanDetermines whether the givenEntitymatches thisEntityDatadata.static voidstatic @Nullable EntityData<?> Prints errors.static @Nullable EntityData<?> parseWithoutIndefiniteArticle(String string) Parses the providedstringto anEntityData.protected static <Data extends EntityData<E>, E extends org.bukkit.entity.Entity>
voidregisterInfo(EntityDataInfo<Data, E> info) Register aEntityDataInfo.Serialises this object.abstract voidApplies thisEntityDatato a newly spawnedEntity.final Espawn(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.final StringtoString()toString(int flags) Gets the string representation of thisEntityData.static StringGets the string representation from theEntityDatathat handles theentityclass.static StringGets the string representation from theEntityDatathat handles theentityclass.static StringtoString(org.bukkit.entity.Entity entity) Gets the string representation from theEntityDatathat handles the type ofentity.static StringtoString(org.bukkit.entity.Entity entity, int flags) Gets the string representation from theEntityDatathat handles the type ofentity.Methods inherited from class EntityData
getAll, getAllMethods inherited from interface SyntaxElement
getParser, preInit
-
Field Details
-
AGE_PATTERN
- See Also:
-
AGE_BABY
-
AGE_ADULT
-
groupIndex
protected int groupIndexReferences the corresponding group in the order they're registered.
-
-
Constructor Details
-
EntityData
public EntityData()
-
-
Method Details
-
onRegistrationStop
@Internal public static void onRegistrationStop() -
isRegistered
Whether theentityClassis already registered.- Parameters:
entityClass- The entity class to check.- Returns:
trueif registered, otherwisefalse.
-
getInfo
Retrieves theEntityDataInforegistered for the givenentityDataClass.- Parameters:
entityDataClass- TheEntityDataclass to look up.- Returns:
- The corresponding
EntityDataInfoinstance. - Throws:
SkriptAPIException- if the class has not been registered.
-
getInfo
Retrieves theEntityDataInfoassociated with the givencodeName.- Parameters:
dataName- The code name used to register the entity data.- Returns:
- The corresponding
EntityDataInfo, ornullif not found.
-
parse
Prints errors.- Parameters:
string- String with optional indefinite article at the beginning- Returns:
- The parsed entity data
-
parseWithoutIndefiniteArticle
Parses the providedstringto anEntityData. Using this method implies thatstringdoes not contain an indefinite article.- Parameters:
string- The pattern to parse.- Returns:
- The parsed entity data.
-
getAll
public static <E extends org.bukkit.entity.Entity> E[] getAll(EntityData<?>[] types, Class<E> type, org.bukkit.World @Nullable [] worlds) Gets all entities that match any of the providedtypesand is a subclass oftype. Providingworldsonly gets entities in those worlds, otherwise gets entities in all worlds.- Parameters:
types- The types of entities to retrieve.type- The super type of the entities wanting to retrieve.worlds- The worlds to get from, or null for all worlds.- 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) Gets all entities that match any of the providedtypesand is a subclass oftype, within the providedchunks.- Parameters:
types- The types of entities to retrieve.type- The super type of the entities wanting to retrieve.chunks- The chunks to get from.- Returns:
- All entities of this type in the given chunks.
-
fromClass
public static <E extends org.bukkit.entity.Entity> EntityData<? super E> fromClass(Class<E> entityClass) Creates anEntityDatathat represents the given entity class.- Parameters:
entityClass- The class of the entity (e.g.Pig.class).- Returns:
- An
EntityDatarepresenting the provided class.
-
fromEntity
Creates anEntityDatathat represents the given entity instance.- Parameters:
entity- The entity to represent.- Returns:
- An
EntityDatarepresenting the provided entity.
-
toString
Gets the string representation from theEntityDatathat handles the type ofentity.- Parameters:
entity- TheEntityto get the string representation of.- Returns:
- The string representation.
-
toString
Gets the string representation from theEntityDatathat handles theentityclass.- Parameters:
entityClass- TheEntityclass to get the string representation of.- Returns:
- The string representation.
-
toString
Gets the string representation from theEntityDatathat handles the type ofentity.- Parameters:
entity- TheEntityto get the string representation of.flags- The flag to determine singular or plural.- Returns:
- The string representation.
-
toString
Gets the string representation from theEntityDatathat handles theentityclass.- Parameters:
entityClass- TheEntityclass to get the string representation of.flags- The flag to determine singular or plural.- Returns:
- The string representation.
-
infoBuilder
protected static <Data extends EntityData<E>, E extends org.bukkit.entity.Entity> EntityDataInfo.Builder<? extends EntityDataInfo.Builder<?,Data, infoBuilderE>, Data, E> (Class<Data> dataClass, String dataName) Helper method for getting a newly constructedEntityDataInfo.Builder.- Type Parameters:
Data- The entity data class being used.E- The entity classDatais assigned to.- Parameters:
dataClass- The class extendingEntityData.dataName- The namedataClasswill be identified as.- Returns:
- The constructed
EntityDataInfo.Builder.
-
registerInfo
protected static <Data extends EntityData<E>, E extends org.bukkit.entity.Entity> void registerInfo(EntityDataInfo<Data, E> info) Register aEntityDataInfo.- Type Parameters:
Data- The entity data class being used.E- The entity classDatais assigned to.- Parameters:
info- TheEntityDataInfoto register.
-
init
public final boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) Performs initial setup for thisEntityDatabefore 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:
initin 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 matchedGroup, int matchedPattern, SkriptParser.ParseResult parseResult) Initializes thisEntityData.As of Skript 2.13, code names can have multiple patterns.
matchedGroupwill be the index of the code name the matched pattern is linked to. (e.g.PigData"unsaddled pig" = 0, "pig" = 1, "saddled pig" = 2)matchedPatternwill be the index of the pattern used from the patterns of the group.- Parameters:
exprs- An array ofLiteralexpressions 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.matchedGroup- The index of the group which matched.matchedPattern- The index of the pattern of the group which matched.parseResult- Additional information from the parser.- Returns:
trueif initialization was successful, otherwisefalse.
-
init
protected abstract boolean init(@Nullable @Nullable Class<? extends E> entityClass, @Nullable E entity) Initializes thisEntityDatafrom 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:
trueif initialization was successful, otherwisefalse.
-
set
Applies thisEntityDatato a newly spawnedEntity.This is used during entity spawning to set additional data, such as a saddled pig.
- Specified by:
setin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
entity- The spawned entity.
-
match
Determines whether the givenEntitymatches thisEntityDatadata.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- TheEntityto match.- Returns:
trueif the entity matches, otherwisefalse.
-
getType
- Specified by:
getTypein classEntityData<E extends org.bukkit.entity.Entity>- Returns:
- The entity's
Class, such asPig.class.
-
getSuperType
Returns a more general version of thisEntityDatawith specific data removed.For example, calling this on
"a saddled pig"should return"a pig". This is typically used to obtain the base entity type without any modifiers or traits.- Specified by:
getSuperTypein classEntityData<E extends org.bukkit.entity.Entity>- Returns:
- A generalized
EntityDatarepresenting the base entity type.
-
toString
- Specified by:
toStringin classEntityData<E extends org.bukkit.entity.Entity>
-
getName
- Returns:
- The name registered for this
EntityData.
-
getAgeNoun
- Returns:
- The age this
EntityDatarepresents.
-
toString
Gets the string representation of thisEntityData.- Specified by:
toStringin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
flags- The flag to determine singular or plural.- Returns:
- The string representation.
-
isPlural
- Specified by:
isPluralin classEntityData<E extends org.bukkit.entity.Entity>- Returns:
Kleeneandetermining whether thisEntityDatais representing plurality.
-
isBaby
- Specified by:
isBabyin classEntityData<E extends org.bukkit.entity.Entity>- Returns:
Kleeneandetermining whether thisEntityDatais 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()- Specified by:
hashCodein classEntityData<E extends org.bukkit.entity.Entity>
-
equals_i
Internal helper forequals(Object)to compare the specific data of thisEntityDatawith another.- Parameters:
entityData- TheEntityDatato compare with.- Returns:
trueif the data is considered equal, otherwisefalse.
-
equals
- Specified by:
equalsin classEntityData<E extends org.bukkit.entity.Entity>
-
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.
- Specified by:
canSpawnin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
world- The world to check spawning permissions in.- Returns:
trueif the entity can be spawned in the given world, or in general if world isnull; otherwisefalse.
-
spawn
Spawn this entity data at a location.- Specified by:
spawnin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
location- TheLocationto spawn the entity at.- 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.- Specified by:
spawnin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
location- TheLocationto spawn the entity at.consumer- AConsumerto apply the entity changes to.- Returns:
- The Entity object that is spawned.
-
getAll
- Specified by:
getAllin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
worlds- TheWorlds to get entities from.- Returns:
- The entities found.
-
isInstance
public final boolean isInstance(@Nullable @Nullable org.bukkit.entity.Entity entity) Whether the providedentityis an instance of the entity class and matches,- Specified by:
isInstancein classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
entity- The entity to check.- Returns:
trueif instance and matches, otherwisefalse.
-
isSupertypeOf
Determines whether thisEntityDatais 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- TheEntityDatato compare against.- Returns:
trueif this is a supertype of the given entity data, otherwisefalse.
-
isSupertypeOf
@Internal @Deprecated(forRemoval=true, since="2.17") public boolean isSupertypeOf(EntityData<?> entityData) Deprecated, for removal: This API element is subject to removal in a future version.Description copied from class:EntityDataDetermines whether thisEntityDatais 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"- Specified by:
isSupertypeOfin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
entityData- TheEntityDatato compare against.- Returns:
trueif this is a supertype of the given entity data, otherwisefalse.
-
serialize
Description copied from interface:YggdrasilSerializable.YggdrasilExtendedSerializableSerialises 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:
serializein interfaceYggdrasilSerializable.YggdrasilExtendedSerializable- Specified by:
serializein classEntityData<E extends org.bukkit.entity.Entity>- 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.YggdrasilExtendedSerializableDeserializes 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:
deserializein interfaceYggdrasilSerializable.YggdrasilExtendedSerializable- Specified by:
deserializein classEntityData<E extends org.bukkit.entity.Entity>- 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
-
getSyntaxTypeName
- Specified by:
getSyntaxTypeNamein interfaceSyntaxElement- Specified by:
getSyntaxTypeNamein classEntityData<E extends org.bukkit.entity.Entity>- 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- Specified by:
createin classEntityData<E extends org.bukkit.entity.Entity>- 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)- Specified by:
createin classEntityData<E extends org.bukkit.entity.Entity>- Parameters:
location- TheLocationto 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) -
kleeneanMatch
- Parameters:
from- TheKleeneanto compare to.to- Theto compare against.invalid reference
boolean- Returns:
trueiffromisKleenean.UNKNOWNor is equal toto, otherwisefalse.
-
kleeneanMatch
- Parameters:
from- TheKleeneanto compare to.to- TheKleeneanto compare against.- Returns:
trueiffromisKleenean.UNKNOWNor is equal toto, otherwisefalse.
-
dataMatch
protected <T> boolean dataMatch(@Nullable T from, T to) Checks iffromisnullor is equal toto.- Parameters:
from- The object to compare to.to- The object to compare against.- Returns:
trueiffromisnullor is equal toto, otherwisefalse.
-