From 6255ccce386214985c1c9d0ea5d2fb0ef6d3df16 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 28 Apr 2019 17:27:33 -0700 Subject: [PATCH] Minor bug fixes --- .../worldedit/command/ApplyBrushCommands.java | 1 + .../worldedit/command/PaintBrushCommands.java | 1 + .../command/argument/FactoryConverter.java | 3 ++- .../platform/PlatformCommandManager.java | 5 +++-- .../command/WorldEditExceptionConverter.java | 13 ++++++++---- .../parametric/ExceptionConverterHelper.java | 21 ++++++++++--------- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java index d324c3484..285dd272c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java @@ -84,6 +84,7 @@ public class ApplyBrushCommands { builder.addParts(REGION_FACTORY, RADIUS); builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TextComponent.of("Type of brush to use")) .withCommands(manager.getAllCommands().collect(Collectors.toList())) + .required() .build()); }); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java index c365e129f..9b1aeef94 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java @@ -89,6 +89,7 @@ public class PaintBrushCommands { builder.addParts(REGION_FACTORY, RADIUS, DENSITY); builder.addPart(SubCommandPart.builder(TranslatableComponent.of("type"), TextComponent.of("Type of brush to use")) .withCommands(manager.getAllCommands().collect(Collectors.toList())) + .required() .build()); }); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java index 2e7eedb72..0de24e5a7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/FactoryConverter.java @@ -36,6 +36,7 @@ import com.sk89q.worldedit.world.World; import org.enginehub.piston.CommandManager; import org.enginehub.piston.converter.ArgumentConverter; import org.enginehub.piston.converter.ConversionResult; +import org.enginehub.piston.converter.FailedConversion; import org.enginehub.piston.converter.SuccessfulConversion; import org.enginehub.piston.inject.InjectedValueAccess; import org.enginehub.piston.inject.Key; @@ -86,7 +87,7 @@ public class FactoryConverter implements ArgumentConverter { factoryExtractor.apply(worldEdit).parseFromInput(argument, parserContext) ); } catch (InputParseException e) { - throw new IllegalArgumentException(e); + return FailedConversion.from(e); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 34b5e0e82..bfc362a6d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -256,6 +256,7 @@ public final class PlatformCommandManager { registration, instance ); + additionalConfig.accept(manager); cmd.addPart(SubCommandPart.builder(TranslatableComponent.of("worldedit.argument.action"), TextComponent.of("Sub-command to run.")) @@ -443,7 +444,7 @@ public final class PlatformCommandManager { Request.reset(); Actor actor = platformManager.createProxyActor(event.getActor()); - String[] split = commandDetection(event.getArguments().split(" ")); + String[] split = commandDetection(event.getArguments().substring(1).split(" ")); // No command found! if (!commandManager.containsCommand(split[0])) { @@ -511,7 +512,7 @@ public final class PlatformCommandManager { actor.print(TextComponent.builder("Usage: ") .color(TextColor.RED) .append(TextComponent.of("/", ColorConfig.getMainText())) - .append(HelpGenerator.create(cmd).getUsage()) + .append(HelpGenerator.create(e.getCommandParseResult()).getUsage()) .build()); } } catch (CommandExecutionException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditExceptionConverter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditExceptionConverter.java index a11294527..3dfafe349 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditExceptionConverter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditExceptionConverter.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.internal.command; -import static com.google.common.base.Preconditions.checkNotNull; - import com.google.common.collect.ImmutableList; import com.sk89q.worldedit.DisallowedItemException; import com.sk89q.worldedit.EmptyClipboardException; @@ -35,7 +33,6 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.InsufficientArgumentsException; import com.sk89q.worldedit.command.tool.InvalidToolBindException; -import com.sk89q.worldedit.command.util.PermissionCondition; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.util.command.parametric.ExceptionConverterHelper; @@ -45,11 +42,13 @@ import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException; import com.sk89q.worldedit.util.io.file.InvalidFilenameException; import org.enginehub.piston.exception.CommandException; -import org.enginehub.piston.exception.ConditionFailedException; +import org.enginehub.piston.exception.UsageException; import java.util.regex.Matcher; import java.util.regex.Pattern; +import static com.google.common.base.Preconditions.checkNotNull; + /** * converts WorldEdit exceptions and converts them into {@link CommandException}s. */ @@ -173,4 +172,10 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper { throw newCommandException(e.getMessage(), e); } + // Prevent investigation into UsageExceptions + @ExceptionMatch + public void convert(UsageException e) throws CommandException { + throw e; + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java index f13557487..039bd4cde 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ExceptionConverterHelper.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.util.command.parametric; +import com.google.common.collect.ImmutableList; import com.sk89q.minecraft.util.commands.WrappedCommandException; import org.enginehub.piston.exception.CommandException; import org.enginehub.piston.exception.CommandExecutionException; @@ -32,24 +33,24 @@ import java.util.List; /** * An implementation of an {@link ExceptionConverter} that automatically calls * the correct method defined on this object. - * + * *

Only public methods will be used. Methods will be called in order of decreasing * levels of inheritance (between classes where one inherits the other). For two * different inheritance branches, the order between them is undefined.

*/ public abstract class ExceptionConverterHelper implements ExceptionConverter { - + private final List handlers; @SuppressWarnings("unchecked") public ExceptionConverterHelper() { List handlers = new ArrayList<>(); - + for (Method method : this.getClass().getMethods()) { if (method.getAnnotation(ExceptionMatch.class) == null) { continue; } - + Class[] parameters = method.getParameterTypes(); if (parameters.length == 1) { Class cls = parameters[0]; @@ -59,9 +60,9 @@ public abstract class ExceptionConverterHelper implements ExceptionConverter { } } } - + Collections.sort(handlers); - + this.handlers = handlers; } @@ -76,18 +77,18 @@ public abstract class ExceptionConverterHelper implements ExceptionConverter { if (e.getCause() instanceof CommandException) { throw (CommandException) e.getCause(); } - throw new CommandExecutionException(e, null); + throw new CommandExecutionException(e, ImmutableList.of()); } catch (IllegalArgumentException | IllegalAccessException e) { - throw new CommandExecutionException(e, null); + throw new CommandExecutionException(e, ImmutableList.of()); } } } } - + private static class ExceptionHandler implements Comparable { final Class cls; final Method method; - + private ExceptionHandler(Class cls, Method method) { this.cls = cls; this.method = method;