SteamWar/SpigotCore
Archiviert
13
0

Remove SWCommand.register method

Add SWCommand.Register annotation
Dieser Commit ist enthalten in:
yoyosource 2021-03-12 16:30:40 +01:00
Ursprung b3c4c45892
Commit ce7d261174
3 geänderte Dateien mit 18 neuen und 39 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,10 @@ package de.steamwar.command;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.*;
@ -57,14 +61,9 @@ public abstract class SWCommand {
return strings;
}
});
}
protected final void register(String methodName) {
if (methodName.equals("onCommand")) return;
if (methodName.equals("onTabComplete")) return;
Method[] methods = this.getClass().getDeclaredMethods();
for (Method method : methods) {
if (!validMethod(method)) continue;
for (Method method : getClass().getDeclaredMethods()) {
if (method.getDeclaredAnnotation(Register.class) == null || !validMethod(method)) continue;
if (method.getReturnType() == Void.TYPE) {
commandSet.add(new InternalCommand(this, method));
}
@ -101,4 +100,15 @@ public abstract class SWCommand {
helpMessage.accept(sender);
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
protected @interface Register {
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
@interface StringConstraint {
String constraint();
}
}

Datei anzeigen

@ -91,7 +91,7 @@ class SWCommandUtils {
Parameter parameter = parameters[i];
Class<?> clazz = parameters[i].getType();
arguments[i] = mapper(clazz).apply(args[i - 1]);
StringConstraint stringConstraint = parameter.getAnnotation(StringConstraint.class);
SWCommand.StringConstraint stringConstraint = parameter.getAnnotation(SWCommand.StringConstraint.class);
if (stringConstraint != null && !Objects.equals(arguments[i], stringConstraint.constraint())) {
throw new SecurityException();
}

Datei anzeigen

@ -1,31 +0,0 @@
/*
* 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();
}