From 2ae5d55b09be0125e09c50201326334863cd22fa Mon Sep 17 00:00:00 2001 From: huanmeng-qwq <1871735932@qq.com> Date: Mon, 21 Oct 2024 02:30:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0KookPermission?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../command/litecommands/LiteKookFactory.java | 2 ++ .../permission/KookPermission.java | 14 ++++++++++ .../KookPermissionAnnotationResolver.java | 26 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermission.java create mode 100644 src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermissionAnnotationResolver.java diff --git a/src/main/java/snw/kookbc/impl/command/litecommands/LiteKookFactory.java b/src/main/java/snw/kookbc/impl/command/litecommands/LiteKookFactory.java index d0071b24..53cc95a8 100644 --- a/src/main/java/snw/kookbc/impl/command/litecommands/LiteKookFactory.java +++ b/src/main/java/snw/kookbc/impl/command/litecommands/LiteKookFactory.java @@ -44,6 +44,7 @@ import snw.kookbc.impl.CoreImpl; import snw.kookbc.impl.KBCClient; import snw.kookbc.impl.command.CommandManagerImpl; +import snw.kookbc.impl.command.litecommands.annotations.permission.KookPermissionAnnotationResolver; import snw.kookbc.impl.command.litecommands.annotations.prefix.PrefixAnnotationResolver; import snw.kookbc.impl.command.litecommands.annotations.result.ResultAnnotationResolver; import snw.kookbc.impl.command.litecommands.argument.*; @@ -76,6 +77,7 @@ public static processorExtension = new LiteAnnotationsProcessorExtension<>(); processorExtension .processor(new PrefixAnnotationResolver<>()) + .processor(new KookPermissionAnnotationResolver<>()) .processor(new ResultAnnotationResolver<>(plugin.getLogger())); return (B) LiteCommandsFactory.builder(CommandSender.class, new KookLitePlatform(liteKookSettings, plugin, ((CommandManagerImpl) plugin.getCore().getCommandManager()).getCommandMap())) diff --git a/src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermission.java b/src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermission.java new file mode 100644 index 00000000..7fd644a0 --- /dev/null +++ b/src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermission.java @@ -0,0 +1,14 @@ +package snw.kookbc.impl.command.litecommands.annotations.permission; + +import snw.jkook.Permission; + +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.TYPE, ElementType.METHOD}) +public @interface KookPermission { + Permission[] value(); +} diff --git a/src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermissionAnnotationResolver.java b/src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermissionAnnotationResolver.java new file mode 100644 index 00000000..09129237 --- /dev/null +++ b/src/main/java/snw/kookbc/impl/command/litecommands/annotations/permission/KookPermissionAnnotationResolver.java @@ -0,0 +1,26 @@ +package snw.kookbc.impl.command.litecommands.annotations.permission; + +import dev.rollczi.litecommands.annotations.AnnotationInvoker; +import dev.rollczi.litecommands.annotations.AnnotationProcessor; +import dev.rollczi.litecommands.meta.Meta; +import snw.jkook.permissions.Permissions; + +import java.util.Arrays; +import java.util.stream.Collectors; + +/** + * 2024/10/21
+ * KookBC
+ * + * @author huanmeng_qwq + */ +public class KookPermissionAnnotationResolver implements AnnotationProcessor { + @Override + public AnnotationInvoker process(AnnotationInvoker invoker) { + return invoker.on(KookPermission.class, (annotation, metaHolder) -> { + metaHolder.meta().listEditor(Meta.PERMISSIONS) + .addAll(Arrays.stream(annotation.value()).map(Permissions::getPermission).collect(Collectors.toList())) + .apply(); + }); + } +}