Class Patterns<T>

java.lang.Object
ch.njol.skript.util.Patterns<T>

public class Patterns<T> extends Object
A helper class useful when an expression/condition/effect/etc. needs to associate additional data with each pattern.
  • Constructor Details

    • Patterns

      public Patterns(Object[][] info)
      Creates a new Patterns with a provided Object in the form of {{String, T}, {String, T}, ...} {{pattern, correlating object}}
  • Method Details

    • getPatterns

      public String[] getPatterns()
      Returns an array of the registered patterns.
      Returns:
      An Array of Strings.
    • getInfo

      public T getInfo(int matchedPattern)
      Returns the typed object Patterns correlating to matchedPattern.
      Parameters:
      matchedPattern - The pattern to get the data to as given in SyntaxElement.init(Expression[], int, Kleenean, ParseResult)
      Returns:
      The info associated with the matched pattern
      Throws:
      ClassCastException - If the item in the source array is not of the requested type
    • getMatchedPatterns

      public Integer @Nullable [] getMatchedPatterns(@Nullable T type)
      Retrieves all pattern indices that are associated with type.

      These indices represent the positions of matched patterns registered for the provided typed object.

      Parameters:
      type - The typed object to look up.
      Returns:
      An array of matched pattern indices, or null if no patterns are registered for the given type.
    • getMatchedPattern

      public Optional<Integer> getMatchedPattern(@Nullable T type, int arrayIndex)
      Retrieves the index of a specific matched pattern for the give type, based on the provided arrayIndex.

      This method looks up all matched pattern indices for the specified type and returns the index at arrayIndex, if it exists.

      Parameters:
      type - The object whose registered patterns should be retrieved.
      arrayIndex - The position in the matched pattern array to retrieve/
      Returns:
      An Optional containing the matched pattern index at the specified position, or Optional.empty() if no patterns are registered for type or if the array does not contain enough elements.
      See Also: