From 4d209deecf141a6991361efbd1a5382352a213da Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 16 May 2021 18:18:07 +1000 Subject: [PATCH] Add support for @Library annotation --- README.md | 3 +++ .../annotation/PluginAnnotationProcessor.java | 9 +++++++ .../java/annotation/dependency/Libraries.java | 23 ++++++++++++++++ .../java/annotation/dependency/Library.java | 26 +++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 src/main/java/org/bukkit/plugin/java/annotation/dependency/Libraries.java create mode 100644 src/main/java/org/bukkit/plugin/java/annotation/dependency/Library.java diff --git a/README.md b/README.md index a5cbd83..5628049 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ See the [wiki](https://www.spigotmc.org/wiki/plugin-yml/) for more information. @Author("md_5") @Website("www.spigotmc.org") @LogPrefix("Testing") +@Library("com.squareup.okhttp3:okhttp:4.9.0") @Dependency("WorldEdit") @Dependency("Towny") @LoadBefore("Towny") @@ -37,6 +38,8 @@ load: STARTUP author: md_5 website: www.spigotmc.org prefix: Testing +libraries: +- com.squareup.okhttp3:okhttp:4.9.0 depend: - WorldEdit - Towny diff --git a/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java index 59a935d..4d65024 100644 --- a/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java +++ b/src/main/java/org/bukkit/plugin/java/annotation/PluginAnnotationProcessor.java @@ -15,6 +15,7 @@ import org.bukkit.plugin.java.annotation.permission.Permission; import org.bukkit.plugin.java.annotation.permission.Permissions; import org.bukkit.plugin.java.annotation.plugin.ApiVersion; import org.bukkit.plugin.java.annotation.plugin.Description; +import org.bukkit.plugin.java.annotation.dependency.Library; import org.bukkit.plugin.java.annotation.plugin.LoadOrder; import org.bukkit.plugin.java.annotation.plugin.LogPrefix; import org.bukkit.plugin.java.annotation.plugin.Plugin; @@ -145,6 +146,14 @@ public class PluginAnnotationProcessor extends AbstractProcessor { // prefix processAndPut( yml, "prefix", mainPluginType, null, LogPrefix.class, String.class ); + // libraries + Library[] libraries = mainPluginType.getAnnotationsByType( Library.class ); + List libraryArr = Lists.newArrayList(); + for ( Library lib : libraries ) { + libraryArr.add( lib.value() ); + } + if ( !libraryArr.isEmpty() ) yml.put( "libraries", libraryArr ); + // dependencies Dependency[] dependencies = mainPluginType.getAnnotationsByType( Dependency.class ); List hardDependencies = Lists.newArrayList(); diff --git a/src/main/java/org/bukkit/plugin/java/annotation/dependency/Libraries.java b/src/main/java/org/bukkit/plugin/java/annotation/dependency/Libraries.java new file mode 100644 index 0000000..e94c261 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/dependency/Libraries.java @@ -0,0 +1,23 @@ +package org.bukkit.plugin.java.annotation.dependency; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Part of the plugin annotations framework. + *

+ * Represents the libraries a plugin depends on in order to be loaded + *
+ * This specific annotation should not be used by people who do not know how + * repeating annotations work. + */ +@Documented +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Libraries { + + Library[] value() default {}; +} diff --git a/src/main/java/org/bukkit/plugin/java/annotation/dependency/Library.java b/src/main/java/org/bukkit/plugin/java/annotation/dependency/Library.java new file mode 100644 index 0000000..e59b342 --- /dev/null +++ b/src/main/java/org/bukkit/plugin/java/annotation/dependency/Library.java @@ -0,0 +1,26 @@ +package org.bukkit.plugin.java.annotation.dependency; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Defines a plugin library. + *
+ * Libraries are dynamically loaded by the server implementation and should take + * the form of groupId:artifactId:version. + */ +@Documented +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Repeatable(Libraries.class) +public @interface Library { + + /** + * A library that is to be loaded and accessible by this plugin. + */ + String value(); +}