From 0fefd4081248a7ee4b97b24a65f8594e0f57a954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sun, 4 Oct 2020 13:50:15 +0200 Subject: [PATCH] :art: Create separate annotation for command permissions This allows for compound annotation creation. Though this will need additional changes made to the annotation parser to actually take effect. --- .../annotations/AnnotationParser.java | 7 ++- .../annotations/CommandMethod.java | 7 --- .../annotations/CommandPermission.java | 45 +++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java index 137f7467..55426ec3 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/AnnotationParser.java @@ -203,8 +203,11 @@ public final class AnnotationParser { break; } } - /* Decorate command data */ - builder = builder.withPermission(commandMethod.permission()); + + if (method.isAnnotationPresent(CommandPermission.class)) { + builder = builder.withPermission(method.getAnnotation(CommandPermission.class).value()); + } + if (commandMethod.requiredSender() != Object.class) { builder = builder.withSenderType(commandMethod.requiredSender()); } else if (senderType != null) { diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java index c38903f1..69baf09d 100644 --- a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandMethod.java @@ -42,13 +42,6 @@ public @interface CommandMethod { */ String value(); - /** - * The command permission node - * - * @return Command permission node - */ - String permission() default ""; - /** * The required sender * diff --git a/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java new file mode 100644 index 00000000..0cf82cd7 --- /dev/null +++ b/cloud-annotations/src/main/java/cloud/commandframework/annotations/CommandPermission.java @@ -0,0 +1,45 @@ +// +// MIT License +// +// Copyright (c) 2020 Alexander Söderberg & Contributors +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +package cloud.commandframework.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Equivalent to {@link cloud.commandframework.Command.Builder#withPermission(String)} + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandPermission { + + /** + * Get the command permission + * + * @return Command permission + */ + String value() default ""; + +}