Fix NPE using '/cf' command with no value. Fixes #86

This commit is contained in:
bloodshot 2020-01-01 21:21:05 -05:00
parent 1c8a2692d1
commit 0629618946

View File

@ -205,6 +205,10 @@ public static PermissionResult addFlagPermission(CommandSender src, GDPermission
GriefDefenderPlugin.sendMessage(src, denyReason); GriefDefenderPlugin.sendMessage(src, denyReason);
return new GDPermissionResult(ResultTypes.NO_PERMISSION); 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 // special handling for commands
@ -223,11 +227,13 @@ public static PermissionResult addFlagPermission(CommandSender src, GDPermission
} }
String[] parts = target.split(":"); 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 // check for meta
parts = target.split("\\."); parts = target.split("\\.");
String targetFlag = parts[0]; String targetId = parts[0];
if (parts.length > 1) { /*if (parts.length > 1) {
try { try {
Integer.parseInt(parts[1]); Integer.parseInt(parts[1]);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
@ -237,15 +243,9 @@ public static PermissionResult addFlagPermission(CommandSender src, GDPermission
GriefDefenderPlugin.sendMessage(src, message); GriefDefenderPlugin.sendMessage(src, message);
return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID); return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID);
} }
} }*/
addFlagContexts(contexts, flag, targetFlag); addFlagContexts(contexts, flag, targetId);
if (!targetFlag.startsWith("#") && !CommandHelper.validateFlagTarget(flag, targetFlag)) { if (!targetId.contains("#") && !CommandHelper.validateFlagTarget(flag, targetId)) {
//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));
return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID); return new GDPermissionResult(ResultTypes.TARGET_NOT_VALID);
} }
} }