Renamed InvalidFlagFormat to InvalidFlagFormatException

This commit is contained in:
Joo200 2023-01-22 12:06:05 +01:00
parent 8d5953a550
commit bb3fdcc880
26 changed files with 79 additions and 52 deletions

View File

@ -21,7 +21,6 @@ package com.sk89q.worldguard.commands;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map; import java.util.Map;

View File

@ -59,7 +59,7 @@ import com.sk89q.worldguard.protection.FlagValueCalculator;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext; import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.Flags; 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.RegionGroup;
import com.sk89q.worldguard.protection.flags.RegionGroupFlag; import com.sk89q.worldguard.protection.flags.RegionGroupFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
@ -587,7 +587,7 @@ public final class RegionCommands extends RegionCommandsBase {
// the [value] part throws an error. // the [value] part throws an error.
try { try {
groupValue = groupFlag.parseInput(FlagContext.create().setSender(sender).setInput(group).setObject("region", existing).build()); groupValue = groupFlag.parseInput(FlagContext.create().setSender(sender).setInput(group).setObject("region", existing).build());
} catch (InvalidFlagFormat e) { } catch (InvalidFlagFormatException e) {
throw new CommandException(e.getMessage()); 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 // Set the flag if [value] was given even if [-g group] was given as well
try { try {
value = setFlag(existing, foundFlag, sender, value).toString(); value = setFlag(existing, foundFlag, sender, value).toString();
} catch (InvalidFlagFormat e) { } catch (InvalidFlagFormatException e) {
throw new CommandException(e.getMessage()); throw new CommandException(e.getMessage());
} }

View File

@ -41,15 +41,11 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard; 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.internal.permission.RegionPermissionModel;
import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext; 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.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion; import com.sk89q.worldguard.protection.regions.GlobalProtectedRegion;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
@ -419,9 +415,9 @@ class RegionCommandsBase {
* @param flag the flag * @param flag the flag
* @param sender the sender * @param sender the sender
* @param value the value * @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()); V val = flag.parseInput(FlagContext.create().setSender(sender).setInput(value).setObject("region", region).build());
region.setFlag(flag, val); region.setFlag(flag, val);
return val; return val;

View File

@ -33,7 +33,7 @@ public class BooleanFlag extends Flag<Boolean> {
} }
@Override @Override
public Boolean parseInput(FlagContext context) throws InvalidFlagFormat { public Boolean parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
if (input.equalsIgnoreCase("true") || input.equalsIgnoreCase("yes") if (input.equalsIgnoreCase("true") || input.equalsIgnoreCase("yes")
@ -45,7 +45,7 @@ public class BooleanFlag extends Flag<Boolean> {
|| input.equalsIgnoreCase("0")) { || input.equalsIgnoreCase("0")) {
return false; return false;
} else { } else {
throw new InvalidFlagFormat("Not a yes/no value: " + input); throw new InvalidFlagFormatException("Not a yes/no value: " + input);
} }
} }

View File

@ -33,7 +33,7 @@ public class CommandStringFlag extends Flag<String> {
} }
@Override @Override
public String parseInput(FlagContext context) throws InvalidFlagFormat { public String parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
input = input.trim(); input = input.trim();
if (!input.startsWith("/")) { if (!input.startsWith("/")) {

View File

@ -33,7 +33,7 @@ public class DoubleFlag extends NumberFlag<Double> {
} }
@Override @Override
public Double parseInput(FlagContext context) throws InvalidFlagFormat { public Double parseInput(FlagContext context) throws InvalidFlagFormatException {
return context.getUserInputAsDouble(); return context.getUserInputAsDouble();
} }

View File

@ -40,12 +40,12 @@ public class EntityTypeFlag extends Flag<EntityType> {
} }
@Override @Override
public EntityType parseInput(FlagContext context) throws InvalidFlagFormat { public EntityType parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
input = input.trim(); input = input.trim();
EntityType entityType = unmarshal(input); EntityType entityType = unmarshal(input);
if (entityType == null) { if (entityType == null) {
throw new InvalidFlagFormat("Unknown entity type: " + input); throw new InvalidFlagFormatException("Unknown entity type: " + input);
} }
return entityType; return entityType;
} }

View File

@ -74,12 +74,12 @@ public class EnumFlag<T extends Enum<T>> extends Flag<T> {
} }
@Override @Override
public T parseInput(FlagContext context) throws InvalidFlagFormat { public T parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
try { try {
return findValue(input); return findValue(input);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new InvalidFlagFormat("Unknown value '" + input + "' in " throw new InvalidFlagFormatException("Unknown value '" + input + "' in "
+ enumClass.getName()); + enumClass.getName());
} }
} }

View File

@ -181,9 +181,9 @@ public abstract class Flag<T> {
* *
* @param context the {@link FlagContext} * @param context the {@link FlagContext}
* @return The coerced type * @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) * Convert a raw type that was loaded (from a YAML file, for example)

View File

@ -27,7 +27,7 @@ import com.sk89q.worldguard.commands.CommandInputContext;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Map; 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) { private FlagContext(Actor sender, String input, Map<String, Object> values) {
super(sender, input, values); super(sender, input, values);
@ -59,8 +59,8 @@ public final class FlagContext extends CommandInputContext<InvalidFlagFormat> {
} }
@Override @Override
protected InvalidFlagFormat createException(String str) { protected InvalidFlagFormatException createException(String str) {
return new InvalidFlagFormat(str); return new InvalidFlagFormatException(str);
} }
public static class FlagContextBuilder { public static class FlagContextBuilder {

View File

@ -40,12 +40,12 @@ public class GameModeTypeFlag extends Flag<GameMode> {
} }
@Override @Override
public GameMode parseInput(FlagContext context) throws InvalidFlagFormat { public GameMode parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
input = input.trim(); input = input.trim();
GameMode gamemode = unmarshal(input); GameMode gamemode = unmarshal(input);
if (gamemode == null) { if (gamemode == null) {
throw new InvalidFlagFormat("Unknown game mode: " + input); throw new InvalidFlagFormatException("Unknown game mode: " + input);
} }
return gamemode; return gamemode;
} }

View File

@ -33,7 +33,7 @@ public class IntegerFlag extends NumberFlag<Integer> {
} }
@Override @Override
public Integer parseInput(FlagContext context) throws InvalidFlagFormat { public Integer parseInput(FlagContext context) throws InvalidFlagFormatException {
return context.getUserInputAsInt(); return context.getUserInputAsInt();
} }

View File

@ -19,6 +19,10 @@
package com.sk89q.worldguard.protection.flags; 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 { public class InvalidFlagFormat extends Exception {
private static final long serialVersionUID = 8101615074524004172L; private static final long serialVersionUID = 8101615074524004172L;

View File

@ -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);
}
}

View File

@ -41,7 +41,7 @@ public class LocationFlag extends Flag<Location> {
} }
@Override @Override
public Location parseInput(FlagContext context) throws InvalidFlagFormat { public Location parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
Player player = context.getPlayerSender(); Player player = context.getPlayerSender();
@ -76,7 +76,7 @@ public class LocationFlag extends Flag<Location> {
player.printDebug("WARNING: Flag location is outside of region."); player.printDebug("WARNING: Flag location is outside of region.");
} else { } else {
// no permission // 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 // clamp height to world limits
@ -86,7 +86,7 @@ public class LocationFlag extends Flag<Location> {
} }
return loc; return loc;
} }
throw new InvalidFlagFormat("Expected 'here' or x,y,z."); throw new InvalidFlagFormatException("Expected 'here' or x,y,z.");
} }
@Override @Override

View File

@ -70,7 +70,7 @@ public class MapFlag<K, V> extends Flag<Map<K, V>> {
} }
@Override @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(); final String input = context.getUserInput();
if (input.isEmpty()) { if (input.isEmpty()) {
@ -83,7 +83,7 @@ public class MapFlag<K, V> extends Flag<Map<K, V>> {
final char split = str.indexOf('=') == -1 ? ':' : '='; final char split = str.indexOf('=') == -1 ? ':' : '=';
final String[] keyVal = str.split(String.valueOf(split)); final String[] keyVal = str.split(String.valueOf(split));
if (keyVal.length != 2) { 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); final FlagContext key = context.copyWith(null, keyVal[0], null);

View File

@ -44,10 +44,10 @@ public class RegistryFlag<T extends Keyed> extends Flag<T> {
} }
@Override @Override
public T parseInput(FlagContext context) throws InvalidFlagFormat { public T parseInput(FlagContext context) throws InvalidFlagFormatException {
final String key = context.getUserInput().trim().toLowerCase(Locale.ROOT); final String key = context.getUserInput().trim().toLowerCase(Locale.ROOT);
return Optional.ofNullable(registry.get(key)) return Optional.ofNullable(registry.get(key))
.orElseThrow(() -> new InvalidFlagFormat("Unknown " + registry.getName() + ": " + key)); .orElseThrow(() -> new InvalidFlagFormatException("Unknown " + registry.getName() + ": " + key));
} }
public Registry<T> getRegistry() { public Registry<T> getRegistry() {

View File

@ -58,7 +58,7 @@ public class SetFlag<T> extends Flag<Set<T>> {
} }
@Override @Override
public Set<T> parseInput(FlagContext context) throws InvalidFlagFormat { public Set<T> parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
if (input.isEmpty()) { if (input.isEmpty()) {
return Sets.newHashSet(); return Sets.newHashSet();

View File

@ -78,7 +78,7 @@ public class StateFlag extends Flag<StateFlag.State> {
} }
@Override @Override
public State parseInput(FlagContext context) throws InvalidFlagFormat { public State parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
if (input.equalsIgnoreCase("allow")) { if (input.equalsIgnoreCase("allow")) {
@ -88,7 +88,7 @@ public class StateFlag extends Flag<StateFlag.State> {
} else if (input.equalsIgnoreCase("none")) { } else if (input.equalsIgnoreCase("none")) {
return null; return null;
} else { } else {
throw new InvalidFlagFormat("Expected none/allow/deny but got '" + input + "'"); throw new InvalidFlagFormatException("Expected none/allow/deny but got '" + input + "'");
} }
} }

View File

@ -57,7 +57,7 @@ public class StringFlag extends Flag<String> {
} }
@Override @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"); String lines = context.getUserInput().replaceAll("(?<!\\\\)\\\\n", "\n").replaceAll("\\\\\\\\n", "\\\\n");
// Add color codes // Add color codes
lines = CommandUtils.replaceColorMacros(lines); lines = CommandUtils.replaceColorMacros(lines);

View File

@ -48,7 +48,7 @@ public class TimestampFlag extends Flag<Instant> {
} }
@Override @Override
public Instant parseInput(FlagContext context) throws InvalidFlagFormat { public Instant parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
if ("now".equalsIgnoreCase(input)) { if ("now".equalsIgnoreCase(input)) {
return Instant.now(); return Instant.now();
@ -61,10 +61,10 @@ public class TimestampFlag extends Flag<Instant> {
} else if (parsed instanceof ZonedDateTime) { } else if (parsed instanceof ZonedDateTime) {
return ((ZonedDateTime) parsed).toInstant(); return ((ZonedDateTime) parsed).toInstant();
} else { } else {
throw new InvalidFlagFormat("Unrecognized input."); throw new InvalidFlagFormatException("Unrecognized input.");
} }
} catch (DateTimeParseException ignored) { } catch (DateTimeParseException ignored) {
throw new InvalidFlagFormat("Expected 'now' or ISO 8601 formatted input."); throw new InvalidFlagFormatException("Expected 'now' or ISO 8601 formatted input.");
} }
} }
} }

View File

@ -33,7 +33,7 @@ public class UUIDFlag extends Flag<UUID> {
} }
@Override @Override
public UUID parseInput(FlagContext context) throws InvalidFlagFormat { public UUID parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
if ("self".equalsIgnoreCase(input)) { if ("self".equalsIgnoreCase(input)) {
return context.getSender().getUniqueId(); return context.getSender().getUniqueId();
@ -41,7 +41,7 @@ public class UUIDFlag extends Flag<UUID> {
try { try {
return UUID.fromString(input); return UUID.fromString(input);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new InvalidFlagFormat("Not a valid uuid: " + input); throw new InvalidFlagFormatException("Not a valid uuid: " + input);
} }
} }

View File

@ -38,7 +38,7 @@ public class VectorFlag extends Flag<Vector3> {
} }
@Override @Override
public Vector3 parseInput(FlagContext context) throws InvalidFlagFormat { public Vector3 parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
if ("here".equalsIgnoreCase(input)) { 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.");
} }
} }

View File

@ -40,12 +40,12 @@ public class WeatherTypeFlag extends Flag<WeatherType> {
} }
@Override @Override
public WeatherType parseInput(FlagContext context) throws InvalidFlagFormat { public WeatherType parseInput(FlagContext context) throws InvalidFlagFormatException {
String input = context.getUserInput(); String input = context.getUserInput();
input = input.trim(); input = input.trim();
WeatherType weatherType = unmarshal(input); WeatherType weatherType = unmarshal(input);
if (weatherType == null) { if (weatherType == null) {
throw new InvalidFlagFormat("Unknown weather type: " + input); throw new InvalidFlagFormatException("Unknown weather type: " + input);
} }
return weatherType; return weatherType;
} }

View File

@ -21,7 +21,7 @@ package com.sk89q.worldguard.protection.flags.registry;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext; 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; import javax.annotation.Nullable;
@ -32,8 +32,8 @@ public class UnknownFlag extends Flag<Object> {
} }
@Override @Override
public Object parseInput(FlagContext context) throws InvalidFlagFormat { public Object parseInput(FlagContext context) throws InvalidFlagFormatException {
throw new InvalidFlagFormat("The plugin that registered this flag is not currently installed"); throw new InvalidFlagFormatException("The plugin that registered this flag is not currently installed");
} }
@Override @Override

View File

@ -26,7 +26,7 @@ import com.sk89q.worldedit.internal.command.exception.ExceptionMatch;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.util.formatting.component.InvalidComponentException; import com.sk89q.worldedit.util.formatting.component.InvalidComponentException;
import com.sk89q.worldguard.WorldGuard; 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.managers.storage.StorageException;
import com.sk89q.worldguard.protection.util.UnresolvedNamesException; import com.sk89q.worldguard.protection.util.UnresolvedNamesException;
@ -93,7 +93,7 @@ public class WorldGuardExceptionConverter extends ExceptionConverterHelper {
} }
@ExceptionMatch @ExceptionMatch
public void convert(InvalidDomainFormat e) throws CommandException { public void convert(InvalidDomainFormatException e) throws CommandException {
throw newCommandException(e.getMessage(), e); throw newCommandException(e.getMessage(), e);
} }