Package dev.polv.taleapi.permission
Class ContextSet
java.lang.Object
dev.polv.taleapi.permission.ContextSet
An immutable set of context key-value pairs.
ContextSet defines the conditions under which a permission applies. For example, a permission might only apply in the "nether" world or when the player is in "creative" gamemode.
Example Usage
ContextSet context = ContextSet.builder()
.add(ContextKey.WORLD, "nether")
.add(ContextKey.GAMEMODE, "creative")
.build();
// Check if context matches
if (context.matches(playerContext)) {
// Permission applies
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for creating ContextSet instances. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ContextSetAn empty context set that matches everything. -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns an unmodifiable view of all contexts.static ContextSet.Builderbuilder()Creates a new builder for constructing a ContextSet.booleancontains(ContextKey<?> key) Checks if this context set contains the specified key.<T> booleancontains(ContextKey<T> key, T value) Checks if this context set contains a specific key-value pair.boolean<T> Optional<T>get(ContextKey<T> key) Gets a context value by its key.inthashCode()booleanisEmpty()Returns whether this context set is empty.keys()Returns all context keys in this set.booleanmatches(ContextSet other) Checks if this context set matches another context set.static <T> ContextSetof(ContextKey<T> key, T value) Creates a ContextSet with a single context value.static <T1,T2> ContextSet of(ContextKey<T1> key1, T1 value1, ContextKey<T2> key2, T2 value2) Creates a ContextSet with two context values.intsize()Returns the number of context entries.toString()
-
Field Details
-
EMPTY
An empty context set that matches everything.
-
-
Method Details
-
builder
Creates a new builder for constructing a ContextSet.- Returns:
- a new Builder instance
-
of
Creates a ContextSet with a single context value.- Type Parameters:
T- the value type- Parameters:
key- the context keyvalue- the context value- Returns:
- a new ContextSet with the single context
-
of
public static <T1,T2> ContextSet of(ContextKey<T1> key1, T1 value1, ContextKey<T2> key2, T2 value2) Creates a ContextSet with two context values.- Type Parameters:
T1- the first value typeT2- the second value type- Parameters:
key1- the first context keyvalue1- the first context valuekey2- the second context keyvalue2- the second context value- Returns:
- a new ContextSet with both contexts
-
get
Gets a context value by its key.- Type Parameters:
T- the value type- Parameters:
key- the context key- Returns:
- an Optional containing the value, or empty if not present
-
contains
Checks if this context set contains the specified key.- Parameters:
key- the context key to check- Returns:
trueif the key is present
-
contains
Checks if this context set contains a specific key-value pair.- Type Parameters:
T- the value type- Parameters:
key- the context keyvalue- the expected value- Returns:
trueif the key exists with the specified value
-
matches
Checks if this context set matches another context set.A context set "matches" another if all keys in this set are present in the other set with matching values. An empty context set matches everything.
- Parameters:
other- the context set to match against (e.g., player's current context)- Returns:
trueif all contexts in this set match
-
isEmpty
public boolean isEmpty()Returns whether this context set is empty.- Returns:
trueif no contexts are defined
-
size
public int size()Returns the number of context entries.- Returns:
- the size of this context set
-
keys
Returns all context keys in this set.- Returns:
- an unmodifiable set of key names
-
asMap
Returns an unmodifiable view of all contexts.- Returns:
- the context map
-
equals
-
hashCode
public int hashCode() -
toString
-