From d81b6137d7d401180ea78b0c04911804e1dea164 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Sat, 27 Feb 2021 09:08:22 -0600 Subject: [PATCH] BLEEDING_EDGE v1.3_03 - Added ReqType enum - Renamed ServerInfo to Requires, removed all boolean values and replaced with a single ReqType value() - Adjusted the registry to check for the requires annotation, and to disable the addon module if the server host is not running the requested server configuration --- .../simplexdev/api/annotations/ReqType.java | 7 +++++++ .../{ServerInfo.java => Requires.java} | 8 ++----- .../simplexcore/plugin/AddonRegistry.java | 21 ++++++++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 src/main/java/io/github/simplexdev/api/annotations/ReqType.java rename src/main/java/io/github/simplexdev/api/annotations/{ServerInfo.java => Requires.java} (64%) diff --git a/src/main/java/io/github/simplexdev/api/annotations/ReqType.java b/src/main/java/io/github/simplexdev/api/annotations/ReqType.java new file mode 100644 index 0000000..b9678ef --- /dev/null +++ b/src/main/java/io/github/simplexdev/api/annotations/ReqType.java @@ -0,0 +1,7 @@ +package io.github.simplexdev.api.annotations; + +public enum ReqType { + PAPER, + WATERFALL, + BUNGEECORD +} diff --git a/src/main/java/io/github/simplexdev/api/annotations/ServerInfo.java b/src/main/java/io/github/simplexdev/api/annotations/Requires.java similarity index 64% rename from src/main/java/io/github/simplexdev/api/annotations/ServerInfo.java rename to src/main/java/io/github/simplexdev/api/annotations/Requires.java index 7980453..8152537 100644 --- a/src/main/java/io/github/simplexdev/api/annotations/ServerInfo.java +++ b/src/main/java/io/github/simplexdev/api/annotations/Requires.java @@ -7,10 +7,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) -public @interface ServerInfo { - boolean isPaper() default false; - - boolean isWaterfall() default false; - - boolean isBungeeCord() default false; +public @interface Requires { + ReqType value(); } diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java index f9ac4cb..1b9c76d 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java +++ b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java @@ -1,7 +1,7 @@ package io.github.simplexdev.simplexcore.plugin; -import io.github.simplexdev.api.annotations.ServerInfo; -import io.github.simplexdev.api.func.Guard; +import io.github.simplexdev.api.annotations.ReqType; +import io.github.simplexdev.api.annotations.Requires; import io.github.simplexdev.simplexcore.utils.Constants; import java.util.HashSet; @@ -51,16 +51,23 @@ public final class AddonRegistry { } } + private boolean checkAnnotation(Requires info, ReqType type) { + return info.value() == type; + } + public > void register(T addon) { - if (addon.getClass().isAnnotationPresent(ServerInfo.class)) { - ServerInfo info = addon.getClass().getDeclaredAnnotation(ServerInfo.class); - if (info.isPaper() && !isPaper(addon)) { + if (addon.getClass().isAnnotationPresent(Requires.class)) { + Requires info = addon.getClass().getDeclaredAnnotation(Requires.class); + if (checkAnnotation(info, ReqType.PAPER) + && !isPaper(addon)) { return; } - if (info.isBungeeCord() && !isBungee(addon)) { + if (checkAnnotation(info, ReqType.BUNGEECORD) + && !isBungee(addon)) { return; } - if (info.isWaterfall() && !isWaterfall(addon)) { + if (checkAnnotation(info, ReqType.WATERFALL) + && !isWaterfall(addon)) { return; } }