diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 5c31b83..d871838 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -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(); + } + } diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index c225205..6434dc8 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -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(); } diff --git a/SpigotCore_Main/src/de/steamwar/command/StringConstraint.java b/SpigotCore_Main/src/de/steamwar/command/StringConstraint.java deleted file mode 100644 index 368ad18..0000000 --- a/SpigotCore_Main/src/de/steamwar/command/StringConstraint.java +++ /dev/null @@ -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 . - */ - -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(); -}