mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-08-29 09:09:51 +02:00
Warn users with multiple permissions plugins installed (#3006)
This commit is contained in:
@@ -305,7 +305,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
|
|||||||
this.bootstrap.getScheduler().executeSync(() -> {
|
this.bootstrap.getScheduler().executeSync(() -> {
|
||||||
try {
|
try {
|
||||||
LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this);
|
LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this);
|
||||||
PermissibleInjector.inject(player, lpPermissible);
|
PermissibleInjector.inject(player, lpPermissible, getLogger());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
getLogger().severe("Exception thrown when setting up permissions for " +
|
getLogger().severe("Exception thrown when setting up permissions for " +
|
||||||
player.getUniqueId() + " - " + player.getName(), t);
|
player.getUniqueId() + " - " + player.getName(), t);
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
package me.lucko.luckperms.bukkit.inject.permissible;
|
package me.lucko.luckperms.bukkit.inject.permissible;
|
||||||
|
|
||||||
import me.lucko.luckperms.bukkit.util.CraftBukkitImplementation;
|
import me.lucko.luckperms.bukkit.util.CraftBukkitImplementation;
|
||||||
|
import me.lucko.luckperms.common.plugin.logging.PluginLogger;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissibleBase;
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
@@ -84,9 +85,10 @@ public final class PermissibleInjector {
|
|||||||
*
|
*
|
||||||
* @param player the player to inject into
|
* @param player the player to inject into
|
||||||
* @param newPermissible the permissible to inject
|
* @param newPermissible the permissible to inject
|
||||||
|
* @param logger the plugin logger
|
||||||
* @throws Exception propagates any exceptions which were thrown during injection
|
* @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
|
// get the existing PermissibleBase held by the player
|
||||||
PermissibleBase oldPermissible = (PermissibleBase) HUMAN_ENTITY_PERMISSIBLE_FIELD.get(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());
|
throw new IllegalStateException("LPPermissible already injected into player " + player.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Class<? extends PermissibleBase> 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
|
// Move attachments over from the old permissible
|
||||||
|
|
||||||
//noinspection unchecked
|
//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<? extends PermissibleBase> 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!)");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -203,7 +203,7 @@ public class BukkitConnectionListener extends AbstractConnectionListener impleme
|
|||||||
LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this.plugin);
|
LuckPermsPermissible lpPermissible = new LuckPermsPermissible(player, user, this.plugin);
|
||||||
|
|
||||||
// Inject into the player
|
// Inject into the player
|
||||||
PermissibleInjector.inject(player, lpPermissible);
|
PermissibleInjector.inject(player, lpPermissible, this.plugin.getLogger());
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
this.plugin.getLogger().warn("Exception thrown when setting up permissions for " +
|
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, "");
|
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
|
// Wait until the last priority to unload, so plugins can still perform permission checks on this event
|
||||||
|
Reference in New Issue
Block a user