Compare commits
1
Commits
1.3.0
...
feat/extensions
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17a2ff73b2 |
No files matched your search
@@ -3,11 +3,16 @@ plugins {
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("net.kyori:adventure-api:4.11.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.11.0")
|
||||
compileOnly("net.kyori:adventure-text-serializer-legacy:4.11.0")
|
||||
compileOnly(project(":miniplaceholders-connect"))
|
||||
implementation("com.google.code.gson:gson:2.9.1")
|
||||
testImplementation(platform("org.junit:junit-bom:5.8.1"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testImplementation("net.kyori:adventure-api:4.11.0")
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package me.dreamerzero.miniplaceholders.api.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.enums.Platform;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Extension {
|
||||
String name();
|
||||
|
||||
Platform[] platform();
|
||||
|
||||
String version() default "";
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package me.dreamerzero.miniplaceholders.api.annotation.processor;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import javax.annotation.processing.AbstractProcessor;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.annotation.processing.RoundEnvironment;
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.element.Name;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.annotation.Extension;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Set;
|
||||
|
||||
@SupportedAnnotationTypes({"me.dreamerzero.miniplaceholders.api.annotation.Extension"})
|
||||
public class ExtensionAnnotationProcessor extends AbstractProcessor {
|
||||
private ProcessingEnvironment environment;
|
||||
|
||||
@Override
|
||||
public synchronized void init(ProcessingEnvironment processingEnv) {
|
||||
this.environment = processingEnv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if (roundEnv.processingOver()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(Extension.class)) {
|
||||
if (element.getKind() != ElementKind.CLASS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Extension extension = element.getAnnotation(Extension.class);
|
||||
Name name = ((TypeElement) element).getQualifiedName();
|
||||
|
||||
try {
|
||||
FileObject object = environment.getFiler()
|
||||
.createResource(StandardLocation.CLASS_OUTPUT, "", "miniplaceholders-extension.json");
|
||||
try (Writer writer = new BufferedWriter(object.openWriter())) {
|
||||
new Gson().toJson(new ProcessedExtension(
|
||||
extension.name(),
|
||||
extension.version(),
|
||||
name.toString(),
|
||||
extension.platform()),
|
||||
writer);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
environment.getMessager().printMessage(Diagnostic.Kind.ERROR, "Cannot generate extension file");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package me.dreamerzero.miniplaceholders.api.annotation.processor;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.enums.Platform;
|
||||
|
||||
public final class ProcessedExtension {
|
||||
private final String name;
|
||||
private final String version;
|
||||
private final Platform[] platforms;
|
||||
private final String clazz;
|
||||
|
||||
ProcessedExtension(String name, String version, String clazz, Platform... platforms) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
this.platforms = platforms;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
public Platform[] getPlatforms() {
|
||||
return platforms;
|
||||
}
|
||||
public String getClazz() {
|
||||
return this.clazz;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ module me.dreamerzero.miniplaceholders.api {
|
||||
requires net.kyori.adventure.text.minimessage;
|
||||
requires static org.jetbrains.annotations;
|
||||
requires me.dreamerzero.miniplaceholders.connect;
|
||||
requires java.base;
|
||||
requires java.compiler;
|
||||
requires com.google.gson;
|
||||
|
||||
exports me.dreamerzero.miniplaceholders.api;
|
||||
exports me.dreamerzero.miniplaceholders.api.enums;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
me.dreamerzero.miniplaceholders.api.annotation.processor.ExtensionAnnotationProcessor
|
||||
+4
-1
@@ -10,6 +10,10 @@ allprojects {
|
||||
group = "me.dreamerzero.miniplaceholders"
|
||||
version = "1.2.0"
|
||||
description = "MiniPlaceholders"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -22,7 +26,6 @@ dependencies {
|
||||
|
||||
subprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
maven("https://repo.maven.apache.org/maven2/")
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ dependencies {
|
||||
compileOnly("com.mojang:brigadier:1.0.18")
|
||||
}
|
||||
|
||||
blossom{
|
||||
blossom {
|
||||
replaceToken("{version}", version)
|
||||
replaceTokenIn("src/main/java/me/dreamerzero/miniplaceholders/common/PluginConstants.java")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.dreamerzero.miniplaceholders.extension;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.dreamerzero.miniplaceholders.api.annotation.Extension;
|
||||
|
||||
public final class Loader {
|
||||
private Loader() {}
|
||||
public static Extension[] loadExtensions(Path extensionsPath) {
|
||||
List<Extension> extensions = new ArrayList<>();
|
||||
try (DirectoryStream<Path> stream = Files.newDirectoryStream(extensionsPath, (file) -> file.toString().endsWith(".jar"))) {
|
||||
for (Path ext : stream) {
|
||||
|
||||
}
|
||||
} catch(IOException e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user