Skip to content

Commit

Permalink
feat: 添加KookPermission注解
Browse files Browse the repository at this point in the history
  • Loading branch information
huanmeng-qwq committed Oct 20, 2024
1 parent 1916076 commit 2ae5d55
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -76,6 +77,7 @@ public static <B extends LiteCommandsBaseBuilder<CommandSender, LiteKookSettings
LiteAnnotationsProcessorExtension<CommandSender> 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()))
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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<br>
* KookBC<br>
*
* @author huanmeng_qwq
*/
public class KookPermissionAnnotationResolver<SENDER> implements AnnotationProcessor<SENDER> {
@Override
public AnnotationInvoker<SENDER> process(AnnotationInvoker<SENDER> 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();
});
}
}

0 comments on commit 2ae5d55

Please sign in to comment.