Remove SWCommand.register method
Add SWCommand.Register annotation
Dieser Commit ist enthalten in:
Ursprung
b3c4c45892
Commit
ce7d261174
@ -22,6 +22,10 @@ package de.steamwar.command;
|
|||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
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.Method;
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -57,14 +61,9 @@ public abstract class SWCommand {
|
|||||||
return strings;
|
return strings;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
protected final void register(String methodName) {
|
for (Method method : getClass().getDeclaredMethods()) {
|
||||||
if (methodName.equals("onCommand")) return;
|
if (method.getDeclaredAnnotation(Register.class) == null || !validMethod(method)) continue;
|
||||||
if (methodName.equals("onTabComplete")) return;
|
|
||||||
Method[] methods = this.getClass().getDeclaredMethods();
|
|
||||||
for (Method method : methods) {
|
|
||||||
if (!validMethod(method)) continue;
|
|
||||||
if (method.getReturnType() == Void.TYPE) {
|
if (method.getReturnType() == Void.TYPE) {
|
||||||
commandSet.add(new InternalCommand(this, method));
|
commandSet.add(new InternalCommand(this, method));
|
||||||
}
|
}
|
||||||
@ -101,4 +100,15 @@ public abstract class SWCommand {
|
|||||||
helpMessage.accept(sender);
|
helpMessage.accept(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.METHOD})
|
||||||
|
protected @interface Register {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.PARAMETER})
|
||||||
|
@interface StringConstraint {
|
||||||
|
String constraint();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ class SWCommandUtils {
|
|||||||
Parameter parameter = parameters[i];
|
Parameter parameter = parameters[i];
|
||||||
Class<?> clazz = parameters[i].getType();
|
Class<?> clazz = parameters[i].getType();
|
||||||
arguments[i] = mapper(clazz).apply(args[i - 1]);
|
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())) {
|
if (stringConstraint != null && !Objects.equals(arguments[i], stringConstraint.constraint())) {
|
||||||
throw new SecurityException();
|
throw new SecurityException();
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
In neuem Issue referenzieren
Einen Benutzer sperren