Add PluginCheck
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-09-22 19:20:16 +02:00
Ursprung eac3433ed1
Commit 8b7c1e08fd
2 geänderte Dateien mit 57 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -294,6 +294,7 @@ public class LinkageProcessor extends AbstractProcessor {
MaxVersion maxVersion = typeElement.getAnnotation(MaxVersion.class); MaxVersion maxVersion = typeElement.getAnnotation(MaxVersion.class);
EventMode eventMode = typeElement.getAnnotation(EventMode.class); EventMode eventMode = typeElement.getAnnotation(EventMode.class);
DiscordMode discordMode = typeElement.getAnnotation(DiscordMode.class); DiscordMode discordMode = typeElement.getAnnotation(DiscordMode.class);
PluginCheck[] pluginChecks = typeElement.getAnnotationsByType(PluginCheck.class);
if (context == LinkageType.Context.SPIGOT) { if (context == LinkageType.Context.SPIGOT) {
errorOnNonNull(typeElement, eventMode, discordMode); errorOnNonNull(typeElement, eventMode, discordMode);
if (minVersion != null) { if (minVersion != null) {
@ -304,7 +305,14 @@ public class LinkageProcessor extends AbstractProcessor {
buildPlan.addImport("de.steamwar.core.Core"); buildPlan.addImport("de.steamwar.core.Core");
stringConsumer.accept("if (Core.getVersion() < " + maxVersion.value() + ") {"); stringConsumer.accept("if (Core.getVersion() < " + maxVersion.value() + ") {");
} }
if (pluginChecks.length != 0) {
buildPlan.addImport("org.bukkit.Bukkit");
stringConsumer.accept(Arrays.stream(pluginChecks).map(pluginCheck -> {
return "Bukkit.getPluginManager().getPlugin(\"" + pluginCheck.value() + "\") " + (pluginCheck.has() == PluginCheck.Has.THIS ? "=" : "!") + "= null";
}).collect(Collectors.joining(" && ", "if (", ") {")));
}
inner.run(); inner.run();
if (pluginChecks.length != 0) stringConsumer.accept("}");
if (maxVersion != null) stringConsumer.accept("}"); if (maxVersion != null) stringConsumer.accept("}");
if (minVersion != null) stringConsumer.accept("}"); if (minVersion != null) stringConsumer.accept("}");
} else { } else {
@ -317,7 +325,14 @@ public class LinkageProcessor extends AbstractProcessor {
buildPlan.addImport("de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig"); buildPlan.addImport("de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig");
stringConsumer.accept("if (SteamwarDiscordBotConfig.loaded) {"); stringConsumer.accept("if (SteamwarDiscordBotConfig.loaded) {");
} }
if (pluginChecks.length != 0) {
buildPlan.addImport("net.md_5.bungee.BungeeCord");
stringConsumer.accept(Arrays.stream(pluginChecks).map(pluginCheck -> {
return "BungeeCord.getPluginManager().getPlugin(\"" + pluginCheck.value() + "\") " + (pluginCheck.has() == PluginCheck.Has.THIS ? "=" : "!") + "= null";
}).collect(Collectors.joining(" && ", "if (", ") {")));
}
inner.run(); inner.run();
if (pluginChecks.length != 0) stringConsumer.accept("}");
if (discordMode != null) stringConsumer.accept("}"); if (discordMode != null) stringConsumer.accept("}");
if (eventMode != null) stringConsumer.accept("}"); if (eventMode != null) stringConsumer.accept("}");
} }

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.linkage;
import java.lang.annotation.*;
@AllowedContexts({LinkageType.Context.BUNGEE, LinkageType.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 {};
}
}