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 Summary
Modifier and TypeMethodDescriptionstatic <N extends Number>
PerArenaExpression<N> constNumber(N number) Constructs a new expression class that always returns the same number.fetchValue(Arena arena) Calculates the number of an arena.Gets all existing per-arena conditions for the expressions.getExpression(ArenaCondition condition) Gets an expression or a static number value based on an expression.static <N extends Number>
PerArenaExpression<N> parseConfig(Object el, Class<N> numberType) Tries to parse the YAML config.static <N extends Number>
PerArenaExpression<N> parseConfig(ConfigurationSection section, String key, N def, @Nullable Consumer<String> errorLog) Tries to parse the YAML config.Serializes the YAML configured expressions for saving in config files.
-
Method Details
-
fetchValue
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
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 fromgetConditions()- Returns:
- The matching expression
- Throws:
NoSuchElementException- if the condition isn't a part ofgetConditions()
-
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 ConfigurationSectionnumberType- 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 inkey- The name of the key entry in the section in which our per-arena-expression config is indef- The default value if the config either doesn't exist or an error ocurrederrorLog- Gets called if an error occured (missing config won't cause a call).nullforThrowable.printStackTrace()- Returns:
- The parsed per-arena-expression
-
constNumber
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
-