12
0

Add CommandParseException (Workflow Exception)

Dieser Commit ist enthalten in:
yoyosource 2021-03-30 14:06:54 +02:00
Ursprung 501803b05c
Commit 2bb7a435c3
3 geänderte Dateien mit 49 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

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

Datei anzeigen

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