Fix permissible injection issue on Nukkit (#2791, #2799)

This commit is contained in:
Luck 2021-01-01 20:00:03 +00:00
parent 657cf2a45e
commit 68167490d4
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -76,13 +76,14 @@ public final class PermissibleInjector {
* @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) throws Exception {
// get the existing PermissibleBase held by the player // get the existing PermissibleBase held by the player
PermissibleBase oldPermissible = (PermissibleBase) PLAYER_PERMISSIBLE_FIELD.get(player); PermissibleBase oldPermissible = (PermissibleBase) PLAYER_PERMISSIBLE_FIELD.get(player);
// seems we have already injected into this player.
if (oldPermissible instanceof LuckPermsPermissible) { if (oldPermissible instanceof LuckPermsPermissible) {
throw new IllegalStateException("LPPermissible already injected into player " + player.toString()); // Nukkit seems to re-use player instances (or perhaps calls the login event twice?)
// so, just uninject here instead of throwing an exception like we do on Bukkit
// See: https://github.com/lucko/LuckPerms/issues/2791
uninject(player, false);
} }
// Move attachments over from the old permissible // Move attachments over from the old permissible