Add support for @Library annotation

This commit is contained in:
md_5 2021-05-16 18:18:07 +10:00
parent 71bc0c2026
commit 4d209deecf
No known key found for this signature in database
GPG key ID: E8E901AC7C617C11
4 changed files with 61 additions and 0 deletions

View file

@ -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

View file

@ -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<String> 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<String> hardDependencies = Lists.newArrayList();

View file

@ -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.
* <p>
* Represents the libraries a plugin depends on in order to be loaded
* <br>
* 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 {};
}

View file

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