SteamWar/SpigotCore
Archiviert
13
0

CommandFramework3 #94

Manuell gemergt
Zeanon hat 71 Commits von CommandFramework3 nach master 2021-03-30 21:15:40 +02:00 zusammengeführt
2 geänderte Dateien mit 10 neuen und 15 gelöschten Zeilen
Nur Änderungen aus Commit 03d35042e3 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -79,9 +79,7 @@ public abstract class SWCommand {
if (!CommandSender.class.isAssignableFrom(parameters[0].getType())) return false;
for (int i = 1; i < parameters.length; i++) {
Parameter parameter = parameters[i];
StringConstraint stringConstraint = parameter.getAnnotation(StringConstraint.class);
Class<?> clazz = parameter.getType();
if (stringConstraint != null && clazz != String.class) return false;
if (parameter.isVarArgs() && i == parameters.length - 1) {
clazz = parameter.getType().getComponentType();
}
@ -103,12 +101,7 @@ public abstract class SWCommand {
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
protected @interface Register {
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@interface StringConstraint {
String constraint();
String[] subCommand() default {};
}
}

Datei anzeigen

@ -25,6 +25,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.*;
import java.util.function.BiFunction;
@ -78,7 +79,7 @@ class SWCommandUtils {
}
}
public static Object[] generateArgumentArray(CommandSender commandSender, Parameter[] parameters, String[] args) {
public static Object[] generateArgumentArray(CommandSender commandSender, Method method, Parameter[] parameters, String[] args) {
Object[] arguments = new Object[args.length + 1];
boolean varArgs = false;
if (parameters[parameters.length - 1].isVarArgs()) {
@ -87,14 +88,15 @@ class SWCommandUtils {
}
arguments[0] = parameters[0].getType().cast(commandSender);
for (int i = 1; i < parameters.length - (varArgs ? 1 : 0); i++) {
Parameter parameter = parameters[i];
SWCommand.Register register = method.getAnnotation(SWCommand.Register.class);
int subCommandIndex = 1;
for (String s : register.subCommand()) {
if (!args[subCommandIndex++].equals(s)) throw new SecurityException();
}
for (int i = subCommandIndex; i < parameters.length - (varArgs ? 1 : 0); i++) {
Class<?> clazz = parameters[i].getType();
arguments[i] = mapper(clazz).apply(args[i - 1]);
SWCommand.StringConstraint stringConstraint = parameter.getAnnotation(SWCommand.StringConstraint.class);
if (stringConstraint != null && !Objects.equals(arguments[i], stringConstraint.constraint())) {
throw new SecurityException();
}
}
if (varArgs) {