From 0629618946b9a45e02f832c329750f2743b5940c Mon Sep 17 00:00:00 2001 From: bloodshot Date: Wed, 1 Jan 2020 21:21:05 -0500 Subject: [PATCH] Fix NPE using '/cf' command with no value. Fixes #86 --- .../griefdefender/command/CommandHelper.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/bukkit/src/main/java/com/griefdefender/command/CommandHelper.java b/bukkit/src/main/java/com/griefdefender/command/CommandHelper.java index 2f4ca84..d97ad33 100644 --- a/bukkit/src/main/java/com/griefdefender/command/CommandHelper.java +++ b/bukkit/src/main/java/com/griefdefender/command/CommandHelper.java @@ -205,6 +205,10 @@ public static PermissionResult addFlagPermission(CommandSender src, GDPermission GriefDefenderPlugin.sendMessage(src, denyReason); return new GDPermissionResult(ResultTypes.NO_PERMISSION); } + if (value == null) { + GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().COMMAND_INVALID); + return new GDPermissionResult(ResultTypes.FAILURE); + } } // special handling for commands @@ -223,11 +227,13 @@ public static PermissionResult addFlagPermission(CommandSender src, GDPermission } String[] parts = target.split(":"); - if (parts.length <= 1 || !parts[1].equalsIgnoreCase("any")) { + if (parts.length == 1) { + addFlagContexts(contexts, flag, target); + } else if (parts.length > 1 && !parts[1].equalsIgnoreCase("any")) { // check for meta parts = target.split("\\."); - String targetFlag = parts[0]; - if (parts.length > 1) { + String targetId = parts[0]; + /*if (parts.length > 1) { try { Integer.parseInt(parts[1]); } catch (NumberFormatException e) { @@ -237,15 +243,9 @@ public static PermissionResult addFlagPermission(CommandSender src, GDPermission GriefDefenderPlugin.sendMessage(src, message); return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID); } - } - addFlagContexts(contexts, flag, targetFlag); - if (!targetFlag.startsWith("#") && !CommandHelper.validateFlagTarget(flag, targetFlag)) { - //TODO - /*final Text message = GriefDefenderPlugin.getInstance().messageData.permissionClaimManage - .apply(ImmutableMap.of( - "target", targetFlag, - "flag", baseFlag)).build();*/ - GriefDefenderPlugin.sendMessage(src,TextComponent.of("Invalid flag " + targetFlag, TextColor.RED)); + }*/ + addFlagContexts(contexts, flag, targetId); + if (!targetId.contains("#") && !CommandHelper.validateFlagTarget(flag, targetId)) { return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID); } }