mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-30 22:53:27 +01:00
Test verbose filters before registering them (#178)
This commit is contained in:
parent
140e6b08ca
commit
3f17e8c3c8
@ -65,6 +65,12 @@ public class VerboseCommand extends SingleCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String filter = filters.isEmpty() ? "" : filters.stream().collect(Collectors.joining(" "));
|
String filter = filters.isEmpty() ? "" : filters.stream().collect(Collectors.joining(" "));
|
||||||
|
|
||||||
|
if (!DebugListener.isValidFilter(filter)) {
|
||||||
|
Message.VERBOSE_INVALID_FILTER.send(sender, filter);
|
||||||
|
return CommandResult.FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
boolean notify = !mode.equals("record");
|
boolean notify = !mode.equals("record");
|
||||||
|
|
||||||
plugin.getDebugHandler().register(sender, filter, notify);
|
plugin.getDebugHandler().register(sender, filter, notify);
|
||||||
|
@ -96,6 +96,7 @@ public enum Message {
|
|||||||
/*
|
/*
|
||||||
* Commands
|
* Commands
|
||||||
*/
|
*/
|
||||||
|
VERBOSE_INVALID_FILTER("&cInvalid verbose filter: &f{0}", true),
|
||||||
VERBOSE_ON("&bVerbose checking output set to &aTRUE &bfor all permissions.", true),
|
VERBOSE_ON("&bVerbose checking output set to &aTRUE &bfor all permissions.", true),
|
||||||
VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}", true),
|
VERBOSE_ON_QUERY("&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}", true),
|
||||||
VERBOSE_OFF("&bVerbose checking output set to &cFALSE&b.", true),
|
VERBOSE_OFF("&bVerbose checking output set to &cFALSE&b.", true),
|
||||||
|
@ -116,6 +116,42 @@ public class DebugListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isValidFilter(String filter) {
|
||||||
|
if (filter.equals("")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptEngine engine = Scripting.getScriptEngine();
|
||||||
|
if (engine == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringTokenizer tokenizer = new StringTokenizer(filter, " |&()!", true);
|
||||||
|
StringBuilder expression = new StringBuilder();
|
||||||
|
|
||||||
|
while (tokenizer.hasMoreTokens()) {
|
||||||
|
String token = tokenizer.nextToken();
|
||||||
|
if (!isDelim(token)) {
|
||||||
|
token = "true"; // dummy result
|
||||||
|
}
|
||||||
|
|
||||||
|
expression.append(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
String exp = expression.toString().replace("&", "&&").replace("|", "||");
|
||||||
|
String result = engine.eval(exp).toString();
|
||||||
|
if (!result.equals("true") && !result.equals("false")) {
|
||||||
|
throw new IllegalArgumentException(exp + " - " + result);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Throwable t) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isDelim(String token) {
|
private static boolean isDelim(String token) {
|
||||||
return token.equals(" ") || token.equals("|") || token.equals("&") || token.equals("(") || token.equals(")") || token.equals("!");
|
return token.equals(" ") || token.equals("|") || token.equals("&") || token.equals("(") || token.equals(")") || token.equals("!");
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ use-inherit-command: "Use the 'parent add' command instead of specifying the nod
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
verbose-invalid-filter: "&cInvalid verbose filter: &f{0}"
|
||||||
verbose-on: "&bVerbose checking output set to &aTRUE &bfor all permissions."
|
verbose-on: "&bVerbose checking output set to &aTRUE &bfor all permissions."
|
||||||
verbose-on_query: "&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}"
|
verbose-on_query: "&bVerbose checking output set to &aTRUE &bfor permissions matching the following filters: &f{0}"
|
||||||
verbose-off: "&bVerbose checking output set to &cFALSE&b."
|
verbose-off: "&bVerbose checking output set to &cFALSE&b."
|
||||||
|
Loading…
Reference in New Issue
Block a user