From 2bb7a435c3ef2a4ea7856e3f3752e11c13791460 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 30 Mar 2021 14:06:54 +0200 Subject: [PATCH] Add CommandParseException (Workflow Exception) --- .../command/CommandParseException.java | 42 +++++++++++++++++++ .../de/steamwar/command/SWCommandUtils.java | 6 +-- .../src/de/steamwar/command/SubCommand.java | 4 ++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 SpigotCore_Main/src/de/steamwar/command/CommandParseException.java diff --git a/SpigotCore_Main/src/de/steamwar/command/CommandParseException.java b/SpigotCore_Main/src/de/steamwar/command/CommandParseException.java new file mode 100644 index 0000000..b47cace --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/command/CommandParseException.java @@ -0,0 +1,42 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.command; + +public class CommandParseException extends Exception { + + public CommandParseException() { + } + + public CommandParseException(String message) { + super(message); + } + + public CommandParseException(String message, Throwable cause) { + super(message, cause); + } + + public CommandParseException(Throwable cause) { + super(cause); + } + + public CommandParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index b8c2c8c..e3b499a 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -99,12 +99,12 @@ public class SWCommandUtils { } } - static Object[] generateArgumentArray(TypeMapper[] parameters, String[] args, boolean varArgs, String[] subCommand) { + static Object[] generateArgumentArray(TypeMapper[] parameters, String[] args, boolean varArgs, String[] subCommand) throws CommandParseException { Object[] arguments = new Object[parameters.length + 1]; int index = 0; while (index < subCommand.length) { if (!args[index].equals(subCommand[index])) { - throw new SecurityException(); + throw new CommandParseException(); } index++; } @@ -112,7 +112,7 @@ public class SWCommandUtils { for (int i = 0; i < parameters.length - (varArgs ? 1 : 0); i++) { arguments[i + 1] = parameters[i].map(args[index++]); if (arguments[i + 1] == null) { - throw new SecurityException(); + throw new CommandParseException(); } } diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index f299359..1d23505 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -19,6 +19,7 @@ package de.steamwar.command; +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import java.lang.reflect.InvocationTargetException; @@ -26,6 +27,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.*; import java.util.function.Function; +import java.util.logging.Level; class SubCommand { @@ -94,6 +96,8 @@ class SubCommand { method.invoke(swCommand, objects); } catch (IllegalAccessException | RuntimeException | InvocationTargetException e) { throw new SecurityException(e.getMessage(), e); + } catch (CommandParseException e) { + return false; } return true; }