From c0eceb9473053695a5f0dfbc28b1b8b1eca86cc7 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 29 Nov 2014 02:48:49 +0100 Subject: [PATCH] Fix PermissionUtil/npe (ensure a Permission instance is present). --- .../permissions/PermissionUtil.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java index d553964d..bd3a96e5 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/permissions/PermissionUtil.java @@ -121,7 +121,7 @@ public class PermissionUtil { } // Set the permission for the command. String cmdPermName = command.getPermission(); - boolean cmdHadPerm; + final boolean cmdHadPerm; if (cmdPermName == null) { // Set a permission. cmdPermName = permissionBase + "." + lcLabel; @@ -133,23 +133,21 @@ public class PermissionUtil { } // Set permission default behavior. Permission cmdPerm = pm.getPermission(cmdPermName); - if (cmdPerm == null) { + final boolean permRegistered = cmdPerm != null; + if (!permRegistered) { + cmdPerm = new Permission(cmdPermName); if (!cmdHadPerm) { - cmdPerm = new Permission(cmdPermName); + // NCP added the permission, allow root. cmdPerm.addParent(rootPerm, true); - pm.addPermission(cmdPerm); - } + } // else: permission was present, but not registered. + pm.addPermission(cmdPerm); } // Create change history entry. - if (cmdHadPerm) { - if (cmdPerm == null) { - changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, null, command.getPermissionMessage())); - } - else { - changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, cmdPerm.getDefault(), command.getPermissionMessage())); - } + if (cmdHadPerm && permRegistered) { + changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, cmdPerm.getDefault(), command.getPermissionMessage())); } else { + // (New Permission instances will not be touched on restore.) changed.add(new CommandProtectionEntry(command, lcLabel, null, null, command.getPermissionMessage())); } // Change