Renamed InvalidFlagFormat to InvalidFlagFormatException
This commit is contained in:
parent
8d5953a550
commit
bb3fdcc880
|
@ -21,7 +21,6 @@ package com.sk89q.worldguard.commands;
|
|||
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
|
|
@ -59,7 +59,7 @@ import com.sk89q.worldguard.protection.FlagValueCalculator;
|
|||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormatException;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroup;
|
||||
import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
|
@ -587,7 +587,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
|||
// the [value] part throws an error.
|
||||
try {
|
||||
groupValue = groupFlag.parseInput(FlagContext.create().setSender(sender).setInput(group).setObject("region", existing).build());
|
||||
} catch (InvalidFlagFormat e) {
|
||||
} catch (InvalidFlagFormatException e) {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
|
@ -598,7 +598,7 @@ public final class RegionCommands extends RegionCommandsBase {
|
|||
// Set the flag if [value] was given even if [-g group] was given as well
|
||||
try {
|
||||
value = setFlag(existing, foundFlag, sender, value).toString();
|
||||
} catch (InvalidFlagFormat e) {
|
||||
} catch (InvalidFlagFormatException e) {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
|
|
|
@ -41,15 +41,11 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
|||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.domains.CustomDomain;
|
||||
import com.sk89q.worldguard.domains.DefaultDomain;
|
||||
import com.sk89q.worldguard.domains.registry.CustomDomainContext;
|
||||
import com.sk89q.worldguard.domains.registry.InvalidDomainFormat;
|
||||
import com.sk89q.worldguard.internal.permission.RegionPermissionModel;
|
||||
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormatException;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
|
||||
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
|
||||
|
@ -419,9 +415,9 @@ class RegionCommandsBase {
|
|||
* @param flag the flag
|
||||
* @param sender the sender
|
||||
* @param value the value
|
||||
* @throws InvalidFlagFormat thrown if the value is invalid
|
||||
* @throws InvalidFlagFormatException thrown if the value is invalid
|
||||
*/
|
||||
protected static <V> V setFlag(ProtectedRegion region, Flag<V> flag, Actor sender, String value) throws InvalidFlagFormat {
|
||||
protected static <V> V setFlag(ProtectedRegion region, Flag<V> flag, Actor sender, String value) throws InvalidFlagFormatException {
|
||||
V val = flag.parseInput(FlagContext.create().setSender(sender).setInput(value).setObject("region", region).build());
|
||||
region.setFlag(flag, val);
|
||||
return val;
|
||||
|
|
|
@ -33,7 +33,7 @@ public class BooleanFlag extends Flag<Boolean> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Boolean parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public Boolean parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
|
||||
if (input.equalsIgnoreCase("true") || input.equalsIgnoreCase("yes")
|
||||
|
@ -45,7 +45,7 @@ public class BooleanFlag extends Flag<Boolean> {
|
|||
|| input.equalsIgnoreCase("0")) {
|
||||
return false;
|
||||
} else {
|
||||
throw new InvalidFlagFormat("Not a yes/no value: " + input);
|
||||
throw new InvalidFlagFormatException("Not a yes/no value: " + input);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class CommandStringFlag extends Flag<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public String parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
input = input.trim();
|
||||
if (!input.startsWith("/")) {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class DoubleFlag extends NumberFlag<Double> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Double parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public Double parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
return context.getUserInputAsDouble();
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,12 @@ public class EntityTypeFlag extends Flag<EntityType> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public EntityType parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public EntityType parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
input = input.trim();
|
||||
EntityType entityType = unmarshal(input);
|
||||
if (entityType == null) {
|
||||
throw new InvalidFlagFormat("Unknown entity type: " + input);
|
||||
throw new InvalidFlagFormatException("Unknown entity type: " + input);
|
||||
}
|
||||
return entityType;
|
||||
}
|
||||
|
|
|
@ -74,12 +74,12 @@ public class EnumFlag<T extends Enum<T>> extends Flag<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public T parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public T parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
try {
|
||||
return findValue(input);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidFlagFormat("Unknown value '" + input + "' in "
|
||||
throw new InvalidFlagFormatException("Unknown value '" + input + "' in "
|
||||
+ enumClass.getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -181,9 +181,9 @@ public abstract class Flag<T> {
|
|||
*
|
||||
* @param context the {@link FlagContext}
|
||||
* @return The coerced type
|
||||
* @throws InvalidFlagFormat Raised if the input is invalid
|
||||
* @throws InvalidFlagFormatException Raised if the input is invalid
|
||||
*/
|
||||
public abstract T parseInput(FlagContext context) throws InvalidFlagFormat;
|
||||
public abstract T parseInput(FlagContext context) throws InvalidFlagFormatException;
|
||||
|
||||
/**
|
||||
* Convert a raw type that was loaded (from a YAML file, for example)
|
||||
|
|
|
@ -27,7 +27,7 @@ import com.sk89q.worldguard.commands.CommandInputContext;
|
|||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FlagContext extends CommandInputContext<InvalidFlagFormat> {
|
||||
public final class FlagContext extends CommandInputContext<InvalidFlagFormatException> {
|
||||
|
||||
private FlagContext(Actor sender, String input, Map<String, Object> values) {
|
||||
super(sender, input, values);
|
||||
|
@ -59,8 +59,8 @@ public final class FlagContext extends CommandInputContext<InvalidFlagFormat> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected InvalidFlagFormat createException(String str) {
|
||||
return new InvalidFlagFormat(str);
|
||||
protected InvalidFlagFormatException createException(String str) {
|
||||
return new InvalidFlagFormatException(str);
|
||||
}
|
||||
|
||||
public static class FlagContextBuilder {
|
||||
|
|
|
@ -40,12 +40,12 @@ public class GameModeTypeFlag extends Flag<GameMode> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public GameMode parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public GameMode parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
input = input.trim();
|
||||
GameMode gamemode = unmarshal(input);
|
||||
if (gamemode == null) {
|
||||
throw new InvalidFlagFormat("Unknown game mode: " + input);
|
||||
throw new InvalidFlagFormatException("Unknown game mode: " + input);
|
||||
}
|
||||
return gamemode;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class IntegerFlag extends NumberFlag<Integer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Integer parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public Integer parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
return context.getUserInputAsInt();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
/**
|
||||
* @deprecated replaced by {@link InvalidFlagFormatException}. Will be removed in WorldGuard 8
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public class InvalidFlagFormat extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 8101615074524004172L;
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* WorldGuard, a suite of tools for Minecraft
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldGuard team and contributors
|
||||
*
|
||||
* 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
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldguard.protection.flags;
|
||||
|
||||
public class InvalidFlagFormatException extends InvalidFlagFormat {
|
||||
private static final long serialVersionUID = 8101615074524004172L;
|
||||
|
||||
public InvalidFlagFormatException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
|
@ -41,7 +41,7 @@ public class LocationFlag extends Flag<Location> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Location parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public Location parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
Player player = context.getPlayerSender();
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class LocationFlag extends Flag<Location> {
|
|||
player.printDebug("WARNING: Flag location is outside of region.");
|
||||
} else {
|
||||
// no permission
|
||||
throw new InvalidFlagFormat("You can't set that flag outside of the region boundaries.");
|
||||
throw new InvalidFlagFormatException("You can't set that flag outside of the region boundaries.");
|
||||
}
|
||||
}
|
||||
// clamp height to world limits
|
||||
|
@ -86,7 +86,7 @@ public class LocationFlag extends Flag<Location> {
|
|||
}
|
||||
return loc;
|
||||
}
|
||||
throw new InvalidFlagFormat("Expected 'here' or x,y,z.");
|
||||
throw new InvalidFlagFormatException("Expected 'here' or x,y,z.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -70,7 +70,7 @@ public class MapFlag<K, V> extends Flag<Map<K, V>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Map<K, V> parseInput(final FlagContext context) throws InvalidFlagFormat {
|
||||
public Map<K, V> parseInput(final FlagContext context) throws InvalidFlagFormatException {
|
||||
|
||||
final String input = context.getUserInput();
|
||||
if (input.isEmpty()) {
|
||||
|
@ -83,7 +83,7 @@ public class MapFlag<K, V> extends Flag<Map<K, V>> {
|
|||
final char split = str.indexOf('=') == -1 ? ':' : '=';
|
||||
final String[] keyVal = str.split(String.valueOf(split));
|
||||
if (keyVal.length != 2) {
|
||||
throw new InvalidFlagFormat("Input must be in a 'key:value,key1=value1' format. Either ':' or '=' can be used.");
|
||||
throw new InvalidFlagFormatException("Input must be in a 'key:value,key1=value1' format. Either ':' or '=' can be used.");
|
||||
}
|
||||
|
||||
final FlagContext key = context.copyWith(null, keyVal[0], null);
|
||||
|
|
|
@ -44,10 +44,10 @@ public class RegistryFlag<T extends Keyed> extends Flag<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public T parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public T parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
final String key = context.getUserInput().trim().toLowerCase(Locale.ROOT);
|
||||
return Optional.ofNullable(registry.get(key))
|
||||
.orElseThrow(() -> new InvalidFlagFormat("Unknown " + registry.getName() + ": " + key));
|
||||
.orElseThrow(() -> new InvalidFlagFormatException("Unknown " + registry.getName() + ": " + key));
|
||||
}
|
||||
|
||||
public Registry<T> getRegistry() {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class SetFlag<T> extends Flag<Set<T>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<T> parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public Set<T> parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
if (input.isEmpty()) {
|
||||
return Sets.newHashSet();
|
||||
|
|
|
@ -78,7 +78,7 @@ public class StateFlag extends Flag<StateFlag.State> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public State parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public State parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
|
||||
if (input.equalsIgnoreCase("allow")) {
|
||||
|
@ -88,7 +88,7 @@ public class StateFlag extends Flag<StateFlag.State> {
|
|||
} else if (input.equalsIgnoreCase("none")) {
|
||||
return null;
|
||||
} else {
|
||||
throw new InvalidFlagFormat("Expected none/allow/deny but got '" + input + "'");
|
||||
throw new InvalidFlagFormatException("Expected none/allow/deny but got '" + input + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class StringFlag extends Flag<String> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public String parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String lines = context.getUserInput().replaceAll("(?<!\\\\)\\\\n", "\n").replaceAll("\\\\\\\\n", "\\\\n");
|
||||
// Add color codes
|
||||
lines = CommandUtils.replaceColorMacros(lines);
|
||||
|
|
|
@ -48,7 +48,7 @@ public class TimestampFlag extends Flag<Instant> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Instant parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public Instant parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
if ("now".equalsIgnoreCase(input)) {
|
||||
return Instant.now();
|
||||
|
@ -61,10 +61,10 @@ public class TimestampFlag extends Flag<Instant> {
|
|||
} else if (parsed instanceof ZonedDateTime) {
|
||||
return ((ZonedDateTime) parsed).toInstant();
|
||||
} else {
|
||||
throw new InvalidFlagFormat("Unrecognized input.");
|
||||
throw new InvalidFlagFormatException("Unrecognized input.");
|
||||
}
|
||||
} catch (DateTimeParseException ignored) {
|
||||
throw new InvalidFlagFormat("Expected 'now' or ISO 8601 formatted input.");
|
||||
throw new InvalidFlagFormatException("Expected 'now' or ISO 8601 formatted input.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class UUIDFlag extends Flag<UUID> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public UUID parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public UUID parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
if ("self".equalsIgnoreCase(input)) {
|
||||
return context.getSender().getUniqueId();
|
||||
|
@ -41,7 +41,7 @@ public class UUIDFlag extends Flag<UUID> {
|
|||
try {
|
||||
return UUID.fromString(input);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new InvalidFlagFormat("Not a valid uuid: " + input);
|
||||
throw new InvalidFlagFormatException("Not a valid uuid: " + input);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ public class VectorFlag extends Flag<Vector3> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Vector3 parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public Vector3 parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
|
||||
if ("here".equalsIgnoreCase(input)) {
|
||||
|
@ -56,7 +56,7 @@ public class VectorFlag extends Flag<Vector3> {
|
|||
}
|
||||
}
|
||||
|
||||
throw new InvalidFlagFormat("Expected 'here' or x,y,z.");
|
||||
throw new InvalidFlagFormatException("Expected 'here' or x,y,z.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,12 +40,12 @@ public class WeatherTypeFlag extends Flag<WeatherType> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public WeatherType parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
public WeatherType parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
String input = context.getUserInput();
|
||||
input = input.trim();
|
||||
WeatherType weatherType = unmarshal(input);
|
||||
if (weatherType == null) {
|
||||
throw new InvalidFlagFormat("Unknown weather type: " + input);
|
||||
throw new InvalidFlagFormatException("Unknown weather type: " + input);
|
||||
}
|
||||
return weatherType;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ package com.sk89q.worldguard.protection.flags.registry;
|
|||
|
||||
import com.sk89q.worldguard.protection.flags.Flag;
|
||||
import com.sk89q.worldguard.protection.flags.FlagContext;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
|
||||
import com.sk89q.worldguard.protection.flags.InvalidFlagFormatException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -32,8 +32,8 @@ public class UnknownFlag extends Flag<Object> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object parseInput(FlagContext context) throws InvalidFlagFormat {
|
||||
throw new InvalidFlagFormat("The plugin that registered this flag is not currently installed");
|
||||
public Object parseInput(FlagContext context) throws InvalidFlagFormatException {
|
||||
throw new InvalidFlagFormatException("The plugin that registered this flag is not currently installed");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,7 @@ import com.sk89q.worldedit.internal.command.exception.ExceptionMatch;
|
|||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||
import com.sk89q.worldedit.util.formatting.component.InvalidComponentException;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.domains.registry.InvalidDomainFormat;
|
||||
import com.sk89q.worldguard.domains.registry.InvalidDomainFormatException;
|
||||
import com.sk89q.worldguard.protection.managers.storage.StorageException;
|
||||
import com.sk89q.worldguard.protection.util.UnresolvedNamesException;
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class WorldGuardExceptionConverter extends ExceptionConverterHelper {
|
|||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(InvalidDomainFormat e) throws CommandException {
|
||||
public void convert(InvalidDomainFormatException e) throws CommandException {
|
||||
throw newCommandException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue