From 9f69cf57c0ae6c0ccabd5a52c7ede261728079f3 Mon Sep 17 00:00:00 2001 From: Shindou Mihou Date: Thu, 28 Sep 2023 21:21:37 +0800 Subject: [PATCH] feat: remove `for-removal` deprecated fields --- .../interceptors/NexusCommandInterceptors.kt | 12 +-- .../core/NexusCommandInterceptorCore.kt | 10 --- .../facades/NexusCommandInterceptor.java | 74 +------------------ .../facades/NexusInterceptorRepository.java | 38 ---------- 4 files changed, 4 insertions(+), 130 deletions(-) delete mode 100644 src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusInterceptorRepository.java diff --git a/src/main/java/pw/mihou/nexus/features/command/interceptors/NexusCommandInterceptors.kt b/src/main/java/pw/mihou/nexus/features/command/interceptors/NexusCommandInterceptors.kt index f66337f4..476c0e70 100644 --- a/src/main/java/pw/mihou/nexus/features/command/interceptors/NexusCommandInterceptors.kt +++ b/src/main/java/pw/mihou/nexus/features/command/interceptors/NexusCommandInterceptors.kt @@ -5,7 +5,6 @@ import pw.mihou.nexus.core.reflective.NexusReflection import pw.mihou.nexus.features.command.interceptors.annotations.Name import pw.mihou.nexus.features.command.interceptors.core.NexusCommandInterceptorCore import pw.mihou.nexus.features.command.interceptors.facades.NexusAfterware -import pw.mihou.nexus.features.command.interceptors.facades.NexusInterceptorRepository import pw.mihou.nexus.features.command.interceptors.facades.NexusMiddleware object NexusCommandInterceptors { @@ -49,18 +48,13 @@ object NexusCommandInterceptors { } /** - * Adds the provided repository to the registry. Any [NexusInterceptorRepository] will be handled like - * how it is done in the older versions, but any other classes will be loaded via reflection through the - * newer mechanism. + * Adds the provided repository to the registry. In this new mechanism, we load all the [NexusAfterware] and + * [NexusMiddleware] variables in the class into the registry with a name based on their field name or the name + * provided using [Name] annotation. * * @param repository the repository to add. */ fun add(repository: Any) { - if (repository is NexusInterceptorRepository) { - interceptors.addRepository(repository) - return - } - NexusReflection.accumulate(repository) { field -> if (field.type != NexusMiddleware::class.java && field.type != NexusAfterware::class.java) return@accumulate val name = diff --git a/src/main/java/pw/mihou/nexus/features/command/interceptors/core/NexusCommandInterceptorCore.kt b/src/main/java/pw/mihou/nexus/features/command/interceptors/core/NexusCommandInterceptorCore.kt index 3b4fc58f..294d5e86 100644 --- a/src/main/java/pw/mihou/nexus/features/command/interceptors/core/NexusCommandInterceptorCore.kt +++ b/src/main/java/pw/mihou/nexus/features/command/interceptors/core/NexusCommandInterceptorCore.kt @@ -2,7 +2,6 @@ package pw.mihou.nexus.features.command.interceptors.core import pw.mihou.nexus.features.command.interceptors.facades.NexusAfterware import pw.mihou.nexus.features.command.interceptors.facades.NexusCommandInterceptor -import pw.mihou.nexus.features.command.interceptors.facades.NexusInterceptorRepository import pw.mihou.nexus.features.command.interceptors.facades.NexusMiddleware import pw.mihou.nexus.Nexus import pw.mihou.nexus.features.command.core.NexusMiddlewareEventCore @@ -35,15 +34,6 @@ internal object NexusCommandInterceptorCore { interceptors[name] = afterware } - /** - * Adds one repository of command interceptors to [Nexus]. - * @param repository the repository to add. - */ - @JvmStatic - fun addRepository(repository: NexusInterceptorRepository) { - repository.define() - } - @JvmStatic fun has(name: String) = interceptors.containsKey(name) diff --git a/src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusCommandInterceptor.java b/src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusCommandInterceptor.java index 104cd45c..48e1773c 100755 --- a/src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusCommandInterceptor.java +++ b/src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusCommandInterceptor.java @@ -1,75 +1,3 @@ package pw.mihou.nexus.features.command.interceptors.facades; -import pw.mihou.nexus.Nexus; -import pw.mihou.nexus.core.assignment.NexusUuidAssigner; -import pw.mihou.nexus.features.command.interceptors.core.NexusCommandInterceptorCore; - -public interface NexusCommandInterceptor { - - /** - * Creates an anonymous middleware where the name of the middleware is generated randomly - * by the framework at runtime. - * - * @param middleware The middleware functionality. - * @return The name of the middleware to generated. - * @see Nexus#getInterceptors - */ - @Deprecated(forRemoval = true) - static String middleware(NexusMiddleware middleware) { - return Nexus.getInterceptors().middleware(middleware); - } - - /** - * Creates an anonymous afterware where the name of the middleware is generated randomly - * by the framework at runtime. - * - * @param afterware The afterware functionality. - * @return The name of the afterware to generated. - * @see Nexus#getInterceptors - */ - @Deprecated(forRemoval = true) - static String afterware(NexusAfterware afterware) { - return Nexus.getInterceptors().afterware(afterware); - - } - - /** - * Adds the middleware into the command interceptor storage. - * - * @param name The name of the middleware to add. - * @param middleware The middleware functionality. - * @return The name of the middleware for quick-use. - * @see Nexus#getInterceptors - */ - @Deprecated(forRemoval = true) - static String addMiddleware(String name, NexusMiddleware middleware) { - return Nexus.getInterceptors().middleware(name, middleware); - } - - /** - * Adds the afterware into the command interceptor storage. - * - * @param name The name of the afterware to add. - * @param afterware The afterware functionality. - * @return The name of the afterware for quick-use. - * @see Nexus#getInterceptors - */ - @Deprecated(forRemoval = true) - static String addAfterware(String name, NexusAfterware afterware) { - return Nexus.getInterceptors().afterware(name, afterware); - - } - - /** - * Adds a repository of command interceptors to the command interceptor - * storage. - * - * @param repository The repository to add. - * @see Nexus#getInterceptors - */ - @Deprecated(forRemoval = true) - static void addRepository(NexusInterceptorRepository repository) { - Nexus.getInterceptors().add(repository); - } - -} +public interface NexusCommandInterceptor {} diff --git a/src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusInterceptorRepository.java b/src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusInterceptorRepository.java deleted file mode 100644 index 37d0862d..00000000 --- a/src/main/java/pw/mihou/nexus/features/command/interceptors/facades/NexusInterceptorRepository.java +++ /dev/null @@ -1,38 +0,0 @@ -package pw.mihou.nexus.features.command.interceptors.facades; - -import pw.mihou.nexus.features.command.interceptors.core.NexusCommandInterceptorCore; - -/** - * {@link NexusInterceptorRepository} is an extendable interface that can be used - * to define one or more interceptors which calling the register function. - */ -@Deprecated(forRemoval = true) -public abstract class NexusInterceptorRepository { - - /** - * Defines one or more interceptors. This method will be called - * upon startup. - */ - public abstract void define(); - - /** - * Adds the middleware into the command interceptor storage. - * - * @param name The name of the middleware to add. - * @param middleware The middleware functionality. - */ - public void middleware(String name, NexusMiddleware middleware) { - NexusCommandInterceptorCore.addMiddleware(name, middleware); - } - - /** - * Adds the afterware into the command interceptor storage. - * - * @param name The name of the afterware to add. - * @param afterware The afterware functionality. - */ - public void afterware(String name, NexusAfterware afterware) { - NexusCommandInterceptorCore.addAfterware(name, afterware); - } - -}