Uniformization of how permission check is handled between pandalib-(.*-)players, Paper/Bungee and pandalib-permissions.

When an *OnlinePlayer class ask for permission, it always ask for Paper/Bungee API. The pandalib-permissions system will be called by Paper/Bungee only if it used and integrated into Paper/Bungee using the appropriate modules.
This commit reduces inter-dependencies between pandalib-(.*-)permissions modules and pandalib-(.*-)players (except pandalib-players-permissible that has to depends on pandalib-permissions)
This commit is contained in:
Marc Baloup 2022-08-08 03:16:00 +02:00
parent a885c224a6
commit f976350ee1
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
14 changed files with 95 additions and 40 deletions

View File

@ -9,22 +9,24 @@ that are detailed in their respective Readme file (if any).
- `pandalib-util` General purpose utility and helper classes; - `pandalib-util` General purpose utility and helper classes;
- `pandalib-chat` A chat API working on top of the Adventure API; - `pandalib-chat` A chat API working on top of the Adventure API;
- `pandalib-db` An ORM working with a MySQL server through JDBC; - `pandalib-db` An ORM working with a MySQL server through JDBC;
- `pandalib-permissions` A general purpose permission system;
- `pandalib-reflect` A reflection wrapper to make reflective operation easier;
- `pandalib-netapi` A poorly designed, but working TCP network library;
- `pandalib-net` A better-designed, packet-based TCP network library (still in development);
- `pandalib-players-standalone` A library to handle classes representing online or offline player;
- `pandalib-players-permissible` An extension of `pandalib-players-standalone` with support for the permission system `pandalib-permissions`;
- `pandalib-commands` A command manager working on top of [Brigadier](https://github.com/Mojang/brigadier);
- `pandalib-core` A catch-all module for some helper classes that didnt have their own module yet;
- `pandalib-bungee` Utility and helper classes to use in Bungeecord plugins; - `pandalib-bungee` Utility and helper classes to use in Bungeecord plugins;
- `pandalib-bungee-permissions` Integration of the permission system `pandalib-permissions` into Bungeecord;
- `pandalib-bungee-players` A partial extension and implementation of `pandalib-players-standalone` for Bungeecord plugin;
- `pandalib-paper` Utility and helper classes to use in Spigot/Paper plugins; - `pandalib-paper` Utility and helper classes to use in Spigot/Paper plugins;
- `pandalib-reflect` A reflection wrapper to make reflective operation easier;
- `pandalib-paper-reflect` A reflection API to ease access to NMS and OBS stuff in Paper server; - `pandalib-paper-reflect` A reflection API to ease access to NMS and OBS stuff in Paper server;
- `pandalib-paper-permissions` Integration of the permission system `pandalib-permissions` into Bukkit/Spigot/Paper permission system; - `pandalib-permissions` A general purpose permission system;
- `pandalib-paper-players` A partial extension and implementation of `pandalib-players-standalone` for Paper plugin; - `pandalib-bungee-permissions` Integration of the permission system `pandalib-permissions` into Bungeecord;
- `pandalib-cli` Utility and helper classes for a standalone Java application. - `pandalib-paper-permissions` Integration of the permission system `pandalib-permissions` into Bukkit, Vault and WEPIF permission systems;
- `pandalib-players` A library to handle classes representing online or offline players;
- `pandalib-players-permissible` An extension of `pandalib-players` with support for the permission system `pandalib-permissions`;
- `pandalib-bungee-players` A partial extension and implementation of `pandalib-players` for Bungeecord plugin;
- `pandalib-paper-players` A partial extension and implementation of `pandalib-players` for Paper plugin;
- `pandalib-netapi` A poorly designed, but working TCP network library;
- `pandalib-net` A better-designed, packet-based TCP network library (_still in development_);
- `pandalib-commands` An abstract command manager working on top of [Brigadier](https://github.com/Mojang/brigadier);
- `pandalib-bungee-commands` Integrates Brigadier commands into Bungeecord, extending `pandalib-commands`;
- `pandalib-paper-commands` Integrates Brigadier commands into the Paper server, extending `pandalib-commands`;
- `pandalib-cli` Utility and helper classes for a standalone CLI Java application.
- `pandalib-core` A catch-all module for some helper classes that didnt have their own module yet;
### Use in your projects ### Use in your projects
@ -45,11 +47,10 @@ Then, add any module you need in your `<dependencies>` section:
<dependency> <dependency>
<groupId>fr.pandacube.pandalib</groupId> <groupId>fr.pandacube.pandalib</groupId>
<artifactId>pandalib-util</artifactId> <!-- Put here the name of the module you want --> <artifactId>pandalib-util</artifactId> <!-- Put here the name of the module you want -->
<version>master-SNAPSHOT</version> <!-- last version on master branch --> <version>master-SNAPSHOT</version> <!-- last version of master branch -->
</dependency> </dependency>
</dependencies> </dependencies>
``` ```
You can use the version as provided in the code above, but if you want a stable version, check those available in the You can use the version as provided in the code above, but if you want a stable version, check those available in the
[tag section](https://github.com/PandacubeFr/PandaLib/tags). Dont forget to take a look at the modules readme file, [tag section](https://github.com/PandacubeFr/PandaLib/tags).
for any details you may need related to that specific module.

View File

@ -23,8 +23,9 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>fr.pandacube.lib</groupId> <groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-players-permissible</artifactId> <artifactId>pandalib-players</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.pandacube.lib</groupId> <groupId>fr.pandacube.lib</groupId>

View File

@ -1,5 +1,8 @@
package fr.pandacube.lib.bungee.permissions; package fr.pandacube.lib.bungee.permissions;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.players.standalone.StandaloneOnlinePlayer;
import fr.pandacube.lib.players.standalone.StandalonePlayerManager;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -9,10 +12,6 @@ import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import fr.pandacube.lib.permissions.Permissions;
import fr.pandacube.lib.players.permissible.PermissibleOnlinePlayer;
import fr.pandacube.lib.players.permissible.PermissiblePlayerManager;
public class PandalibBungeePermissions implements Listener { public class PandalibBungeePermissions implements Listener {
public static void init(Plugin bungeePlugin) { public static void init(Plugin bungeePlugin) {
@ -35,13 +34,14 @@ public class PandalibBungeePermissions implements Listener {
private volatile boolean tryPermPlayerManager = true; private volatile boolean tryPermPlayerManager = true;
private boolean hasPerm(ProxiedPlayer p, String permission) { private boolean hasPerm(ProxiedPlayer p, String permission) {
String world = null;
if (tryPermPlayerManager) { if (tryPermPlayerManager) {
try { try {
PermissiblePlayerManager<?, ?> pm = PermissiblePlayerManager.getInstance(); StandalonePlayerManager<?, ?> pm = StandalonePlayerManager.getInstance();
if (pm != null) { if (pm != null) {
PermissibleOnlinePlayer op = pm.get(p.getUniqueId()); StandaloneOnlinePlayer op = pm.get(p.getUniqueId());
if (op != null) { if (op != null) {
return op.hasPermission(permission); world = op.getWorldName();
} }
} }
} catch (NoClassDefFoundError ignored) { } catch (NoClassDefFoundError ignored) {
@ -52,6 +52,6 @@ public class PandalibBungeePermissions implements Listener {
// if not using player manager, fallback to directly call permissions API // if not using player manager, fallback to directly call permissions API
Server sv = p.getServer(); Server sv = p.getServer();
String server = sv == null ? null : sv.getInfo().getName(); String server = sv == null ? null : sv.getInfo().getName();
return Permissions.getPlayer(p.getUniqueId()).hasPermissionOr(permission, server, null, false); return Permissions.getPlayer(p.getUniqueId()).hasPermissionOr(permission, server, world, false);
} }
} }

View File

@ -28,7 +28,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.pandacube.lib</groupId> <groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-players-standalone</artifactId> <artifactId>pandalib-players</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -63,6 +63,21 @@ public interface BungeeOnlinePlayer extends BungeeOffPlayer, StandaloneOnlinePla
/*
* Permissions and groups
*/
/**
* Tells if this online player has the specified permission.
*/
default boolean hasPermission(String permission) {
return getBungeeProxiedPlayer().hasPermission(permission);
}
/* /*
* Sending packet and stuff to player * Sending packet and stuff to player

View File

@ -23,7 +23,7 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>fr.pandacube.lib</groupId> <groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-players-standalone</artifactId> <artifactId>pandalib-players</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>

View File

@ -61,6 +61,21 @@ public interface PaperOnlinePlayer extends PaperOffPlayer, StandaloneOnlinePlaye
/*
* Permissions and groups
*/
/**
* Tells if this online player has the specified permission.
*/
default boolean hasPermission(String permission) {
return getBukkitPlayer().hasPermission(permission);
}
/* /*
* Sending packet and stuff to player * Sending packet and stuff to player
*/ */

View File

@ -23,7 +23,7 @@
<dependency> <dependency>
<groupId>fr.pandacube.lib</groupId> <groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-players-standalone</artifactId> <artifactId>pandalib-players</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>

View File

@ -3,6 +3,7 @@ package fr.pandacube.lib.players.permissible;
import java.util.OptionalLong; import java.util.OptionalLong;
import java.util.stream.LongStream; import java.util.stream.LongStream;
import fr.pandacube.lib.permissions.PermissionExpressionParser;
import fr.pandacube.lib.players.standalone.StandaloneOnlinePlayer; import fr.pandacube.lib.players.standalone.StandaloneOnlinePlayer;
public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, StandaloneOnlinePlayer { public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, StandaloneOnlinePlayer {
@ -45,7 +46,9 @@ public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, Standalon
* indirectly call the method {@link PermissibleOffPlayer#hasPermissionExpression(String)}, * indirectly call the method {@link PermissibleOffPlayer#hasPermissionExpression(String)},
* or it may result in a {@link StackOverflowError}. * or it may result in a {@link StackOverflowError}.
*/ */
boolean hasPermissionExpression(String permission); default boolean hasPermissionExpression(String permissionExpression) {
return PermissionExpressionParser.evaluate(permissionExpression, this::hasPermission);
}
/** /**
* Lists all the values for a set of permission indicating an integer in a range. * Lists all the values for a set of permission indicating an integer in a range.
@ -60,12 +63,20 @@ public interface PermissibleOnlinePlayer extends PermissibleOffPlayer, Standalon
* @param permissionPrefix the permission prefix to search for. * @param permissionPrefix the permission prefix to search for.
* @return a LongStream containing all the values found for the specified permission prefix. * @return a LongStream containing all the values found for the specified permission prefix.
*/ */
LongStream getPermissionRangeValues(String permissionPrefix); default LongStream getPermissionRangeValues(String permissionPrefix) {
String server = getServerName();
String world = server == null ? null : getWorldName();
return getPermissionUser().getPermissionRangeValues(permissionPrefix, server, world);
}
/** /**
* Returns the maximum value returned by {@link PermissibleOffPlayer#getPermissionRangeValues(String)}. * Returns the maximum value returned by {@link PermissibleOffPlayer#getPermissionRangeValues(String)}.
*/ */
OptionalLong getPermissionRangeMax(String permissionPrefix); default OptionalLong getPermissionRangeMax(String permissionPrefix) {
String server = getServerName();
String world = server == null ? null : getWorldName();
return getPermissionUser().getPermissionRangeMax(permissionPrefix, server, world);
}

View File

@ -10,7 +10,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>pandalib-players-standalone</artifactId> <artifactId>pandalib-players</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>

View File

@ -1,14 +1,13 @@
package fr.pandacube.lib.players.standalone; package fr.pandacube.lib.players.standalone;
import java.util.Locale; import fr.pandacube.lib.chat.ChatStatic;
import java.util.UUID;
import net.kyori.adventure.identity.Identified; import net.kyori.adventure.identity.Identified;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.text.ComponentLike;
import fr.pandacube.lib.chat.ChatStatic; import java.util.Locale;
import java.util.UUID;
public interface StandaloneOnlinePlayer extends StandaloneOffPlayer { public interface StandaloneOnlinePlayer extends StandaloneOffPlayer {
@ -28,14 +27,27 @@ public interface StandaloneOnlinePlayer extends StandaloneOffPlayer {
String getServerName(); String getServerName();
String getWorldName(); String getWorldName();
/*
* Permissions and groups
*/
/**
* Tells if this online player has the specified permission.
* @implSpec Implementation of this method should call the permission system of their environment (paper/bungee),
* so this method will work independently of the usage of the 'pandalib-permissions' module.
*/
boolean hasPermission(String permission);

View File

@ -78,8 +78,8 @@
<module>pandalib-paper-players</module> <module>pandalib-paper-players</module>
<module>pandalib-paper-reflect</module> <module>pandalib-paper-reflect</module>
<module>pandalib-permissions</module> <module>pandalib-permissions</module>
<module>pandalib-players</module>
<module>pandalib-players-permissible</module> <module>pandalib-players-permissible</module>
<module>pandalib-players-standalone</module>
<module>pandalib-reflect</module> <module>pandalib-reflect</module>
<module>pandalib-util</module> <module>pandalib-util</module>
</modules> </modules>