From 10f8bc164afc515551cd76733f7445716741e433 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 7 Jan 2017 16:54:19 -0500 Subject: [PATCH] move sneaky into command util --- commands.iml | 5 ++- .../java/co/aikar/commands/BaseCommand.java | 2 +- .../java/co/aikar/commands/CommandUtil.java | 10 +++++ .../co/aikar/commands/RegisteredCommand.java | 2 +- .../java/co/aikar/commands/SneakyThrow.java | 39 ------------------- .../commands/contexts/CommandContexts.java | 3 +- 6 files changed, 16 insertions(+), 45 deletions(-) delete mode 100644 src/main/java/co/aikar/commands/SneakyThrow.java diff --git a/commands.iml b/commands.iml index 7c851e11..a4adc74c 100644 --- a/commands.iml +++ b/commands.iml @@ -12,17 +12,18 @@ - + + - + \ No newline at end of file diff --git a/src/main/java/co/aikar/commands/BaseCommand.java b/src/main/java/co/aikar/commands/BaseCommand.java index df283447..b7591b14 100644 --- a/src/main/java/co/aikar/commands/BaseCommand.java +++ b/src/main/java/co/aikar/commands/BaseCommand.java @@ -97,7 +97,7 @@ public abstract class BaseCommand extends Command { registerSubcommand(method, "__default"); foundDefault = true; } else { - SneakyThrow.sneaky(new InvalidConfigurationException("Multiple @Default commands")); + CommandUtil.sneaky(new InvalidConfigurationException("Multiple @Default commands")); } } if (sub != null) { diff --git a/src/main/java/co/aikar/commands/CommandUtil.java b/src/main/java/co/aikar/commands/CommandUtil.java index 17b7ff16..9a076cd4 100644 --- a/src/main/java/co/aikar/commands/CommandUtil.java +++ b/src/main/java/co/aikar/commands/CommandUtil.java @@ -852,4 +852,14 @@ public final class CommandUtil { public static boolean isValidName(String name) { return name != null && !name.isEmpty() && CommandPatterns.VALID_NAME_PATTERN.matcher(name).matches(); } + + public static void sneaky(Throwable t) + { + throw CommandUtil.superSneaky( t ); + } + + private static T superSneaky(Throwable t) throws T + { + throw (T) t; + } } diff --git a/src/main/java/co/aikar/commands/RegisteredCommand.java b/src/main/java/co/aikar/commands/RegisteredCommand.java index 22b85d73..fd50f72b 100644 --- a/src/main/java/co/aikar/commands/RegisteredCommand.java +++ b/src/main/java/co/aikar/commands/RegisteredCommand.java @@ -103,7 +103,7 @@ public class RegisteredCommand { } } } else { - SneakyThrow.sneaky(new InvalidConfigurationException( + CommandUtil.sneaky(new InvalidConfigurationException( "Parameter " + type.getSimpleName() + " of " + this.command + " has no resolver" )); } diff --git a/src/main/java/co/aikar/commands/SneakyThrow.java b/src/main/java/co/aikar/commands/SneakyThrow.java deleted file mode 100644 index 04807c38..00000000 --- a/src/main/java/co/aikar/commands/SneakyThrow.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package co.aikar.commands; - -public class SneakyThrow -{ - - public static void sneaky(Throwable t) - { - throw SneakyThrow.superSneaky( t ); - } - - private static T superSneaky(Throwable t) throws T - { - throw (T) t; - } -} - diff --git a/src/main/java/co/aikar/commands/contexts/CommandContexts.java b/src/main/java/co/aikar/commands/contexts/CommandContexts.java index afd363be..1d367c50 100644 --- a/src/main/java/co/aikar/commands/contexts/CommandContexts.java +++ b/src/main/java/co/aikar/commands/contexts/CommandContexts.java @@ -30,7 +30,6 @@ import co.aikar.commands.annotation.Optional; import co.aikar.commands.annotation.Values; import co.aikar.commands.CommandLog; import co.aikar.commands.CommandPatterns; -import co.aikar.commands.SneakyThrow; import co.aikar.commands.CommandUtil; import com.google.common.collect.Maps; import org.bukkit.Bukkit; @@ -112,7 +111,7 @@ public final class CommandContexts { } return CommandPatterns.getPattern(split.value()).split(val); } else if (!c.isLastArg()) { - SneakyThrow.sneaky(new InvalidConfigurationException("Weird Command signature... String[] should be last or @Split")); + CommandUtil.sneaky(new InvalidConfigurationException("Weird Command signature... String[] should be last or @Split")); } String[] result = c.getArgs().toArray(new String[c.getArgs().size()]);