From 7853d4686a32c2f823406cd61e8dbbfe9f2b689c Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 8 Oct 2016 16:43:57 +0100 Subject: [PATCH] Fix NPE with LPPermissibles & refreshing users --- .../me/lucko/luckperms/BukkitListener.java | 2 +- .../me/lucko/luckperms/users/BukkitUser.java | 28 +++++++++++++------ .../luckperms/users/BukkitUserManager.java | 6 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/bukkit/src/main/java/me/lucko/luckperms/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/BukkitListener.java index 87b63b45..aeb67bcd 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/BukkitListener.java @@ -113,7 +113,7 @@ class BukkitListener extends AbstractListener implements Listener { // Inject into the player Injector.inject(player, lpPermissible); - u.setLpPermissible(lpPermissible); + u.setPermissible(lpPermissible); } catch (Throwable t) { t.printStackTrace(); diff --git a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java index a356c737..710dff2e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java +++ b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUser.java @@ -40,9 +40,8 @@ import java.util.UUID; public class BukkitUser extends User { private final LPBukkitPlugin plugin; - @Getter - @Setter private LPPermissible lpPermissible = null; + private final Object permissibleLock = new Object(); @Getter @Setter @@ -62,17 +61,30 @@ public class BukkitUser extends User { return lpPermissible != null && lpPermissible.isOp(); } + public LPPermissible getPermissible() { + synchronized (permissibleLock) { + return lpPermissible; + } + } + + public void setPermissible(LPPermissible permissible) { + synchronized (permissibleLock) { + lpPermissible = permissible; + } + } + @SuppressWarnings("unchecked") @Override public synchronized void refreshPermissions() { - if (lpPermissible == null) { + LPPermissible permissible = getPermissible(); + if (permissible == null) { return; } // Calculate the permissions that should be applied. This is done async, who cares about how long it takes or how often it's done. Map toApply = exportNodes( new Contexts( - plugin.getContextManager().giveApplicableContext((Player) lpPermissible.getParent(), new HashMap<>()), + plugin.getContextManager().giveApplicableContext((Player) permissible.getParent(), new HashMap<>()), plugin.getConfiguration().isIncludingGlobalPerms(), plugin.getConfiguration().isIncludingGlobalWorldPerms(), true, @@ -84,7 +96,7 @@ public class BukkitUser extends User { ); try { - Map existing = lpPermissible.getLuckPermsPermissions(); + Map existing = permissible.getLuckPermsPermissions(); boolean different = false; if (toApply.size() != existing.size()) { @@ -102,7 +114,7 @@ public class BukkitUser extends User { if (!different) return; existing.clear(); - lpPermissible.invalidateCache(); + permissible.invalidateCache(); existing.putAll(toApply); if (plugin.getConfiguration().isAutoOp()) { @@ -116,8 +128,8 @@ public class BukkitUser extends User { } final boolean finalOp = op; - if (lpPermissible.isOp() != op) { - final Permissible parent = lpPermissible.getParent(); + if (permissible.isOp() != op) { + final Permissible parent = permissible.getParent(); plugin.doSync(() -> parent.setOp(finalOp)); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java index c48142d6..6b0cd1f3 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/users/BukkitUserManager.java @@ -46,9 +46,9 @@ public class BukkitUserManager extends UserManager implements ContextListener