From d5c9876734b70a1c3a4257d24deb0818e56402fd Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 16 Apr 2023 23:49:41 +0200 Subject: [PATCH] Plugins using Vault to interact with Pandalib permission system can now add and remove permission to specific players on server and world + added warning messages when plugin tries to manipulate player's groups and group's permissions --- .../permissions/PermissionsInjectorVault.java | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/pandalib-paper-permissions/src/main/java/fr/pandacube/lib/paper/permissions/PermissionsInjectorVault.java b/pandalib-paper-permissions/src/main/java/fr/pandacube/lib/paper/permissions/PermissionsInjectorVault.java index acded4e..8fa1adb 100644 --- a/pandalib-paper-permissions/src/main/java/fr/pandacube/lib/paper/permissions/PermissionsInjectorVault.java +++ b/pandalib-paper-permissions/src/main/java/fr/pandacube/lib/paper/permissions/PermissionsInjectorVault.java @@ -1,14 +1,13 @@ package fr.pandacube.lib.paper.permissions; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.plugin.ServicePriority; - import fr.pandacube.lib.permissions.PermGroup; import fr.pandacube.lib.permissions.Permissions; import fr.pandacube.lib.util.Log; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.plugin.ServicePriority; + +import java.util.List; /* package */ class PermissionsInjectorVault { @@ -73,13 +72,29 @@ import fr.pandacube.lib.util.Log; @Deprecated @Override public boolean playerAdd(String world, String player, String permission) { - return false; + return playerAdd(world, Bukkit.getOfflinePlayer(player), permission); + } + + @Override + public boolean playerAdd(String world, OfflinePlayer player, String permission) { + String server = PandalibPaperPermissions.serverName; + Permissions.getPlayer(player.getUniqueId()).addSelfPermission(permission, server, world); + Log.info("A plugin added permission " + permission + " (server=" + server + ",world=" + world + ") to player " + player.getName() + " through Vault."); + return true; } @Deprecated @Override public boolean playerRemove(String world, String player, String permission) { - return false; + return playerRemove(world, Bukkit.getOfflinePlayer(player), permission); + } + + @Override + public boolean playerRemove(String world, OfflinePlayer player, String permission) { + String server = PandalibPaperPermissions.serverName; + Permissions.getPlayer(player.getUniqueId()).removeSelfPermission(permission, server, world); + Log.info("A plugin removed permission " + permission + " (server=" + server + ",world=" + world + ") to player " + player.getName() + " through Vault."); + return true; } @Override @@ -97,11 +112,15 @@ import fr.pandacube.lib.util.Log; @Override public boolean groupAdd(String world, String group, String permission) { + Log.warning(new Throwable("A plugin tried to add to group " + group + " (world=" + world + ") the permission " + permission + + " through Vault but Pandalib does not support it.")); return false; } @Override public boolean groupRemove(String world, String group, String permission) { + Log.warning(new Throwable("A plugin tried to remove from group " + group + " (world=" + world + ") the permission " + permission + + " through Vault but Pandalib does not support it.")); return false; } @@ -119,12 +138,16 @@ import fr.pandacube.lib.util.Log; @Deprecated @Override public boolean playerAddGroup(String world, String player, String group) { + Log.warning(new Throwable("A plugin tried to add player " + player + " (world=" + world + ") to permission group " + group + + " through Vault but Pandalib does not support it.")); return false; } @Deprecated @Override public boolean playerRemoveGroup(String world, String player, String group) { + Log.warning(new Throwable("A plugin tried to remove player " + player + " (world=" + world + ") from permission group " + group + + " through Vault but Pandalib does not support it.")); return false; }