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)Create a new context value based on this definition.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.booleanmatches(V ownVal, V testVal)Get whether two values match.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)
Create a new context value based on this definition.- Parameters:
value- the value to associate with this definition- Returns:
- a new context value holder
- Since:
- 2.0.0
-
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
- Since:
- 2.0.0
-
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 - Since:
- 2.0.0
-
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.- Parameters:
ctx- a defined contextactiveValue- a value to test for membership inctx- Returns:
- whether a match was found
- Since:
- 2.0.0
-
matches
public boolean matches(V ownVal, V testVal)
Get whether two values match.- Parameters:
ownVal- the defined valuetestVal- the value being tested against- Returns:
- whether
testValis an element ofownVal
-
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- Since:
- 2.0.0
-
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.- Parameters:
subject- a subject to query for environment information- Returns:
- a set of possible values
- Since:
- 2.0.0
-
-