🎨 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.
This commit is contained in:
Alexander Söderberg 2020-10-04 13:50:15 +02:00
parent a8b2b9a608
commit 0fefd40812
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
3 changed files with 50 additions and 9 deletions

View file

@ -203,8 +203,11 @@ public final class AnnotationParser<C> {
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) {

View file

@ -42,13 +42,6 @@ public @interface CommandMethod {
*/
String value();
/**
* The command permission node
*
* @return Command permission node
*/
String permission() default "";
/**
* The required sender
*

View file

@ -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 "";
}