From 71896a75bfd639bd173f2aab4b99c23526723f06 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 2 May 2021 16:14:23 +0100 Subject: [PATCH] Warn users with multiple permissions plugins installed (#3006) --- .../luckperms/bukkit/LPBukkitPlugin.java | 2 +- .../permissible/PermissibleInjector.java | 33 ++++++++++++++++++- .../listeners/BukkitConnectionListener.java | 4 ++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index df390c145..44b322766 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -305,7 +305,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin { this.bootstrap.getScheduler().executeSync(() -> { try { LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this); - PermissibleInjector.inject(player, lpPermissible); + PermissibleInjector.inject(player, lpPermissible, getLogger()); } catch (Throwable t) { getLogger().severe("Exception thrown when setting up permissions for " + player.getUniqueId() + " - " + player.getName(), t); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/PermissibleInjector.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/PermissibleInjector.java index 7196b5196..d7e819a2c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/PermissibleInjector.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/inject/permissible/PermissibleInjector.java @@ -26,6 +26,7 @@ package me.lucko.luckperms.bukkit.inject.permissible; import me.lucko.luckperms.bukkit.util.CraftBukkitImplementation; +import me.lucko.luckperms.common.plugin.logging.PluginLogger; import org.bukkit.entity.Player; import org.bukkit.permissions.PermissibleBase; @@ -84,9 +85,10 @@ public final class PermissibleInjector { * * @param player the player to inject into * @param newPermissible the permissible to inject + * @param logger the plugin logger * @throws Exception propagates any exceptions which were thrown during injection */ - public static void inject(Player player, LuckPermsPermissible newPermissible) throws Exception { + public static void inject(Player player, LuckPermsPermissible newPermissible, PluginLogger logger) throws Exception { // get the existing PermissibleBase held by the player PermissibleBase oldPermissible = (PermissibleBase) HUMAN_ENTITY_PERMISSIBLE_FIELD.get(player); @@ -96,6 +98,15 @@ public final class PermissibleInjector { throw new IllegalStateException("LPPermissible already injected into player " + player.toString()); } + Class oldClass = oldPermissible.getClass(); + if (!PermissibleBase.class.equals(oldClass)) { + logger.warn("Player " + player.getName() + " already has a custom permissible (" + oldClass.getName() + ")!\n" + + "This is probably because you have multiple permission plugins installed.\n" + + "Please make sure that LuckPerms is the only permission plugin installed on your server!\n" + + "(unless you're performing a migration, in which case, just remember to remove your old " + + "permission plugin once you're done!)"); + } + // Move attachments over from the old permissible //noinspection unchecked @@ -151,4 +162,24 @@ public final class PermissibleInjector { } } + public static void checkInjected(Player player, PluginLogger logger) { + PermissibleBase permissibleBase; + try { + permissibleBase = (PermissibleBase) HUMAN_ENTITY_PERMISSIBLE_FIELD.get(player); + } catch (IllegalAccessException e) { + return; // ignore + } + + if (permissibleBase instanceof LuckPermsPermissible) { + return; // all gucci + } + + Class clazz = permissibleBase.getClass(); + logger.warn("Player " + player.getName() + " has a non-LuckPerms permissible (" + clazz.getName() + ")!\n" + + "This is probably because you have multiple permission plugins installed.\n" + + "Please make sure that LuckPerms is the only permission plugin installed on your server!\n" + + "(unless you're performing a migration, in which case, just remember to remove your old " + + "permission plugin once you're done!)"); + } + } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java index 747754454..9dbbd5b24 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/listeners/BukkitConnectionListener.java @@ -203,7 +203,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this.plugin); // Inject into the player - PermissibleInjector.inject(player, lpPermissible); + PermissibleInjector.inject(player, lpPermissible, this.plugin.getLogger()); } catch (Throwable t) { this.plugin.getLogger().warn("Exception thrown when setting up permissions for " + @@ -230,6 +230,8 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme e.disallow(PlayerLoginEvent.Result.KICK_OTHER, ""); } } + + PermissibleInjector.checkInjected(e.getPlayer(), this.plugin.getLogger()); } // Wait until the last priority to unload, so plugins can still perform permission checks on this event