Validate config tool params on execution

Fixes #642 #686
This commit is contained in:
Brokkonaut
2018-08-01 02:36:06 +02:00
parent 6d13c6436c
commit c30aba4f90
3 changed files with 15 additions and 4 deletions

View File

@ -556,6 +556,10 @@ public final class QueryParams implements Cloneable {
}
public void parseArgs(CommandSender sender, List<String> args) throws IllegalArgumentException {
parseArgs(sender, args, true);
}
public void parseArgs(CommandSender sender, List<String> args, boolean validate) throws IllegalArgumentException {
if (args == null || args.isEmpty()) {
throw new IllegalArgumentException("No parameters specified.");
}
@ -775,6 +779,15 @@ public final class QueryParams implements Cloneable {
}
i += values.length;
}
if (validate) {
validate();
}
if (session != null) {
session.lastQuery = clone();
}
}
public void validate() {
if (bct == BlockChangeType.KILLS) {
if (world == null) {
throw new IllegalArgumentException("No world specified");
@ -794,9 +807,6 @@ public final class QueryParams implements Cloneable {
if (bct == BlockChangeType.CHAT && !Config.isLogging(Logging.CHAT)) {
throw new IllegalArgumentException("Chat is not logged");
}
if (session != null) {
session.lastQuery = clone();
}
}
public void setLocation(Location loc) {

View File

@ -228,7 +228,7 @@ public class Config {
final boolean canDrop = tSec.getBoolean("canDrop", false);
final QueryParams params = new QueryParams(logblock);
params.prepareToolQuery = true;
params.parseArgs(getConsoleSender(), Arrays.asList(tSec.getString("params").split(" ")));
params.parseArgs(getConsoleSender(), Arrays.asList(tSec.getString("params").split(" ")), false);
final ToolMode mode = ToolMode.valueOf(tSec.getString("mode").toUpperCase());
final PermissionDefault pdef = PermissionDefault.valueOf(tSec.getString("permissionDefault").toUpperCase());
tools.add(new Tool(toolName, aliases, leftClickBehavior, rightClickBehavior, defaultEnabled, item, canDrop, params, mode, pdef));

View File

@ -69,6 +69,7 @@ public class ToolListener implements Listener {
}
}
try {
params.validate();
if (toolData.mode == ToolMode.ROLLBACK) {
handler.new CommandRollback(player, params, true);
} else if (toolData.mode == ToolMode.REDO) {