Record Class Property<Handler extends PropertyHandler<?>>
java.lang.Object
java.lang.Record
org.skriptlang.skript.lang.properties.Property<Handler>
- Type Parameters:
Handler
- the type of the handler for this property
@Experimental
public record Property<Handler extends PropertyHandler<?>>(String name, String description, String[] since, SkriptAddon provider, @NotNull Class<? extends Handler extends PropertyHandler<?>> handler)
extends Record
A property that can be applied to certain types of objects.
A property has a name, a provider (the addon that provides it), and a handler class.
The handler class is responsible for defining the concrete behavior of the property.
A pre-existing handler class may be used, such as
For example, the
The
Properties can be used in syntaxes in two ways:
1) Using
2) By implementing the property directly in a custom syntax. This is more complex, but allows for more flexibility. See
All properties should be registered with the
PropertyHandler.ExpressionPropertyHandler
or a new one may be created by
implementing PropertyHandler
. All implementations of this property on ClassInfo
s will then adhere to
the behavior defined in the handler class.
For example, the
NAME
property uses the PropertyHandler.ExpressionPropertyHandler
, which provides a standard set
of behaviors for properties that can be expressed as an expression, such as getting the value of the property and
changing it via PropertyHandler.ExpressionPropertyHandler.change(Object, Object[], Changer.ChangeMode)
.
The
CONTAINS
property uses the PropertyHandler.ContainsHandler
, which is an example of a custom handler that
provides more specialized behavior.
Properties can be used in syntaxes in two ways:
1) Using
PropertyBaseExpression
. This expression handles all the complexities of properties for any property
handler that implements PropertyHandler.ExpressionPropertyHandler
. See PropExprName
for an example.2) By implementing the property directly in a custom syntax. This is more complex, but allows for more flexibility. See
PropCondContains
for an example. The implementer is responsible for using PropertyBaseSyntax.asProperty(Property, Expression)
and PropertyBaseSyntax.getPossiblePropertyInfos(Property, Expression)
to ensure the given expression can return
valid types that have the given property, and then use PropertyMap.get(Class)
during runtime
to acquire the right handler for the given type and then apply it.
All properties should be registered with the
PropertyRegistry
before use, to ensure that no conflicts between
registered properties occur.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Property.PropertyInfo<Handler extends PropertyHandler<?>>
A pair of a property and a handler. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Property
<PropertyHandler.ExpressionPropertyHandler<?, ?>> A property for getting the amount of something.static final Property
<PropertyHandler.ContainsHandler<?, ?>> A property for checking if something contains an element.static final Property
<PropertyHandler.ExpressionPropertyHandler<?, ?>> A property for things that have a display name.static final Property
<PropertyHandler.ConditionPropertyHandler<?>> A property for checking whether something is empty.static final Property
<PropertyHandler.ExpressionPropertyHandler<?, ?>> A property for things that have a name.static final Property
<PropertyHandler.ExpressionPropertyHandler<?, ?>> A property for getting the number of something.static final Property
<PropertyHandler.ExpressionPropertyHandler<?, ?>> A property for getting the size of something.static final Property
<PropertyHandler.TypedValuePropertyHandler<?, ?>> A property for getting a specific value of something. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedescription
record component.final boolean
Indicates whether some other object is "equal to" this one.Gets a documentation-friendly ID for this property, based on its name.handler()
Returns the value of thehandler
record component.final int
hashCode()
Returns a hash code value for this object.name()
Returns the value of thename
record component.static <HandlerClass extends PropertyHandler<?>,
Handler extends HandlerClass>
@NotNull Property<Handler> of
(@NotNull String name, @NotNull String description, @NotNull String @NotNull [] since, @NotNull SkriptAddon provider, @NotNull Class<HandlerClass> handler) Creates a new property.static <HandlerClass extends PropertyHandler<?>,
Handler extends HandlerClass>
@NotNull Property<Handler> of
(@NotNull String name, @NotNull String description, @NotNull String since, @NotNull SkriptAddon provider, @NotNull Class<HandlerClass> handler) Creates a new property.provider()
Returns the value of theprovider
record component.static void
Register all Skript's default properties.String[]
since()
Returns the value of thesince
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
NAME
A property for things that have a name.- See Also:
-
DISPLAY_NAME
A property for things that have a display name.- See Also:
-
CONTAINS
A property for checking if something contains an element.- See Also:
-
AMOUNT
A property for getting the amount of something.- See Also:
-
SIZE
A property for getting the size of something.- See Also:
-
NUMBER
A property for getting the number of something. -
IS_EMPTY
A property for checking whether something is empty.- See Also:
-
TYPED_VALUE
A property for getting a specific value of something.
-
-
Constructor Details
-
Property
public Property(String name, String description, String[] since, SkriptAddon provider, @NotNull @NotNull Class<? extends Handler> handler) Creates a new property. Preferof(String, String, String, SkriptAddon, Class)
.- Parameters:
name
- the name of the propertyprovider
- the addon that provides this propertyhandler
- the handler class for this property- See Also:
-
-
Method Details
-
getDocumentationID
Gets a documentation-friendly ID for this property, based on its name. May be overridden to provide a custom ID.- Returns:
- a documentation-friendly ID for this property
-
of
@Contract("_, _, _, _, _ -> new") @NotNull public static <HandlerClass extends PropertyHandler<?>,Handler extends HandlerClass> @NotNull Property<Handler> of(@NotNull @NotNull String name, @NotNull @NotNull String description, @NotNull @NotNull String since, @NotNull @NotNull SkriptAddon provider, @NotNull @NotNull Class<HandlerClass> handler) Creates a new property.- Type Parameters:
HandlerClass
- the type of the handler classHandler
- the type of the handler- Parameters:
name
- the name of the propertydescription
- a brief description of the propertyprovider
- the addon that provides this propertyhandler
- the handler class for this property- Returns:
- a new property
-
of
@Contract("_, _, _, _, _ -> new") @NotNull public static <HandlerClass extends PropertyHandler<?>,Handler extends HandlerClass> @NotNull Property<Handler> of(@NotNull @NotNull String name, @NotNull @NotNull String description, @NotNull @NotNull String @NotNull [] since, @NotNull @NotNull SkriptAddon provider, @NotNull @NotNull Class<HandlerClass> handler) Creates a new property.- Type Parameters:
HandlerClass
- the type of the handler classHandler
- the type of the handler- Parameters:
name
- the name of the propertydescription
- a brief description of the propertysince
- the version[s] that this property was added/updated.provider
- the addon that provides this propertyhandler
- the handler class for this property- Returns:
- a new property
-
registerDefaultProperties
public static void registerDefaultProperties()Register all Skript's default properties. Should be done prior to loading classinfos. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
name
Returns the value of thename
record component.- Returns:
- the value of the
name
record component
-
description
Returns the value of thedescription
record component.- Returns:
- the value of the
description
record component
-
since
Returns the value of thesince
record component.- Returns:
- the value of the
since
record component
-
provider
Returns the value of theprovider
record component.- Returns:
- the value of the
provider
record component
-
handler
Returns the value of thehandler
record component.- Returns:
- the value of the
handler
record component
-