From b904373652a3a717b2e617a615d49ae4568076bf Mon Sep 17 00:00:00 2001 From: Shindou Date: Sat, 5 Mar 2022 14:56:34 +0800 Subject: [PATCH] Fix common interceptors not found issue --- .../java/pw/mihou/nexus/core/NexusCore.java | 3 +++ .../commons/NexusCommonInterceptors.java | 20 -------------- .../core/NexusCommonInterceptorsCore.java | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 src/main/java/pw/mihou/nexus/features/command/interceptors/commons/core/NexusCommonInterceptorsCore.java diff --git a/src/main/java/pw/mihou/nexus/core/NexusCore.java b/src/main/java/pw/mihou/nexus/core/NexusCore.java index 85f481e1..c6d48fb4 100755 --- a/src/main/java/pw/mihou/nexus/core/NexusCore.java +++ b/src/main/java/pw/mihou/nexus/core/NexusCore.java @@ -17,6 +17,8 @@ import pw.mihou.nexus.features.command.core.NexusBaseCommandImplementation; import pw.mihou.nexus.features.command.core.NexusCommandCore; import pw.mihou.nexus.features.command.facade.NexusCommand; +import pw.mihou.nexus.features.command.interceptors.commons.NexusCommonInterceptors; +import pw.mihou.nexus.features.command.interceptors.commons.core.NexusCommonInterceptorsCore; import pw.mihou.nexus.features.command.responders.NexusResponderRepository; import pw.mihou.nexus.features.command.synchronizer.NexusSynchronizer; import pw.mihou.nexus.features.messages.defaults.NexusDefaultMessageConfiguration; @@ -60,6 +62,7 @@ public NexusCore( this.shardManager = new NexusShardManager(this); this.nexusConfiguration = nexusConfiguration; this.messageConfiguration = Objects.requireNonNullElseGet(messageConfiguration, NexusDefaultMessageConfiguration::new); + NexusCommonInterceptorsCore.addAll(); } @Override diff --git a/src/main/java/pw/mihou/nexus/features/command/interceptors/commons/NexusCommonInterceptors.java b/src/main/java/pw/mihou/nexus/features/command/interceptors/commons/NexusCommonInterceptors.java index 14858aa6..c4df6df9 100755 --- a/src/main/java/pw/mihou/nexus/features/command/interceptors/commons/NexusCommonInterceptors.java +++ b/src/main/java/pw/mihou/nexus/features/command/interceptors/commons/NexusCommonInterceptors.java @@ -1,9 +1,5 @@ package pw.mihou.nexus.features.command.interceptors.commons; -import pw.mihou.nexus.features.command.interceptors.facades.NexusCommandInterceptor; -import pw.mihou.nexus.features.messages.facade.NexusMessage; -import pw.mihou.nexus.features.ratelimiter.core.NexusRatelimiterCore; - /** * This class exists purely to separate the static function of adding * all the common interceptors. You can use this as a reference for all built-in Nexus middlewares @@ -17,20 +13,4 @@ public class NexusCommonInterceptors { public static final String NEXUS_GATE_DMS = "nexus.gate.dms"; public static final String NEXUS_RATELIMITER = "nexus.ratelimiter"; - static { - NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_BOT_OWNER_MIDDLEWARE, event -> event.stopIf( - !event.getUser().isBotOwner(), - NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the bot owner to execute this command.") - )); - - NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_SERVER_OWNER_MIDDLEWARE, event -> event.stopIf( - event.getServer().isPresent() && event.getServer().get().isOwner(event.getUser()), - NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the server owner to execute this command.") - )); - - NexusCommandInterceptor.addMiddleware(NEXUS_GATE_SERVER, event -> event.stopIf(event.getServer().isEmpty())); - NexusCommandInterceptor.addMiddleware(NEXUS_GATE_DMS, event -> event.stopIf(event.getServer().isPresent())); - NexusCommandInterceptor.addMiddleware(NEXUS_RATELIMITER, new NexusRatelimiterCore()); - } - } diff --git a/src/main/java/pw/mihou/nexus/features/command/interceptors/commons/core/NexusCommonInterceptorsCore.java b/src/main/java/pw/mihou/nexus/features/command/interceptors/commons/core/NexusCommonInterceptorsCore.java new file mode 100644 index 00000000..87737713 --- /dev/null +++ b/src/main/java/pw/mihou/nexus/features/command/interceptors/commons/core/NexusCommonInterceptorsCore.java @@ -0,0 +1,26 @@ +package pw.mihou.nexus.features.command.interceptors.commons.core; + +import pw.mihou.nexus.features.command.interceptors.commons.NexusCommonInterceptors; +import pw.mihou.nexus.features.command.interceptors.facades.NexusCommandInterceptor; +import pw.mihou.nexus.features.messages.facade.NexusMessage; +import pw.mihou.nexus.features.ratelimiter.core.NexusRatelimiterCore; + +public class NexusCommonInterceptorsCore extends NexusCommonInterceptors { + + public static void addAll() { + NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_BOT_OWNER_MIDDLEWARE, event -> event.stopIf( + !event.getUser().isBotOwner(), + NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the bot owner to execute this command.") + )); + + NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_SERVER_OWNER_MIDDLEWARE, event -> event.stopIf( + event.getServer().isPresent() && event.getServer().get().isOwner(event.getUser()), + NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the server owner to execute this command.") + )); + + NexusCommandInterceptor.addMiddleware(NEXUS_GATE_SERVER, event -> event.stopIf(event.getServer().isEmpty())); + NexusCommandInterceptor.addMiddleware(NEXUS_GATE_DMS, event -> event.stopIf(event.getServer().isPresent())); + NexusCommandInterceptor.addMiddleware(NEXUS_RATELIMITER, new NexusRatelimiterCore()); + } + +}