Folia/patches/server/0014-Require-plugins-to-be-explicitly-marked-as-Folia-sup.patch
Spottedleaf b3e1b06c07 Fix compilation of TestPluginMeta
Needed to implement isFoliaSupported()
2023-03-29 14:33:48 -07:00

83 lines
4.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Wed, 29 Mar 2023 16:50:14 -0400
Subject: [PATCH] Require plugins to be explicitly marked as Folia supported
diff --git a/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java b/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
index 3808f5a9abc9f084cbabfc4cb95394cc37aaf4bb..19a136c482ba28a2fcedc8e9c889510c974b8f68 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/configuration/PaperPluginMeta.java
@@ -62,6 +62,7 @@ public class PaperPluginMeta implements PluginMeta {
@Required
@PluginConfigConstraints.PluginVersion
private String apiVersion;
+ private boolean foliaSupported = false; // Folia
private transient String displayName;
@@ -204,6 +205,13 @@ public class PaperPluginMeta implements PluginMeta {
return this.apiVersion;
}
+ // Folia start
+ @Override
+ public boolean isFoliaSupported() {
+ return this.foliaSupported;
+ }
+ // Folia end
+
@Override
public @NotNull List<String> getProvidedPlugins() {
return this.provides;
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
index eb0464a52d99a916bca8f93cd9294cdc30893671..923019a5823033871ab61ed9ed7625a2bc4d2b3d 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginProviderFactory.java
@@ -24,6 +24,11 @@ class PaperPluginProviderFactory implements PluginTypeFactory<PaperPluginParent,
@Override
public PaperPluginParent build(JarFile file, PaperPluginMeta configuration, Path source) throws Exception {
+ // Folia start - block plugins not marked as supported
+ if (!configuration.isFoliaSupported()) {
+ throw new RuntimeException("Could not load plugin '" + configuration.getDisplayName() + "' as it is not marked as supporting Folia!");
+ }
+ // Folia end - block plugins not marked as supported
Logger jul = PaperPluginLogger.getLogger(configuration);
ComponentLogger logger = ComponentLogger.logger(jul.getName());
PluginProviderContext context = PluginProviderContextImpl.of(configuration, logger);
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
index 14ed05945ba5bfeb2b539d4786278b0e04130404..ad13d60eeb94a75c97b3d0696c39d834d6082bfa 100644
--- a/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/spigot/SpigotPluginProviderFactory.java
@@ -17,6 +17,11 @@ class SpigotPluginProviderFactory implements PluginTypeFactory<SpigotPluginProvi
@Override
public SpigotPluginProvider build(JarFile file, PluginDescriptionFile configuration, Path source) throws Exception {
+ // Folia start - block plugins not marked as supported
+ if (!configuration.isFoliaSupported()) {
+ throw new RuntimeException("Could not load plugin '" + configuration.getDisplayName() + "' as it is not marked as supporting Folia!");
+ }
+ // Folia end - block plugins not marked as supported
// Copied from SimplePluginManager#loadPlugins
// Spigot doesn't validate the name when the config is created, and instead when the plugin is loaded.
// Paper plugin configuration will do these checks in config serializer instead of when this is created.
diff --git a/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java b/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java
index ba271c35eb2804f94cfc893bf94affb9ae13d3ba..db9285c2ff0c805f5d9564b6e8520c33ea5bb65a 100644
--- a/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java
+++ b/src/test/java/io/papermc/paper/plugin/TestPluginMeta.java
@@ -20,6 +20,13 @@ public class TestPluginMeta implements PluginMeta {
this.identifier = identifier;
}
+ // Folia start - region threading
+ @Override
+ public boolean isFoliaSupported() {
+ return true;
+ }
+ // Folia end - region threading
+
@Override
public @NotNull String getName() {
return this.identifier;