Class ContextDefinition<V>
- java.lang.Object
-
- ca.stellardrift.permissionsex.context.ContextDefinition<V>
-
- Direct Known Subclasses:
EnumContextDefinition,SimpleContextDefinition
public abstract class ContextDefinition<V> extends Object
A specific type of context, for exampleworld,server-tag, oruntil.- Since:
- 2.0.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedContextDefinition(String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaccumulateCurrentValues(CalculatedSubject subject, Consumer<V> consumer)Given a player, calculate active context typesContextValue<V>createValue(V value)abstract @Nullable Vdeserialize(String userValue)Given a string (which may be in user format), return a parsed object.booleanequals(@Nullable Object other)inthashCode()booleanmatches(ContextValue<V> ctx, V activeValue)Given a defined context and the active value (provided byaccumulateCurrentValues(CalculatedSubject, Consumer)), return whether the active value matches the defined value.abstract booleanmatches(V ownVal, V testVal)Stringname()Gets the name for this context definition.abstract Stringserialize(V canonicalValue)Given a parsed value, write data out as a string.Set<V>suggestValues(CalculatedSubject subject)Given a subject, suggest a set of values that may be valid for this context.StringtoString()
-
-
-
Constructor Detail
-
ContextDefinition
protected ContextDefinition(String name)
-
-
Method Detail
-
createValue
public final ContextValue<V> createValue(V value)
-
name
public final String name()
Gets the name for this context definition.- Returns:
- the definition name
- Since:
- 2.0.0
-
serialize
public abstract String serialize(V canonicalValue)
Given a parsed value, write data out as a string.- Parameters:
canonicalValue- Parsed value- Returns:
- serialized form of the value
-
deserialize
public abstract @Nullable V deserialize(String userValue)
Given a string (which may be in user format), return a parsed object.- Parameters:
userValue- the value as a string, such as when provided by user input- Returns:
- V a deserialized value, or
null if unsuccessful
-
matches
public final boolean matches(ContextValue<V> ctx, V activeValue)
Given a defined context and the active value (provided byaccumulateCurrentValues(CalculatedSubject, Consumer)), return whether the active value matches the defined value.
-
accumulateCurrentValues
public abstract void accumulateCurrentValues(CalculatedSubject subject, Consumer<V> consumer)
Given a player, calculate active context types- Parameters:
subject- The subject active contexts are being calculated forconsumer- A function that will take the returned value and add it to the active context set
-
suggestValues
public Set<V> suggestValues(CalculatedSubject subject)
Given a subject, suggest a set of values that may be valid for this context. This need not be an exhaustive list, or could even be an empty list, but allows providing users possible suggestions to what sensible values for a context may be.
-
-