Dieser Commit ist enthalten in:
Ursprung
bbd4eeacd3
Commit
067acf5f62
@ -249,7 +249,7 @@ public class LinkageProcessor extends AbstractProcessor {
|
|||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.forEach(type -> {
|
.forEach(type -> {
|
||||||
Class<? extends LinkageType> clazz = type.getClass();
|
Class<? extends LinkageType> clazz = type.getClass();
|
||||||
if (!type.requirements(typeElement.getSuperclass().toString(), typeElement.getInterfaces().stream().map(TypeMirror::toString).collect(Collectors.toSet()))) {
|
if (!type.requirements(typeElement.getSuperclass().toString(), typeElement.getInterfaces().stream().map(TypeMirror::toString).collect(Collectors.toSet()), typeElement)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ import de.steamwar.linkage.plan.BuildPlan;
|
|||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
import de.steamwar.linkage.plan.MethodBuilder;
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.OptionalInt;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface LinkageType {
|
public interface LinkageType {
|
||||||
@ -39,9 +37,22 @@ public interface LinkageType {
|
|||||||
SPIGOT
|
SPIGOT
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean requirements(String superClass, Set<String> interfaces) {
|
default boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement);
|
default void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
|
switch (context) {
|
||||||
|
case BUNGEE:
|
||||||
|
generateCodeBungee(buildPlan, linkageTypeMethod, instance, typeElement);
|
||||||
|
break;
|
||||||
|
case SPIGOT:
|
||||||
|
generateCodeSpigot(buildPlan, linkageTypeMethod, instance, typeElement);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
|
}
|
||||||
|
default void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,16 +29,17 @@ import java.util.Set;
|
|||||||
public class Command implements LinkageType {
|
public class Command implements LinkageType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requirements(String superClass, Set<String> interfaces) {
|
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
|
||||||
return superClass.equals("de.steamwar.command.SWCommand");
|
return superClass.equals("de.steamwar.command.SWCommand");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
public void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
if (context == Context.BUNGEE) {
|
|
||||||
linkageTypeMethod.addLine(instance + ";");
|
linkageTypeMethod.addLine(instance + ";");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
linkageTypeMethod.addLine(instance + ".setMessage(" + getPluginMain() + ".MESSAGE);");
|
linkageTypeMethod.addLine(instance + ".setMessage(" + getPluginMain() + ".MESSAGE);");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ import java.util.Set;
|
|||||||
public class DisableLink implements LinkageType {
|
public class DisableLink implements LinkageType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requirements(String superClass, Set<String> interfaces) {
|
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
|
||||||
return interfaces.contains("de.steamwar.linkage.api.Disable");
|
return interfaces.contains("de.steamwar.linkage.api.Disable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.linkage.types;
|
package de.steamwar.linkage.types;
|
||||||
|
|
||||||
import de.steamwar.linkage.LinkageType;
|
import de.steamwar.linkage.LinkageType;
|
||||||
import de.steamwar.linkage.api.Enable;
|
|
||||||
import de.steamwar.linkage.plan.BuildPlan;
|
import de.steamwar.linkage.plan.BuildPlan;
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
import de.steamwar.linkage.plan.MethodBuilder;
|
||||||
|
|
||||||
@ -30,7 +29,7 @@ import java.util.Set;
|
|||||||
public class EnableLink implements LinkageType {
|
public class EnableLink implements LinkageType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requirements(String superClass, Set<String> interfaces) {
|
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
|
||||||
return interfaces.contains("de.steamwar.linkage.api.Enable");
|
return interfaces.contains("de.steamwar.linkage.api.Enable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ import de.steamwar.linkage.plan.BuildPlan;
|
|||||||
import de.steamwar.linkage.plan.FieldBuilder;
|
import de.steamwar.linkage.plan.FieldBuilder;
|
||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
import de.steamwar.linkage.plan.MethodBuilder;
|
||||||
import de.steamwar.linkage.plan.ParameterBuilder;
|
import de.steamwar.linkage.plan.ParameterBuilder;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
import javax.lang.model.element.*;
|
import javax.lang.model.element.*;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
@ -35,7 +34,7 @@ import java.util.Set;
|
|||||||
public class ListenerLink implements LinkageType {
|
public class ListenerLink implements LinkageType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requirements(String superClass, Set<String> interfaces) {
|
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
|
||||||
if (context == Context.BUNGEE) {
|
if (context == Context.BUNGEE) {
|
||||||
return interfaces.contains("net.md_5.bungee.api.plugin.Listener");
|
return interfaces.contains("net.md_5.bungee.api.plugin.Listener");
|
||||||
} else {
|
} else {
|
||||||
@ -44,12 +43,14 @@ public class ListenerLink implements LinkageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
public void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
if (context == Context.BUNGEE) {
|
|
||||||
buildPlan.addImport("net.md_5.bungee.api.ProxyServer");
|
buildPlan.addImport("net.md_5.bungee.api.ProxyServer");
|
||||||
buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
|
buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
|
||||||
linkageTypeMethod.addLine("ProxyServer.getInstance().getPluginManager().registerListener(BungeeCore.get(), " + instance + ");");
|
linkageTypeMethod.addLine("ProxyServer.getInstance().getPluginManager().registerListener(BungeeCore.get(), " + instance + ");");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
Map<String, TypeElement> eventClasses = new HashMap<>();
|
Map<String, TypeElement> eventClasses = new HashMap<>();
|
||||||
Map<TypeElement, ExecutableElement> eventMethods = new HashMap<>();
|
Map<TypeElement, ExecutableElement> eventMethods = new HashMap<>();
|
||||||
|
|
||||||
@ -110,4 +111,3 @@ public class ListenerLink implements LinkageType {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -24,12 +24,13 @@ import de.steamwar.linkage.plan.BuildPlan;
|
|||||||
import de.steamwar.linkage.plan.MethodBuilder;
|
import de.steamwar.linkage.plan.MethodBuilder;
|
||||||
|
|
||||||
import javax.lang.model.element.TypeElement;
|
import javax.lang.model.element.TypeElement;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class UnlinkListener implements LinkageType {
|
public class UnlinkListener implements LinkageType {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean requirements(String superClass, Set<String> interfaces) {
|
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
|
||||||
if (context == Context.BUNGEE) {
|
if (context == Context.BUNGEE) {
|
||||||
return interfaces.contains("net.md_5.bungee.api.plugin.Listener");
|
return interfaces.contains("net.md_5.bungee.api.plugin.Listener");
|
||||||
} else {
|
} else {
|
||||||
@ -38,14 +39,15 @@ public class UnlinkListener implements LinkageType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
public void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
if (context == Context.BUNGEE) {
|
|
||||||
buildPlan.addImport("net.md_5.bungee.api.ProxyServer");
|
buildPlan.addImport("net.md_5.bungee.api.ProxyServer");
|
||||||
buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
|
buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
|
||||||
linkageTypeMethod.addLine("ProxyServer.getInstance().getPluginManager().registerListener(" + instance + ");");
|
linkageTypeMethod.addLine("ProxyServer.getInstance().getPluginManager().registerListener(" + instance + ");");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
|
||||||
buildPlan.addImport("org.bukkit.event.HandlerList");
|
buildPlan.addImport("org.bukkit.event.HandlerList");
|
||||||
linkageTypeMethod.addLine("HandlerList.unregisterAll(" + instance + ");");
|
linkageTypeMethod.addLine("HandlerList.unregisterAll(" + instance + ");");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren