From 07c38de44bc8c08bee48f0a53382aa3d9a151e6d Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 18 Aug 2017 10:44:54 +0200 Subject: [PATCH] Allow permission info command to be filtered by context (#442) --- .../generic/permission/PermissionInfo.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java index cf2868e46..2ed8f9265 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/impl/generic/permission/PermissionInfo.java @@ -112,9 +112,41 @@ public class PermissionInfo extends SharedSubCommand { } private static Map.Entry nodesToMessage(boolean temp, String filter, SortedSet nodes, PermissionHolder holder, String label, int pageNumber, boolean console) { + // parse the filter + String nodeFilter = null; + Map.Entry contextFilter = null; + + if (filter != null) { + int index = filter.indexOf('='); + + context: + if (index != -1) { + String key = filter.substring(0, index); + if (key.equals("")) { + break context; + } + + String value = filter.substring(index + 1); + if (value.equals("")) { + break context; + } + + contextFilter = Maps.immutableEntry(key, value); + } + + if (contextFilter == null) { + nodeFilter = filter; + } + } + List l = new ArrayList<>(); for (Node node : nodes) { - if (filter != null && !node.getPermission().startsWith(filter)) continue; + if (nodeFilter != null && !node.getPermission().startsWith(nodeFilter)) { + continue; + } + if (contextFilter != null && !node.getFullContexts().hasIgnoreCase(contextFilter.getKey(), contextFilter.getValue())) { + continue; + } if (temp != node.isTemporary()) continue; l.add(node); }