diff --git a/build.gradle b/build.gradle
index 1edd6eb..48d33bd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -85,6 +85,18 @@ dependencies {
implementation 'org.xerial:sqlite-jdbc:3.36.0'
}
+task buildResources {
+ doLast {
+ File to = new File("${buildDir}/classes/java/main/META-INF/services/javax.annotation.processing.Processor")
+ to.parentFile.mkdirs()
+ if (!to.exists()) {
+ to.createNewFile()
+ to.append("de.steamwar.linkage.LinkageProcessor\n")
+ }
+ }
+}
+classes.finalizedBy(buildResources)
+
task buildProject {
description 'Build this project'
group "Steamwar"
diff --git a/src/de/steamwar/linkage/AllowedContexts.java b/src/de/steamwar/linkage/AllowedContexts.java
new file mode 100644
index 0000000..175a783
--- /dev/null
+++ b/src/de/steamwar/linkage/AllowedContexts.java
@@ -0,0 +1,36 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.ANNOTATION_TYPE)
+@Retention(RetentionPolicy.CLASS)
+public @interface AllowedContexts {
+
+ /**
+ * The context in which this annotation is valid.
+ */
+ Context[] value();
+
+}
diff --git a/src/de/steamwar/linkage/Context.java b/src/de/steamwar/linkage/Context.java
new file mode 100644
index 0000000..7559bd0
--- /dev/null
+++ b/src/de/steamwar/linkage/Context.java
@@ -0,0 +1,25 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+public enum Context {
+ BUNGEE,
+ SPIGOT
+}
diff --git a/src/de/steamwar/linkage/EventMode.java b/src/de/steamwar/linkage/EventMode.java
new file mode 100644
index 0000000..cdff466
--- /dev/null
+++ b/src/de/steamwar/linkage/EventMode.java
@@ -0,0 +1,44 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@AllowedContexts(Context.BUNGEE)
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.TYPE})
+public @interface EventMode {
+ Mode value();
+
+ @AllArgsConstructor
+ enum Mode {
+ EventOnly(""),
+ NonEvent("!");
+
+ @Getter
+ private String prefix;
+ }
+}
diff --git a/src/de/steamwar/linkage/LinkageProcessor.java b/src/de/steamwar/linkage/LinkageProcessor.java
new file mode 100644
index 0000000..f2f245c
--- /dev/null
+++ b/src/de/steamwar/linkage/LinkageProcessor.java
@@ -0,0 +1,303 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.FieldBuilder;
+import de.steamwar.linkage.plan.MethodBuilder;
+import de.steamwar.linkage.types.Plain_GENERIC;
+import lombok.Getter;
+import lombok.SneakyThrows;
+
+import javax.annotation.processing.*;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.*;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+import javax.tools.Diagnostic;
+import java.io.*;
+import java.lang.annotation.Annotation;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+
+@SupportedAnnotationTypes("de.steamwar.linkage.Linked")
+public class LinkageProcessor extends AbstractProcessor {
+
+ private static Context context;
+
+ @Getter
+ private static String pluginMain;
+
+ private String name;
+ private String packageName;
+ private String className;
+
+ private Messager messager;
+ private boolean processed = false;
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latestSupported();
+ }
+
+ @SneakyThrows
+ @Override
+ public synchronized void init(ProcessingEnvironment processingEnv) {
+ super.init(processingEnv);
+
+ String name = new File(System.getProperty("user.dir")).getName();
+ if (name.contains(".")) name = name.substring(0, name.indexOf('.'));
+ name = name.toLowerCase();
+
+ messager = processingEnv.getMessager();
+
+ this.name = name;
+ packageName = "de.steamwar." + name + ".linkage";
+ className = "LinkageUtils";
+ mainClass();
+ }
+
+ @SneakyThrows
+ private void mainClass() {
+ File file = new File(System.getProperty("user.dir"));
+ Optional pluginYMLFile = Files.walk(file.toPath())
+ .map(Path::toFile)
+ .filter(File::isFile)
+ .filter(f -> f.getName().equals("plugin.yml") || f.getName().equals("bungee.yml"))
+ .findFirst();
+ if (!pluginYMLFile.isPresent()) {
+ messager.printMessage(Diagnostic.Kind.ERROR, "Could not find plugin.yml or bungee.yml");
+ return;
+ }
+ context = pluginYMLFile.get().getName().equals("bungee.yml") ? Context.BUNGEE : Context.SPIGOT;
+ Optional mainName = getMainName(pluginYMLFile.get());
+ if (!mainName.isPresent()) {
+ messager.printMessage(Diagnostic.Kind.ERROR, "Could not find main class in plugin.yml or bungee.yml");
+ return;
+ }
+ pluginMain = mainName.get();
+ }
+
+ @SneakyThrows
+ private Optional getMainName(File pluginYML) {
+ if (!pluginYML.exists()) return Optional.empty();
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(pluginYML)))) {
+ return reader.lines()
+ .filter(line -> line.startsWith("main:"))
+ .map(line -> line.substring(line.indexOf(':') + 1).trim())
+ .findFirst();
+ }
+ }
+
+ @SneakyThrows
+ @Override
+ public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (processed) return false;
+ processed = true;
+
+ Writer writer = processingEnv.getFiler().createSourceFile("de.steamwar." + name + ".linkage.LinkageUtils").openWriter();
+
+ BuildPlan buildPlan = new BuildPlan(packageName, className);
+ buildPlan.addImport("de.steamwar.linkage.LinkageType");
+
+ Set extends Element> elements = roundEnv.getElementsAnnotatedWith(Linked.class);
+ Map neededFields = new HashMap<>();
+ for (Element element : elements) {
+ if (element.getKind() != ElementKind.CLASS) {
+ continue;
+ }
+ TypeElement typeElement = (TypeElement) element;
+ Linked linked = element.getAnnotation(Linked.class);
+ if (linked == null) {
+ continue;
+ }
+ if (getLinkagesOfType(typeElement).size() > 1) {
+ neededFields.put(typeElement.getQualifiedName().toString(), typeElement);
+ }
+
+ List variableElements = typeElement.getEnclosedElements().stream().filter(e -> e.getKind() == ElementKind.FIELD).map(VariableElement.class::cast).filter(e -> {
+ return e.getAnnotation(LinkedInstance.class) != null;
+ }).collect(Collectors.toList());
+ if (variableElements.isEmpty()) {
+ continue;
+ }
+
+ for (VariableElement variableElement : variableElements) {
+ if (!variableElement.getModifiers().contains(Modifier.PUBLIC)) {
+ messager.printMessage(Diagnostic.Kind.ERROR, "Field " + variableElement.getSimpleName() + " must be public", variableElement);
+ continue;
+ }
+ if (variableElement.getModifiers().contains(Modifier.STATIC)) {
+ messager.printMessage(Diagnostic.Kind.ERROR, "Field " + variableElement.getSimpleName() + " must be non static", variableElement);
+ continue;
+ }
+ if (variableElement.getModifiers().contains(Modifier.FINAL)) {
+ messager.printMessage(Diagnostic.Kind.ERROR, "Field " + variableElement.getSimpleName() + " must be non final", variableElement);
+ continue;
+ }
+ neededFields.put(typeElement.getQualifiedName().toString(), typeElement);
+ TypeElement fieldType = (TypeElement) ((DeclaredType) variableElement.asType()).asElement();
+ neededFields.put(fieldType.getQualifiedName().toString(), fieldType);
+
+ specialElements(typeElement, buildPlan, buildPlan::addStaticLine, () -> {
+ buildPlan.addStaticLine(getElement(typeElement, neededFields) + "." + variableElement.getSimpleName().toString() + " = " + getElement((TypeElement) ((DeclaredType) variableElement.asType()).asElement(), neededFields) + ";");
+ });
+ }
+ }
+ neededFields.forEach((s, typeElement) -> {
+ buildPlan.addImport(typeElement.getQualifiedName().toString());
+ String t = typeElement.getSimpleName().toString();
+ t = t.substring(0, 1).toLowerCase() + t.substring(1);
+ buildPlan.addField(new FieldBuilder(typeElement.getSimpleName().toString(), t, "new " + typeElement.getSimpleName().toString() + "()"));
+ });
+
+ Map methods = new HashMap<>();
+ for (Element element : elements) {
+ if (element.getKind() != ElementKind.CLASS) {
+ continue;
+ }
+ TypeElement typeElement = (TypeElement) element;
+
+ System.out.println("Found element: " + typeElement.getQualifiedName().toString());
+ Map> linkages = getLinkagesOfType(typeElement);
+ if (linkages.isEmpty()) {
+ continue;
+ }
+
+ for (Map.Entry> entry : linkages.entrySet()) {
+ MethodBuilder method = methods.computeIfAbsent(entry.getKey(), s -> {
+ MethodBuilder methodBuilder = new MethodBuilder(s, "void");
+ buildPlan.addMethod(methodBuilder);
+ return methodBuilder;
+ });
+ for (LinkageType type : entry.getValue()) {
+ specialElements(typeElement, buildPlan, method::addLine, () -> {
+ buildPlan.addImport(typeElement.getQualifiedName().toString());
+ type.generateCode(buildPlan, method, getElement(typeElement, neededFields), typeElement);
+ });
+ }
+ }
+ }
+
+ BufferedWriter bufferedWriter = new BufferedWriter(writer);
+ buildPlan.write(bufferedWriter);
+ bufferedWriter.close();
+ return true;
+ }
+
+ private String getElement(TypeElement typeElement, Map neededFields) {
+ if (neededFields.containsKey(typeElement.getQualifiedName().toString())) {
+ String s = typeElement.getSimpleName().toString();
+ return s.substring(0, 1).toLowerCase() + s.substring(1);
+ }
+ return "new " + typeElement.getSimpleName().toString() + "()";
+ }
+
+ private void specialElements(TypeElement typeElement, BuildPlan buildPlan, Consumer stringConsumer, Runnable inner) {
+ MinVersion minVersion = typeElement.getAnnotation(MinVersion.class);
+ MaxVersion maxVersion = typeElement.getAnnotation(MaxVersion.class);
+ EventMode eventMode = typeElement.getAnnotation(EventMode.class);
+ PluginCheck[] pluginChecks = typeElement.getAnnotationsByType(PluginCheck.class);
+ if (context == Context.SPIGOT) {
+ errorOnNonNull(typeElement, eventMode);
+ List checks = new ArrayList<>();
+ if (minVersion != null) {
+ buildPlan.addImport("de.steamwar.core.Core");
+ checks.add("Core.getVersion() >= " + minVersion.value());
+ }
+ if (maxVersion != null) {
+ buildPlan.addImport("de.steamwar.core.Core");
+ checks.add("Core.getVersion() <= " + maxVersion.value());
+ }
+ if (pluginChecks.length != 0) {
+ buildPlan.addImport("org.bukkit.Bukkit");
+ Arrays.stream(pluginChecks).map(pluginCheck -> {
+ return "Bukkit.getPluginManager().getPlugin(\"" + pluginCheck.value() + "\") " + (pluginCheck.has() == PluginCheck.Has.THIS ? "!" : "=") + "= null";
+ }).forEach(checks::add);
+ }
+ if (!checks.isEmpty()) stringConsumer.accept("if (" + String.join(" && ", checks) + ") {");
+ inner.run();
+ if (!checks.isEmpty()) stringConsumer.accept("}");
+ } else {
+ errorOnNonNull(typeElement, minVersion, maxVersion);
+ List checks = new ArrayList<>();
+ if (eventMode != null) {
+ buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
+ checks.add(eventMode.value().getPrefix() + "BungeeCore.EVENT_MODE");
+ }
+ if (pluginChecks.length != 0) {
+ buildPlan.addImport("net.md_5.bungee.BungeeCord");
+ Arrays.stream(pluginChecks).map(pluginCheck -> {
+ return "BungeeCord.getPluginManager().getPlugin(\"" + pluginCheck.value() + "\") " + (pluginCheck.has() == PluginCheck.Has.THIS ? "!" : "=") + "= null";
+ }).forEach(checks::add);
+ }
+ if (!checks.isEmpty()) stringConsumer.accept("if (" + String.join(" && ", checks) + ") {");
+ inner.run();
+ if (!checks.isEmpty()) stringConsumer.accept("}");
+ }
+ }
+
+ private void errorOnNonNull(TypeElement typeElement, Annotation... annotations) {
+ for (Annotation annotation : annotations) {
+ if (annotation != null) {
+ messager.printMessage(Diagnostic.Kind.ERROR, annotation.annotationType().getSimpleName() + " is not supported in " + context.name(), typeElement);
+ }
+ }
+ }
+
+ private Plain_GENERIC plain_GENERIC = new Plain_GENERIC();
+
+ private Map> getLinkagesOfType(TypeElement typeElement) {
+ Map> linkages = new HashMap<>();
+ LinkageType superClassType = resolveSingle(typeElement.getSuperclass());
+ if (superClassType != null) {
+ linkages.computeIfAbsent(superClassType.method(), s -> new ArrayList<>()).add(superClassType);
+ }
+ for (TypeMirror typeMirror : typeElement.getInterfaces()) {
+ LinkageType interfaceType = resolveSingle(typeMirror);
+ if (interfaceType != null) {
+ linkages.computeIfAbsent(interfaceType.method(), s -> new ArrayList<>()).add(interfaceType);
+ }
+ }
+ if (!linkages.containsKey(plain_GENERIC.method())) {
+ linkages.put(plain_GENERIC.method(), Collections.singletonList(plain_GENERIC));
+ }
+ return linkages;
+ }
+
+ private LinkageType resolveSingle(TypeMirror typeMirror) {
+ String qualifier = typeMirror.toString();
+ qualifier = qualifier.substring(qualifier.lastIndexOf('.') + 1);
+ try {
+ return (LinkageType) Class.forName("de.steamwar.linkage.types." + qualifier + "_" + context.name()).getDeclaredConstructor().newInstance();
+ } catch (Exception e) {
+ // Ignore
+ }
+ try {
+ return (LinkageType) Class.forName("de.steamwar.linkage.types." + qualifier + "_GENERIC").getDeclaredConstructor().newInstance();
+ } catch (Exception e) {
+ // Ignore
+ }
+ return null;
+ }
+}
diff --git a/src/de/steamwar/linkage/LinkageType.java b/src/de/steamwar/linkage/LinkageType.java
new file mode 100644
index 0000000..9291279
--- /dev/null
+++ b/src/de/steamwar/linkage/LinkageType.java
@@ -0,0 +1,36 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public interface LinkageType {
+
+ default String getPluginMain() {
+ return LinkageProcessor.getPluginMain();
+ }
+
+ String method();
+
+ void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement);
+}
diff --git a/src/de/steamwar/linkage/Linked.java b/src/de/steamwar/linkage/Linked.java
new file mode 100644
index 0000000..f3836e0
--- /dev/null
+++ b/src/de/steamwar/linkage/Linked.java
@@ -0,0 +1,27 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.TYPE})
+public @interface Linked {
+}
diff --git a/src/de/steamwar/linkage/LinkedInstance.java b/src/de/steamwar/linkage/LinkedInstance.java
new file mode 100644
index 0000000..9636ba5
--- /dev/null
+++ b/src/de/steamwar/linkage/LinkedInstance.java
@@ -0,0 +1,30 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.FIELD})
+public @interface LinkedInstance {
+}
diff --git a/src/de/steamwar/linkage/MaxVersion.java b/src/de/steamwar/linkage/MaxVersion.java
new file mode 100644
index 0000000..e144b16
--- /dev/null
+++ b/src/de/steamwar/linkage/MaxVersion.java
@@ -0,0 +1,32 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@AllowedContexts(Context.SPIGOT)
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.TYPE})
+public @interface MaxVersion {
+ int value();
+}
diff --git a/src/de/steamwar/linkage/MinVersion.java b/src/de/steamwar/linkage/MinVersion.java
new file mode 100644
index 0000000..b6f5b99
--- /dev/null
+++ b/src/de/steamwar/linkage/MinVersion.java
@@ -0,0 +1,32 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@AllowedContexts(Context.SPIGOT)
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.TYPE})
+public @interface MinVersion {
+ int value();
+}
diff --git a/src/de/steamwar/linkage/PluginCheck.java b/src/de/steamwar/linkage/PluginCheck.java
new file mode 100644
index 0000000..241f19a
--- /dev/null
+++ b/src/de/steamwar/linkage/PluginCheck.java
@@ -0,0 +1,42 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage;
+
+import java.lang.annotation.*;
+
+@AllowedContexts({Context.BUNGEE, Context.SPIGOT})
+@Retention(RetentionPolicy.SOURCE)
+@Target({ElementType.TYPE})
+@Repeatable(PluginCheck.PluginChecks.class)
+public @interface PluginCheck {
+ Has has() default Has.THIS;
+ String value();
+
+ enum Has {
+ THIS,
+ NOT
+ }
+
+ @Retention(RetentionPolicy.SOURCE)
+ @Target({ElementType.TYPE})
+ @interface PluginChecks {
+ @SuppressWarnings("unused") PluginCheck[] value() default {};
+ }
+}
diff --git a/src/de/steamwar/linkage/api/Disable.java b/src/de/steamwar/linkage/api/Disable.java
new file mode 100644
index 0000000..f09b846
--- /dev/null
+++ b/src/de/steamwar/linkage/api/Disable.java
@@ -0,0 +1,24 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.api;
+
+public interface Disable {
+ void disable();
+}
diff --git a/src/de/steamwar/linkage/api/Enable.java b/src/de/steamwar/linkage/api/Enable.java
new file mode 100644
index 0000000..5d516cd
--- /dev/null
+++ b/src/de/steamwar/linkage/api/Enable.java
@@ -0,0 +1,24 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.api;
+
+public interface Enable {
+ void enable();
+}
diff --git a/src/de/steamwar/linkage/plan/BuildPlan.java b/src/de/steamwar/linkage/plan/BuildPlan.java
new file mode 100644
index 0000000..2fc7b8b
--- /dev/null
+++ b/src/de/steamwar/linkage/plan/BuildPlan.java
@@ -0,0 +1,89 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.plan;
+
+import lombok.RequiredArgsConstructor;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.util.*;
+
+@RequiredArgsConstructor
+public class BuildPlan {
+
+ private final String packageName;
+ private Set imports = new HashSet<>();
+ private final String className;
+
+ private List fieldBuilders = new ArrayList<>();
+ private Map methodBuilderMap = new HashMap<>();
+ private List staticLines = new ArrayList<>();
+
+ public void addImport(String importName) {
+ imports.add(importName);
+ }
+
+ public void addField(FieldBuilder fieldBuilder) {
+ fieldBuilders.add(fieldBuilder);
+ }
+
+ public void addMethod(MethodBuilder methodBuilder) {
+ methodBuilderMap.put(methodBuilder.getMethodName(), methodBuilder);
+ }
+
+ public boolean hasMethod(String methodName) {
+ return methodBuilderMap.containsKey(methodName);
+ }
+
+ public void addStaticLine(String line) {
+ staticLines.add(line);
+ }
+
+ public void write(BufferedWriter writer) throws IOException {
+ writer.write("package " + packageName + ";\n");
+ if (!imports.isEmpty()) {
+ writer.write("\n");
+ for (String importName : imports) {
+ writer.write("import " + importName + ";\n");
+ }
+ }
+ writer.write("\n");
+ writer.write("public class " + className + " {\n");
+ if (!fieldBuilders.isEmpty()) {
+ for (FieldBuilder fieldBuilder : fieldBuilders) {
+ fieldBuilder.write(writer);
+ }
+ writer.write("\n");
+ }
+ if (!staticLines.isEmpty()) {
+ writer.write(" static {\n");
+ for (String line : staticLines) {
+ writer.write(" " + line + "\n");
+ }
+ writer.write(" }\n");
+ writer.write("\n");
+ }
+ for (MethodBuilder methodBuilder : methodBuilderMap.values()) {
+ methodBuilder.write(writer);
+ writer.write("\n");
+ }
+ writer.write("}\n");
+ }
+}
diff --git a/src/de/steamwar/linkage/plan/FieldBuilder.java b/src/de/steamwar/linkage/plan/FieldBuilder.java
new file mode 100644
index 0000000..12fa440
--- /dev/null
+++ b/src/de/steamwar/linkage/plan/FieldBuilder.java
@@ -0,0 +1,44 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.plan;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+
+@RequiredArgsConstructor
+@AllArgsConstructor
+public class FieldBuilder {
+ @Getter
+ private final String type;
+ private final String name;
+ private String initializer;
+
+ public String getFieldName() {
+ return name;
+ }
+
+ public void write(BufferedWriter writer) throws IOException {
+ writer.write(" private static " + type + " " + getFieldName() + (initializer == null ? "" : " = " + initializer) + ";\n");
+ }
+}
diff --git a/src/de/steamwar/linkage/plan/MethodBuilder.java b/src/de/steamwar/linkage/plan/MethodBuilder.java
new file mode 100644
index 0000000..6a31175
--- /dev/null
+++ b/src/de/steamwar/linkage/plan/MethodBuilder.java
@@ -0,0 +1,70 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.plan;
+
+import lombok.RequiredArgsConstructor;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+@RequiredArgsConstructor
+public class MethodBuilder {
+
+ private final String name;
+ private final String returnType;
+ private List parameters = new ArrayList<>();
+ private List lines = new ArrayList<>();
+ private boolean isPrivate = false;
+
+ public void addParameter(ParameterBuilder parameterBuilder) {
+ parameters.add(parameterBuilder);
+ }
+
+ public void addLine(String line) {
+ lines.add(line);
+ }
+
+ public String getMethodName() {
+ return name;
+ }
+
+ public void setPrivate(boolean isPrivate) {
+ this.isPrivate = isPrivate;
+ }
+
+ public void write(BufferedWriter writer) throws IOException {
+ writer.write(" " + (isPrivate ? "private" : "public") + " static " + returnType + " " + getMethodName() + "(");
+ for (int i = 0; i < parameters.size(); i++) {
+ parameters.get(i).write(writer);
+ if (i < parameters.size() - 1) {
+ writer.write(", ");
+ }
+ }
+ writer.write(") {");
+ for (String line : lines) {
+ writer.write("\n");
+ writer.write(" " + line);
+ }
+ writer.write("\n");
+ writer.write(" }\n");
+ }
+}
diff --git a/src/de/steamwar/linkage/plan/ParameterBuilder.java b/src/de/steamwar/linkage/plan/ParameterBuilder.java
new file mode 100644
index 0000000..d88364b
--- /dev/null
+++ b/src/de/steamwar/linkage/plan/ParameterBuilder.java
@@ -0,0 +1,35 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.plan;
+
+import lombok.AllArgsConstructor;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+
+@AllArgsConstructor
+public class ParameterBuilder {
+ private String type;
+ private String name;
+
+ public void write(BufferedWriter writer) throws IOException {
+ writer.write(type + " " + name);
+ }
+}
diff --git a/src/de/steamwar/linkage/types/Disable_GENERIC.java b/src/de/steamwar/linkage/types/Disable_GENERIC.java
new file mode 100644
index 0000000..ea58c91
--- /dev/null
+++ b/src/de/steamwar/linkage/types/Disable_GENERIC.java
@@ -0,0 +1,39 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public class Disable_GENERIC implements LinkageType {
+
+ @Override
+ public String method() {
+ return "unlink";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ method.addLine(instance + ".disable();");
+ }
+}
diff --git a/src/de/steamwar/linkage/types/Enable_GENERIC.java b/src/de/steamwar/linkage/types/Enable_GENERIC.java
new file mode 100644
index 0000000..03afd57
--- /dev/null
+++ b/src/de/steamwar/linkage/types/Enable_GENERIC.java
@@ -0,0 +1,39 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public class Enable_GENERIC implements LinkageType {
+
+ @Override
+ public String method() {
+ return "link";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ method.addLine(instance + ".enable();");
+ }
+}
diff --git a/src/de/steamwar/linkage/types/Listener_BUNGEE.java b/src/de/steamwar/linkage/types/Listener_BUNGEE.java
new file mode 100644
index 0000000..327b19a
--- /dev/null
+++ b/src/de/steamwar/linkage/types/Listener_BUNGEE.java
@@ -0,0 +1,41 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public class Listener_BUNGEE implements LinkageType {
+
+ @Override
+ public String method() {
+ return "link";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ buildPlan.addImport("net.md_5.bungee.api.ProxyServer");
+ buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
+ method.addLine("ProxyServer.getInstance().getPluginManager().registerListener(BungeeCore.get(), " + instance + ");");
+ }
+}
diff --git a/src/de/steamwar/linkage/types/Listener_SPIGOT.java b/src/de/steamwar/linkage/types/Listener_SPIGOT.java
new file mode 100644
index 0000000..4d78b08
--- /dev/null
+++ b/src/de/steamwar/linkage/types/Listener_SPIGOT.java
@@ -0,0 +1,100 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.FieldBuilder;
+import de.steamwar.linkage.plan.MethodBuilder;
+import de.steamwar.linkage.plan.ParameterBuilder;
+
+import javax.lang.model.element.*;
+import javax.lang.model.type.DeclaredType;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Listener_SPIGOT implements LinkageType {
+
+ @Override
+ public String method() {
+ return "link";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ Map eventClasses = new HashMap<>();
+ Map eventMethods = new HashMap<>();
+
+ typeElement.getEnclosedElements().stream().filter(e -> e.getKind() == ElementKind.METHOD).map(ExecutableElement.class::cast).filter(e -> {
+ return e.getAnnotationMirrors().stream().anyMatch(annotationMirror -> {
+ return annotationMirror.getAnnotationType().asElement().getSimpleName().toString().equals("EventHandler");
+ });
+ }).forEach(e -> {
+ TypeElement current = ((TypeElement)((DeclaredType) e.getParameters().get(0).asType()).asElement());
+ eventClasses.put(current.getQualifiedName().toString(), current);
+ eventMethods.put(current, e);
+ });
+
+ eventClasses.forEach((s, eventType) -> {
+ if (buildPlan.hasMethod(s)) return;
+ buildPlan.addImport("org.bukkit.event.HandlerList");
+ buildPlan.addImport("org.bukkit.event.Listener");
+ buildPlan.addImport("java.util.function.Consumer");
+ buildPlan.addImport("org.bukkit.event.EventPriority");
+ buildPlan.addImport("org.bukkit.plugin.RegisteredListener");
+ buildPlan.addImport("org.bukkit.plugin.EventExecutor");
+ buildPlan.addImport(s);
+ buildPlan.addField(new FieldBuilder("HandlerList", "handlerList" + eventType.getSimpleName()));
+ MethodBuilder methodBuilder = new MethodBuilder(eventType.getSimpleName().toString(), "void");
+ methodBuilder.addParameter(new ParameterBuilder("Listener", "listener"));
+ methodBuilder.addParameter(new ParameterBuilder("Consumer<" + eventType.getSimpleName() + ">", "consumer"));
+ methodBuilder.addParameter(new ParameterBuilder("EventPriority", "eventPriority"));
+ methodBuilder.addParameter(new ParameterBuilder("boolean", "ignoreCancelled"));
+ methodBuilder.setPrivate(true);
+ methodBuilder.addLine("EventExecutor eventExecutor = (l, event) -> {");
+ methodBuilder.addLine(" if (event instanceof " + eventType.getSimpleName() + ") {");
+ methodBuilder.addLine(" consumer.accept((" + eventType.getSimpleName() + ") event);");
+ methodBuilder.addLine(" }");
+ methodBuilder.addLine("};");
+ methodBuilder.addLine("handlerList" + eventType.getSimpleName() + ".register(new RegisteredListener(listener, eventExecutor, eventPriority, " + getPluginMain() + ".getInstance(), ignoreCancelled));");
+ buildPlan.addMethod(methodBuilder);
+ method.addLine("handlerList" + eventType.getSimpleName() + " = " + eventType.getSimpleName() + ".getHandlerList();");
+ });
+
+ String localInstance = "local" + typeElement.getSimpleName().toString();
+ method.addLine(typeElement.getSimpleName() + " " + localInstance + " = " + instance + ";");
+ eventMethods.forEach((type, executableElement) -> {
+ AnnotationMirror eventHandler = executableElement.getAnnotationMirrors().stream().filter(annotationMirror -> annotationMirror.getAnnotationType().asElement().getSimpleName().toString().equals("EventHandler")).findFirst().orElse(null);
+ if (eventHandler == null) {
+ return;
+ }
+ String priority = "NORMAL";
+ String ignoreCancelled = "false";
+ for (Map.Entry extends ExecutableElement, ? extends AnnotationValue> entry : eventHandler.getElementValues().entrySet()) {
+ if (entry.getKey().getSimpleName().toString().equals("priority")) {
+ priority = entry.getValue().getValue().toString();
+ } else if (entry.getKey().getSimpleName().toString().equals("ignoreCancelled")) {
+ ignoreCancelled = entry.getValue().getValue().toString();
+ }
+ }
+ method.addLine(type.getSimpleName().toString() + "(" + localInstance + ", " + localInstance + "::" + executableElement.getSimpleName().toString() + ", EventPriority." + priority + ", " + ignoreCancelled + ");");
+ });
+ }
+}
diff --git a/src/de/steamwar/linkage/types/PacketHandler_GENERIC.java b/src/de/steamwar/linkage/types/PacketHandler_GENERIC.java
new file mode 100644
index 0000000..630f6f9
--- /dev/null
+++ b/src/de/steamwar/linkage/types/PacketHandler_GENERIC.java
@@ -0,0 +1,39 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2022 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public class PacketHandler_GENERIC implements LinkageType {
+
+ @Override
+ public String method() {
+ return "link";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ method.addLine(instance + ".register();");
+ }
+}
diff --git a/src/de/steamwar/linkage/types/Plain_GENERIC.java b/src/de/steamwar/linkage/types/Plain_GENERIC.java
new file mode 100644
index 0000000..eca2830
--- /dev/null
+++ b/src/de/steamwar/linkage/types/Plain_GENERIC.java
@@ -0,0 +1,39 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public class Plain_GENERIC implements LinkageType {
+
+ @Override
+ public String method() {
+ return "link";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ method.addLine(instance + ";");
+ }
+}
diff --git a/src/de/steamwar/linkage/types/SWCommand_BUNGEE.java b/src/de/steamwar/linkage/types/SWCommand_BUNGEE.java
new file mode 100644
index 0000000..5db62c4
--- /dev/null
+++ b/src/de/steamwar/linkage/types/SWCommand_BUNGEE.java
@@ -0,0 +1,39 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public class SWCommand_BUNGEE implements LinkageType {
+
+ @Override
+ public String method() {
+ return "link";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ method.addLine(instance + ";");
+ }
+}
diff --git a/src/de/steamwar/linkage/types/SWCommand_SPIGOT.java b/src/de/steamwar/linkage/types/SWCommand_SPIGOT.java
new file mode 100644
index 0000000..96e3f77
--- /dev/null
+++ b/src/de/steamwar/linkage/types/SWCommand_SPIGOT.java
@@ -0,0 +1,39 @@
+/*
+ * This file is a part of the SteamWar software.
+ *
+ * Copyright (C) 2020 SteamWar.de-Serverteam
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.steamwar.linkage.types;
+
+import de.steamwar.linkage.LinkageType;
+import de.steamwar.linkage.plan.BuildPlan;
+import de.steamwar.linkage.plan.MethodBuilder;
+
+import javax.lang.model.element.TypeElement;
+
+public class SWCommand_SPIGOT implements LinkageType {
+
+ @Override
+ public String method() {
+ return "link";
+ }
+
+ @Override
+ public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
+ method.addLine(instance + ".setMessage(" + getPluginMain() + ".MESSAGE);");
+ }
+}