Fix NPE with LPPermissibles & refreshing users
This commit is contained in:
parent
ed5892eb56
commit
7853d4686a
@ -113,7 +113,7 @@ class BukkitListener extends AbstractListener implements Listener {
|
|||||||
|
|
||||||
// Inject into the player
|
// Inject into the player
|
||||||
Injector.inject(player, lpPermissible);
|
Injector.inject(player, lpPermissible);
|
||||||
u.setLpPermissible(lpPermissible);
|
u.setPermissible(lpPermissible);
|
||||||
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
|
@ -40,9 +40,8 @@ import java.util.UUID;
|
|||||||
public class BukkitUser extends User {
|
public class BukkitUser extends User {
|
||||||
private final LPBukkitPlugin plugin;
|
private final LPBukkitPlugin plugin;
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private LPPermissible lpPermissible = null;
|
private LPPermissible lpPermissible = null;
|
||||||
|
private final Object permissibleLock = new Object();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@ -62,17 +61,30 @@ public class BukkitUser extends User {
|
|||||||
return lpPermissible != null && lpPermissible.isOp();
|
return lpPermissible != null && lpPermissible.isOp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LPPermissible getPermissible() {
|
||||||
|
synchronized (permissibleLock) {
|
||||||
|
return lpPermissible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissible(LPPermissible permissible) {
|
||||||
|
synchronized (permissibleLock) {
|
||||||
|
lpPermissible = permissible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public synchronized void refreshPermissions() {
|
public synchronized void refreshPermissions() {
|
||||||
if (lpPermissible == null) {
|
LPPermissible permissible = getPermissible();
|
||||||
|
if (permissible == null) {
|
||||||
return;
|
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.
|
// 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<String, Boolean> toApply = exportNodes(
|
Map<String, Boolean> toApply = exportNodes(
|
||||||
new Contexts(
|
new Contexts(
|
||||||
plugin.getContextManager().giveApplicableContext((Player) lpPermissible.getParent(), new HashMap<>()),
|
plugin.getContextManager().giveApplicableContext((Player) permissible.getParent(), new HashMap<>()),
|
||||||
plugin.getConfiguration().isIncludingGlobalPerms(),
|
plugin.getConfiguration().isIncludingGlobalPerms(),
|
||||||
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
||||||
true,
|
true,
|
||||||
@ -84,7 +96,7 @@ public class BukkitUser extends User {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, Boolean> existing = lpPermissible.getLuckPermsPermissions();
|
Map<String, Boolean> existing = permissible.getLuckPermsPermissions();
|
||||||
|
|
||||||
boolean different = false;
|
boolean different = false;
|
||||||
if (toApply.size() != existing.size()) {
|
if (toApply.size() != existing.size()) {
|
||||||
@ -102,7 +114,7 @@ public class BukkitUser extends User {
|
|||||||
if (!different) return;
|
if (!different) return;
|
||||||
|
|
||||||
existing.clear();
|
existing.clear();
|
||||||
lpPermissible.invalidateCache();
|
permissible.invalidateCache();
|
||||||
existing.putAll(toApply);
|
existing.putAll(toApply);
|
||||||
|
|
||||||
if (plugin.getConfiguration().isAutoOp()) {
|
if (plugin.getConfiguration().isAutoOp()) {
|
||||||
@ -116,8 +128,8 @@ public class BukkitUser extends User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final boolean finalOp = op;
|
final boolean finalOp = op;
|
||||||
if (lpPermissible.isOp() != op) {
|
if (permissible.isOp() != op) {
|
||||||
final Permissible parent = lpPermissible.getParent();
|
final Permissible parent = permissible.getParent();
|
||||||
plugin.doSync(() -> parent.setOp(finalOp));
|
plugin.doSync(() -> parent.setOp(finalOp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ public class BukkitUserManager extends UserManager implements ContextListener<Pl
|
|||||||
BukkitUser u = (BukkitUser) user;
|
BukkitUser u = (BukkitUser) user;
|
||||||
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
|
Player player = plugin.getServer().getPlayer(plugin.getUuidCache().getExternalUUID(u.getUuid()));
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (u.getLpPermissible() != null) {
|
if (u.getPermissible() != null) {
|
||||||
Injector.unInject(player); // TODO is this needed?
|
Injector.unInject(player);
|
||||||
u.setLpPermissible(null);
|
u.setPermissible(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plugin.getConfiguration().isAutoOp()) {
|
if (plugin.getConfiguration().isAutoOp()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user