Stop using IAE to communicate parameter mis-use

This commit is contained in:
Kenzie Togami
2019-05-14 17:57:05 -07:00
parent 718c2e8306
commit e7613dd879
4 changed files with 37 additions and 17 deletions

View File

@ -19,10 +19,14 @@
package com.sk89q.worldedit.internal.command;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import org.enginehub.piston.Command;
import org.enginehub.piston.exception.CommandException;
import org.enginehub.piston.part.SubCommandPart;
import java.util.Comparator;
@ -92,6 +96,30 @@ public class CommandUtil {
return Optional.of(builder.toString());
}
/**
* Require {@code condition} to be {@code true}, otherwise throw a {@link CommandException}
* with the given message.
*
* @param condition the condition to check
* @param message the message for failure
*/
public static void checkCommandArgument(boolean condition, String message) {
checkCommandArgument(condition, TextComponent.of(message));
}
/**
* Require {@code condition} to be {@code true}, otherwise throw a {@link CommandException}
* with the given message.
*
* @param condition the condition to check
* @param message the message for failure
*/
public static void checkCommandArgument(boolean condition, Component message) {
if (!condition) {
throw new CommandException(message, ImmutableList.of());
}
}
private CommandUtil() {
}
}

View File

@ -165,11 +165,6 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
throw newCommandException(e.getMessage(), e);
}
@ExceptionMatch
public void convert(IllegalArgumentException e) throws CommandException {
throw newCommandException(e.getMessage(), e);
}
// Prevent investigation into UsageExceptions
@ExceptionMatch
public void convert(UsageException e) throws CommandException {