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 PropertyHandler.ExpressionPropertyHandler or a new one may be created by implementing PropertyHandler. All implementations of this property on ClassInfos 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.
  • Field Details

  • Constructor Details

  • Method Details

    • getDocumentationID

      public String 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 class
      Handler - the type of the handler
      Parameters:
      name - the name of the property
      description - a brief description of the property
      provider - the addon that provides this property
      handler - 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 class
      Handler - the type of the handler
      Parameters:
      name - the name of the property
      description - a brief description of the property
      since - the version[s] that this property was added/updated.
      provider - the addon that provides this property
      handler - 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

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • description

      public String description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • since

      public String[] since()
      Returns the value of the since record component.
      Returns:
      the value of the since record component
    • provider

      public SkriptAddon provider()
      Returns the value of the provider record component.
      Returns:
      the value of the provider record component
    • handler

      @NotNull public @NotNull Class<? extends Handler> handler()
      Returns the value of the handler record component.
      Returns:
      the value of the handler record component