2022-07-21 02:19:28 +02:00
|
|
|
package fr.pandacube.lib.players.permissible;
|
|
|
|
|
|
|
|
import java.util.OptionalLong;
|
|
|
|
import java.util.stream.LongStream;
|
|
|
|
|
2022-08-08 03:16:00 +02:00
|
|
|
import fr.pandacube.lib.permissions.PermissionExpressionParser;
|
2022-08-10 03:04:12 +02:00
|
|
|
import fr.pandacube.lib.players.standalone.AbstractOnlinePlayer;
|
2022-07-21 02:19:28 +02:00
|
|
|
|
2022-08-10 03:04:12 +02:00
|
|
|
/**
|
|
|
|
* Represents an online player, with extra methods related to the {@code pandalib-permissions} system.
|
|
|
|
*/
|
|
|
|
public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, AbstractOnlinePlayer {
|
2022-07-21 02:19:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General data and state
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2022-08-10 03:04:12 +02:00
|
|
|
* {@inheritDoc}
|
2022-07-21 02:19:28 +02:00
|
|
|
* @implSpec The implementation is expected to call the environment API
|
|
|
|
* (Bukkit/Bungee) to get the name of the player.
|
|
|
|
*/
|
|
|
|
String getName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Permissions and groups
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tells if this online player has the specified permission.
|
|
|
|
* @implSpec the implementation of this method must not directly or
|
|
|
|
* indirectly call the method {@link PermissibleOffPlayer#hasPermission(String)},
|
|
|
|
* or it may result in a {@link StackOverflowError}.
|
|
|
|
*/
|
|
|
|
boolean hasPermission(String permission);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tells if this online player has the permission resulted from the provided expression.
|
|
|
|
* @implSpec the implementation of this method must not directly or
|
|
|
|
* indirectly call the method {@link PermissibleOffPlayer#hasPermissionExpression(String)},
|
|
|
|
* or it may result in a {@link StackOverflowError}.
|
|
|
|
*/
|
2022-08-08 03:16:00 +02:00
|
|
|
default boolean hasPermissionExpression(String permissionExpression) {
|
|
|
|
return PermissionExpressionParser.evaluate(permissionExpression, this::hasPermission);
|
|
|
|
}
|
2022-07-21 02:19:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists all the values for a set of permission indicating an integer in a range.
|
|
|
|
* <p>
|
|
|
|
* A permission range is used to easily attribute a number to a group or player,
|
|
|
|
* like the maximum number of homes allowed. For instance, if the player has the permission
|
|
|
|
* {@code essentials.home.12}, this method would return a stream containing the value 12,
|
|
|
|
* if the parameter {@code permissionPrefix} is {@code "essentials.home."}.
|
|
|
|
* <p>
|
|
|
|
* The use of a stream allow the caller to get either the maximum, the minimum, or do any
|
|
|
|
* other treatment to the values.
|
|
|
|
* @param permissionPrefix the permission prefix to search for.
|
|
|
|
* @return a LongStream containing all the values found for the specified permission prefix.
|
|
|
|
*/
|
2022-08-08 03:16:00 +02:00
|
|
|
default LongStream getPermissionRangeValues(String permissionPrefix) {
|
|
|
|
String server = getServerName();
|
|
|
|
String world = server == null ? null : getWorldName();
|
|
|
|
return getPermissionUser().getPermissionRangeValues(permissionPrefix, server, world);
|
|
|
|
}
|
2022-07-21 02:19:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the maximum value returned by {@link PermissibleOffPlayer#getPermissionRangeValues(String)}.
|
|
|
|
*/
|
2022-08-08 03:16:00 +02:00
|
|
|
default OptionalLong getPermissionRangeMax(String permissionPrefix) {
|
|
|
|
String server = getServerName();
|
|
|
|
String world = server == null ? null : getWorldName();
|
|
|
|
return getPermissionUser().getPermissionRangeMax(permissionPrefix, server, world);
|
|
|
|
}
|
2022-07-21 02:19:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|