CommandFramework3 #94
@ -80,7 +80,9 @@ 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();
|
||||
}
|
||||
|
@ -26,10 +26,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
@ -91,8 +88,13 @@ class SWCommandUtils {
|
||||
arguments[0] = parameters[0].getType().cast(commandSender);
|
||||
|
||||
for (int i = 1; i < parameters.length - (varArgs ? 1 : 0); i++) {
|
||||
Parameter parameter = parameters[i];
|
||||
Class<?> clazz = parameters[i].getType();
|
||||
arguments[i] = mapper(clazz).apply(args[i - 1]);
|
||||
StringConstraint stringConstraint = parameter.getAnnotation(StringConstraint.class);
|
||||
if (stringConstraint != null && !Objects.equals(arguments[i], stringConstraint.constraint())) {
|
||||
throw new SecurityException();
|
||||
}
|
||||
}
|
||||
|
||||
if (varArgs) {
|
||||
|
31
SpigotCore_Main/src/de/steamwar/command/StringConstraint.java
Normale Datei
31
SpigotCore_Main/src/de/steamwar/command/StringConstraint.java
Normale Datei
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER})
|
||||
public @interface StringConstraint {
|
||||
String constraint();
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren