Interface PerArenaExpression<N extends Number>

Type Parameters:
N - The number type that is represented

public interface PerArenaExpression<N extends Number>
Certain configurable number-values may utilize expressions and conditions to differ per arena.
  • Method Details

    • fetchValue

      N fetchValue(Arena arena)
      Calculates the number of an arena.

      Or in other words: This method tries to obtain the number that this expression has for this given moment.

      Do note the output may differ depending on the exact time, since an expression and conditions may contain variables that change over the lifespan of i.a. a match.

      Parameters:
      arena - The arena from which we want to obtain the value of
      Returns:
      The fetched number
    • getConditions

      Set<ArenaCondition> getConditions()
      Gets all existing per-arena conditions for the expressions.

      In case during serialization no condition has been explicitly defined, the set will only contain ArenaCondition.ALWAYS_TRUE.

      Returns:
      All the configured conditions that have a matching expression
    • getExpression

      Either<String,N> getExpression(ArenaCondition condition)
      Gets an expression or a static number value based on an expression.

      If an expression isn't complex and always returns the same number, it is precalculated and stored as Either.right().

      Parameters:
      condition - The condition from getConditions()
      Returns:
      The matching expression
      Throws:
      NoSuchElementException - if the condition isn't a part of getConditions()
    • serializeConfig

      Object serializeConfig()
      Serializes the YAML configured expressions for saving in config files.

      Returns the value that you may use for ConfigurationSection.set(String, Object). Returned object is either a String, Number, or a ConfigurationSection.

      Returns:
      The serialized config that can be later used for deserialization
    • parseConfig

      static <N extends Number> PerArenaExpression<N> parseConfig(Object el, Class<N> numberType) throws IllegalArgumentException
      Tries to parse the YAML config.
      Type Parameters:
      N - The number-type the expression shall output
      Parameters:
      el - The yaml object. Must be either a String, Number, or a ConfigurationSection
      numberType - The class of the generic N
      Returns:
      The parsed per-arena-expression
      Throws:
      IllegalArgumentException - If an error occurred during parsing (invalid types, broken arena conditions ...)
    • parseConfig

      static <N extends Number> PerArenaExpression<N> parseConfig(ConfigurationSection section, String key, N def, @Nullable @Nullable Consumer<String> errorLog)
      Tries to parse the YAML config.
      Type Parameters:
      N - The number-type the expression shall output
      Parameters:
      section - The parent-section in which our per-arena-expression config is in
      key - The name of the key entry in the section in which our per-arena-expression config is in
      def - The default value if the config either doesn't exist or an error ocurred
      errorLog - Gets called if an error occured (missing config won't cause a call). null for Throwable.printStackTrace()
      Returns:
      The parsed per-arena-expression
    • constNumber

      static <N extends Number> PerArenaExpression<N> constNumber(N number)
      Constructs a new expression class that always returns the same number.
      Type Parameters:
      N - The type of the number
      Parameters:
      number - The number it shall output
      Returns:
      The constructed instance