2013-06-18 21:51:42 +00:00
|
|
|
/*
|
2014-06-27 23:03:29 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2013-06-18 21:51:42 +00:00
|
|
|
*
|
2014-06-27 23:03:29 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
2013-06-18 21:51:42 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-06-27 23:03:29 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
|
|
* for more details.
|
2013-06-18 21:51:42 +00:00
|
|
|
*
|
2014-06-27 23:03:29 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-06-18 21:51:42 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
package com.sk89q.worldedit.internal.command.exception;
|
2013-06-18 21:51:42 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2018-06-17 07:50:04 +00:00
|
|
|
import com.sk89q.worldedit.DisallowedItemException;
|
|
|
|
import com.sk89q.worldedit.EmptyClipboardException;
|
|
|
|
import com.sk89q.worldedit.IncompleteRegionException;
|
|
|
|
import com.sk89q.worldedit.InvalidItemException;
|
|
|
|
import com.sk89q.worldedit.MaxBrushRadiusException;
|
|
|
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
|
|
import com.sk89q.worldedit.MaxRadiusException;
|
2019-08-25 09:58:28 +00:00
|
|
|
import com.sk89q.worldedit.MissingWorldException;
|
2018-06-17 07:50:04 +00:00
|
|
|
import com.sk89q.worldedit.UnknownDirectionException;
|
|
|
|
import com.sk89q.worldedit.UnknownItemException;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2014-06-27 23:03:29 +00:00
|
|
|
import com.sk89q.worldedit.command.InsufficientArgumentsException;
|
2014-07-29 14:57:45 +00:00
|
|
|
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
|
2014-06-27 23:03:29 +00:00
|
|
|
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
2013-06-18 21:51:42 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionOperationException;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
2014-07-29 14:57:45 +00:00
|
|
|
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
|
|
|
|
import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
|
|
|
|
import com.sk89q.worldedit.util.io.file.InvalidFilenameException;
|
2019-08-06 15:29:49 +00:00
|
|
|
import org.enginehub.piston.exception.CommandException;
|
|
|
|
import org.enginehub.piston.exception.UsageException;
|
2014-06-27 23:03:29 +00:00
|
|
|
|
2020-02-05 05:37:42 +00:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
2019-04-29 00:27:33 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
|
2013-06-18 21:51:42 +00:00
|
|
|
/**
|
|
|
|
* converts WorldEdit exceptions and converts them into {@link CommandException}s.
|
|
|
|
*/
|
|
|
|
public class WorldEditExceptionConverter extends ExceptionConverterHelper {
|
|
|
|
|
2014-06-27 23:03:29 +00:00
|
|
|
private static final Pattern numberFormat = Pattern.compile("^For input string: \"(.*)\"$");
|
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
|
|
|
public WorldEditExceptionConverter(WorldEdit worldEdit) {
|
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
private CommandException newCommandException(String message, Throwable cause) {
|
|
|
|
return new CommandException(TextComponent.of(String.valueOf(message)), cause, ImmutableList.of());
|
|
|
|
}
|
|
|
|
|
2013-06-18 21:51:42 +00:00
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(NumberFormatException e) throws CommandException {
|
|
|
|
final Matcher matcher = numberFormat.matcher(e.getMessage());
|
|
|
|
|
|
|
|
if (matcher.matches()) {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Number expected; string \"" + matcher.group(1)
|
|
|
|
+ "\" given.", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
} else {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Number expected; string given.", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(IncompleteRegionException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Make a region selection first.", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 15:29:49 +00:00
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(MissingWorldException e) throws CommandException {
|
|
|
|
throw newCommandException("You need to provide a world (Try //world)", e);
|
|
|
|
}
|
2019-09-21 01:52:35 +00:00
|
|
|
|
2013-06-18 21:51:42 +00:00
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(UnknownItemException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Block name '" + e.getID() + "' was not recognized.", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(InvalidItemException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException(e.getMessage(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(DisallowedItemException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Block '" + e.getID()
|
|
|
|
+ "' not allowed (see WorldEdit configuration).", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(MaxChangedBlocksException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Max blocks changed in an operation reached ("
|
|
|
|
+ e.getBlockLimit() + ").", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
2014-06-29 01:53:06 +00:00
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(MaxBrushRadiusException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Maximum brush radius (in configuration): " + worldEdit.getConfiguration().maxBrushRadius, e);
|
2014-06-29 01:53:06 +00:00
|
|
|
}
|
|
|
|
|
2013-06-18 21:51:42 +00:00
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(MaxRadiusException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Maximum radius (in configuration): " + worldEdit.getConfiguration().maxRadius, e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(UnknownDirectionException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Unknown direction: " + e.getDirection(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(InsufficientArgumentsException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException(e.getMessage(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(RegionOperationException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException(e.getMessage(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(ExpressionException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException(e.getMessage(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(EmptyClipboardException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Your clipboard is empty. Use //copy first.", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(InvalidFilenameException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Filename '" + e.getFilename() + "' invalid: "
|
|
|
|
+ e.getMessage(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(FilenameResolutionException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException(
|
|
|
|
"File '" + e.getFilename() + "' resolution error: " + e.getMessage(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(InvalidToolBindException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("Can't bind tool to " + e.getItemType().getName() + ": " + e.getMessage(), e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(FileSelectionAbortedException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException("File selection aborted.", e);
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(WorldEditException e) throws CommandException {
|
2019-07-06 00:46:48 +00:00
|
|
|
throw newCommandException(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent investigation into UsageExceptions
|
|
|
|
@ExceptionMatch
|
|
|
|
public void convert(UsageException e) throws CommandException {
|
|
|
|
throw e;
|
2013-06-18 21:51:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|