mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-09-02 19:02:33 +02:00
Allow context pairs to be specified in commands, fix misuse of exceptions in the permission holder class
This commit is contained in:
@@ -85,15 +85,35 @@ public interface Node extends Map.Entry<String, Boolean> {
|
||||
Optional<String> getWorld();
|
||||
|
||||
/**
|
||||
* Returns if this node is server specific
|
||||
*
|
||||
* @return true if this node is server specific
|
||||
*/
|
||||
boolean isServerSpecific();
|
||||
|
||||
/**
|
||||
* Returns if this node is server specific
|
||||
*
|
||||
* @return true if this node is server specific
|
||||
*/
|
||||
boolean isWorldSpecific();
|
||||
|
||||
/**
|
||||
* Returns if this node applies globally, and has no specific context
|
||||
*
|
||||
* @return true if this node applies globally, and has no specific context
|
||||
* @since 3.1
|
||||
*/
|
||||
boolean appliesGlobally();
|
||||
|
||||
/**
|
||||
* Returns if this node has any specific context in order to apply.
|
||||
*
|
||||
* @return true if this node has specific context
|
||||
* @since 3.1
|
||||
*/
|
||||
boolean hasSpecificContext();
|
||||
|
||||
/**
|
||||
* If this node should apply on a specific server
|
||||
*
|
||||
@@ -222,22 +242,30 @@ public interface Node extends Map.Entry<String, Boolean> {
|
||||
* Converts this node into a serialized form
|
||||
*
|
||||
* @return a serialized node string
|
||||
* @deprecated because this serialized form is no longer used by the implementation.
|
||||
*/
|
||||
@Deprecated
|
||||
String toSerializedNode();
|
||||
|
||||
/**
|
||||
* Returns if this is a group node
|
||||
*
|
||||
* @return true if this is a group node
|
||||
*/
|
||||
boolean isGroupNode();
|
||||
|
||||
/**
|
||||
* Returns the name of the group
|
||||
*
|
||||
* @return the name of the group
|
||||
* @throws IllegalStateException if this is not a group node. See {@link #isGroupNode()}
|
||||
*/
|
||||
String getGroupName();
|
||||
|
||||
/**
|
||||
* @return true is this node is a wildcard node
|
||||
* Returns if this node is a wildcard node
|
||||
*
|
||||
* @return true if this node is a wildcard node
|
||||
*/
|
||||
boolean isWildcard();
|
||||
|
||||
@@ -250,6 +278,8 @@ public interface Node extends Map.Entry<String, Boolean> {
|
||||
int getWildcardLevel();
|
||||
|
||||
/**
|
||||
* Returns if this node is a meta node
|
||||
*
|
||||
* @return true if this node is a meta node
|
||||
*/
|
||||
boolean isMeta();
|
||||
|
@@ -37,7 +37,7 @@ import java.util.Set;
|
||||
public interface ContextSet {
|
||||
|
||||
/**
|
||||
* Make a singleton ImmutableContextSet from a context pair
|
||||
* Creates an ImmutableContextSet from a context pair
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
@@ -49,7 +49,22 @@ public interface ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ImmutableContextSet from an existing map
|
||||
* Creates an ImmutableContextSet from two context pairs
|
||||
*
|
||||
* @param key1 the first key
|
||||
* @param value1 the first value
|
||||
* @param key2 the second key
|
||||
* @param value2 the second value
|
||||
* @return a new ImmutableContextSet containing the two pairs
|
||||
* @throws NullPointerException if any of the keys or values are null
|
||||
* @since 3.1
|
||||
*/
|
||||
static ImmutableContextSet of(String key1, String value1, String key2, String value2) {
|
||||
return ImmutableContextSet.of(key1, value1, key2, value2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ImmutableContextSet from an existing map
|
||||
*
|
||||
* @param map the map to copy from
|
||||
* @return a new ImmutableContextSet representing the pairs from the map
|
||||
@@ -60,7 +75,7 @@ public interface ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ImmutableContextSet from an existing iterable of Map Entries
|
||||
* Creates an ImmutableContextSet from an existing iterable of Map Entries
|
||||
*
|
||||
* @param iterable the iterable to copy from
|
||||
* @return a new ImmutableContextSet representing the pairs in the iterable
|
||||
@@ -71,7 +86,7 @@ public interface ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ImmutableContextSet from an existing multimap
|
||||
* Creates an ImmutableContextSet from an existing multimap
|
||||
*
|
||||
* @param multimap the multimap to copy from
|
||||
* @return a new ImmutableContextSet representing the pairs in the multimap
|
||||
@@ -83,7 +98,7 @@ public interface ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ImmutableContextSet from an existing set.
|
||||
* Creates an new ImmutableContextSet from an existing set.
|
||||
* Only really useful for converting between mutable and immutable types.
|
||||
*
|
||||
* @param contextSet the context set to copy from
|
||||
@@ -173,6 +188,7 @@ public interface ContextSet {
|
||||
*
|
||||
* @param key the key to find values for
|
||||
* @return an optional containing any match
|
||||
* @since 3.1
|
||||
*/
|
||||
default Optional<String> getAnyValue(String key) {
|
||||
return getValues(key).stream().findAny();
|
||||
@@ -203,6 +219,7 @@ public interface ContextSet {
|
||||
*
|
||||
* @param other the other set to check
|
||||
* @return true if all entries in this set are also in the other set
|
||||
* @since 3.1
|
||||
*/
|
||||
default boolean isSatisfiedBy(ContextSet other) {
|
||||
if (this.isEmpty()) {
|
||||
|
@@ -41,7 +41,7 @@ public final class ImmutableContextSet implements ContextSet {
|
||||
private static final ImmutableContextSet EMPTY = new ImmutableContextSet(ImmutableSetMultimap.of());
|
||||
|
||||
/**
|
||||
* Make a singleton ImmutableContextSet from a context pair
|
||||
* Creates an ImmutableContextSet from a context pair
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
@@ -60,7 +60,35 @@ public final class ImmutableContextSet implements ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ImmutableContextSet from an existing map
|
||||
* Creates an ImmutableContextSet from two context pairs
|
||||
*
|
||||
* @param key1 the first key
|
||||
* @param value1 the first value
|
||||
* @param key2 the second key
|
||||
* @param value2 the second value
|
||||
* @return a new ImmutableContextSet containing the two pairs
|
||||
* @throws NullPointerException if any of the keys or values are null
|
||||
* @since 3.1
|
||||
*/
|
||||
public static ImmutableContextSet of(String key1, String value1, String key2, String value2) {
|
||||
if (key1 == null) {
|
||||
throw new NullPointerException("key1");
|
||||
}
|
||||
if (value1 == null) {
|
||||
throw new NullPointerException("value1");
|
||||
}
|
||||
if (key2 == null) {
|
||||
throw new NullPointerException("key2");
|
||||
}
|
||||
if (value2 == null) {
|
||||
throw new NullPointerException("value2");
|
||||
}
|
||||
|
||||
return new ImmutableContextSet(ImmutableSetMultimap.of(key1.toLowerCase(), value1, key2.toLowerCase(), value2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ImmutableContextSet from an existing map
|
||||
*
|
||||
* @param map the map to copy from
|
||||
* @return a new ImmutableContextSet representing the pairs from the map
|
||||
@@ -80,7 +108,7 @@ public final class ImmutableContextSet implements ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ImmutableContextSet from an existing iterable of Map Entries
|
||||
* Creates an ImmutableContextSet from an existing iterable of Map Entries
|
||||
*
|
||||
* @param iterable the iterable to copy from
|
||||
* @return a new ImmutableContextSet representing the pairs in the iterable
|
||||
@@ -95,7 +123,7 @@ public final class ImmutableContextSet implements ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a ImmutableContextSet from an existing multimap
|
||||
* Creates an ImmutableContextSet from an existing multimap
|
||||
*
|
||||
* @param multimap the multimap to copy from
|
||||
* @return a new ImmutableContextSet representing the pairs in the multimap
|
||||
@@ -122,7 +150,7 @@ public final class ImmutableContextSet implements ContextSet {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new empty ContextSet.
|
||||
* Creates an new empty ContextSet.
|
||||
*
|
||||
* @return a new ContextSet
|
||||
*/
|
||||
|
@@ -62,6 +62,36 @@ public final class MutableContextSet implements ContextSet {
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a MutableContextSet from two context pairs
|
||||
*
|
||||
* @param key1 the first key
|
||||
* @param value1 the first value
|
||||
* @param key2 the second key
|
||||
* @param value2 the second value
|
||||
* @return a new MutableContextSet containing the two pairs
|
||||
* @throws NullPointerException if any of the keys or values are null
|
||||
* @since 3.1
|
||||
*/
|
||||
public static MutableContextSet of(String key1, String value1, String key2, String value2) {
|
||||
if (key1 == null) {
|
||||
throw new NullPointerException("key1");
|
||||
}
|
||||
if (value1 == null) {
|
||||
throw new NullPointerException("value1");
|
||||
}
|
||||
if (key2 == null) {
|
||||
throw new NullPointerException("key2");
|
||||
}
|
||||
if (value2 == null) {
|
||||
throw new NullPointerException("value2");
|
||||
}
|
||||
|
||||
MutableContextSet ret = singleton(key1, value1);
|
||||
ret.add(key2, value2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MutableContextSet from an existing map
|
||||
*
|
||||
|
Reference in New Issue
Block a user