CommandFramework3 #94
42
SpigotCore_Main/src/de/steamwar/command/CommandParseException.java
Normale Datei
42
SpigotCore_Main/src/de/steamwar/command/CommandParseException.java
Normale Datei
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Ich denke mal, das throw new SecurityException aus der Zeile drüber wäre auch angebracht. Auf jeden Fall für "RuntimeException".