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
This commit is contained in:
Paldiu 2021-02-27 09:08:22 -06:00
parent 9bb8902eed
commit d81b6137d7
3 changed files with 23 additions and 13 deletions

View File

@ -0,0 +1,7 @@
package io.github.simplexdev.api.annotations;
public enum ReqType {
PAPER,
WATERFALL,
BUNGEECORD
}

View File

@ -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();
}

View File

@ -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 <T extends SimplexAddon<T>> 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;
}
}