mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-04 15:41:31 +00:00
Update Leaves Plugin (#477)
* feat: leaves plugin * fix: license * fix: fix plugins command, fix build * fix: fix comment * fix: do not add MIXIN to availableFeatures when debug option not set
This commit is contained in:
@@ -24,6 +24,9 @@ subprojects {
|
||||
maven("https://repo.leavesmc.org/releases") {
|
||||
content { onlyForConfigurations("leavesclip") }
|
||||
}
|
||||
maven("https://repo.leavesmc.org/snapshots") {
|
||||
content { onlyForConfigurations("leavesclip") }
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<AbstractArchiveTask>().configureEach {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// This file is licensed under the MIT license.
|
||||
package org.leavesmc.leaves.plugin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public interface FeatureManager {
|
||||
Set<String> getAvailableFeatures();
|
||||
|
||||
boolean isFeatureAvailable(String feature);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// This file is licensed under the MIT license.
|
||||
package org.leavesmc.leaves.plugin;
|
||||
|
||||
public class Features {
|
||||
public static final String MIXIN = "mixin";
|
||||
public static final String FAKEPLAYER = "fakeplayer";
|
||||
public static final String PHOTOGRAPHER = "photographer";
|
||||
public static final String RECORDER = "recorder";
|
||||
}
|
||||
@@ -23,7 +23,7 @@
|
||||
dependencies {
|
||||
mache("io.papermc:mache:1.21.5+build.1")
|
||||
- paperclip("io.papermc:paperclip:3.0.3")
|
||||
+ leavesclip("org.leavesmc:leavesclip:2.0.1") // Leaves - build change
|
||||
+ leavesclip("org.leavesmc:leavesclip:3.0.0-SNAPSHOT") // Leaves - build change
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
configurations.named(log4jPlugins.compileClasspathConfigurationName) {
|
||||
extendsFrom(configurations.compileClasspath.get())
|
||||
}
|
||||
@@ -130,7 +_,13 @@
|
||||
@@ -130,7 +_,18 @@
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -94,7 +94,12 @@
|
||||
+ implementation("org.lz4:lz4-java:1.8.0")
|
||||
+ implementation("net.openhft:zero-allocation-hashing:0.16")
|
||||
+ // Leaves end - linear
|
||||
+ implementation("org.spongepowered:configurate-hocon:4.2.0-SNAPSHOT") // Leaves - leaves plugins
|
||||
+ // Leaves start - leaves plugin
|
||||
+ implementation("org.spongepowered:configurate-gson:4.2.0-SNAPSHOT") {
|
||||
+ exclude(group = "com.google.code.gson", module = "gson")
|
||||
+ exclude(group = "com.google.guava", module = "guava")
|
||||
+ }
|
||||
+ // Leaves end - leaves plugin
|
||||
implementation("ca.spottedleaf:concurrentutil:0.0.3")
|
||||
implementation("org.jline:jline-terminal-ffm:3.27.1") // use ffm on java 22+
|
||||
implementation("org.jline:jline-terminal-jni:3.27.1") // fall back to jni on java 21
|
||||
@@ -155,7 +160,7 @@
|
||||
idea {
|
||||
module {
|
||||
generatedSourceDirs.add(generatedDir.toFile())
|
||||
@@ -360,13 +_,24 @@
|
||||
@@ -360,13 +_,26 @@
|
||||
classpath(tasks.createReobfBundlerJar.flatMap { it.outputZip })
|
||||
mainClass.set(null as String?)
|
||||
}
|
||||
@@ -173,11 +178,13 @@
|
||||
+// Leaves start - build change
|
||||
+tasks.registerRunTask("runLeavesclip") {
|
||||
+ description = "Spin up a test server from the Mojang mapped Leavesclip jar"
|
||||
+ systemProperty("leavesclip.enable.mixin", true)
|
||||
+ classpath(tasks.createMojmapLeavesclipJar.flatMap { it.outputZip })
|
||||
+ mainClass.set(null as String?)
|
||||
+}
|
||||
+tasks.registerRunTask("runReobfLeavesclip") {
|
||||
+ description = "Spin up a test server from the reobf Leavesclip jar"
|
||||
+ systemProperty("leavesclip.enable.mixin", true)
|
||||
+ classpath(tasks.createMojmapLeavesclipJar.flatMap { it.outputZip })
|
||||
+ mainClass.set(null as String?)
|
||||
+}
|
||||
|
||||
262
leaves-server/paper-patches/features/0015-Leaves-plugin.patch
Normal file
262
leaves-server/paper-patches/features/0015-Leaves-plugin.patch
Normal file
@@ -0,0 +1,262 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MC_XiaoHei <xiaohei.xor7@outlook.com>
|
||||
Date: Mon, 22 Jul 2024 09:05:56 +0000
|
||||
Subject: [PATCH] Leaves plugin
|
||||
|
||||
This patch is licensed under the MIT license.
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java b/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java
|
||||
index 41c95f00b4b2bea6d31f85e268c33d7f6184823e..a9154645554379d80b43171562f6f64a01ed3792 100644
|
||||
--- a/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java
|
||||
+++ b/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java
|
||||
@@ -172,28 +172,41 @@ public class PaperPluginsCommand extends BukkitCommand {
|
||||
|
||||
final TreeMap<String, PluginProvider<JavaPlugin>> paperPlugins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
final TreeMap<String, PluginProvider<JavaPlugin>> spigotPlugins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
+ // Leaves start - leaves plugin
|
||||
+ final TreeMap<String, PluginProvider<JavaPlugin>> leavesPlugins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (final PluginProvider<JavaPlugin> provider : LaunchEntryPointHandler.INSTANCE.get(Entrypoint.PLUGIN).getRegisteredProviders()) {
|
||||
final PluginMeta configuration = provider.getMeta();
|
||||
|
||||
if (provider instanceof SpigotPluginProvider) {
|
||||
spigotPlugins.put(configuration.getDisplayName(), provider);
|
||||
+ } else if (provider instanceof PaperPluginParent.LeavesServerPluginProvider) {
|
||||
+ leavesPlugins.put(configuration.getDisplayName(), provider);
|
||||
} else if (provider instanceof PaperPluginParent.PaperServerPluginProvider) {
|
||||
paperPlugins.put(configuration.getDisplayName(), provider);
|
||||
}
|
||||
}
|
||||
|
||||
+ final int sizeLeavesPlugins = leavesPlugins.size();
|
||||
final int sizePaperPlugins = paperPlugins.size();
|
||||
final int sizeSpigotPlugins = spigotPlugins.size();
|
||||
- final int sizePlugins = sizePaperPlugins + sizeSpigotPlugins;
|
||||
- final boolean hasAllPluginTypes = (sizePaperPlugins > 0 && sizeSpigotPlugins > 0);
|
||||
+ final int sizePlugins = sizePaperPlugins + sizeSpigotPlugins + sizeLeavesPlugins;
|
||||
+ final boolean showSize = (sizePaperPlugins > 0 && sizeSpigotPlugins > 0) || (sizePaperPlugins > 0 && sizeLeavesPlugins > 0) || (sizeSpigotPlugins > 0 && sizeLeavesPlugins > 0);
|
||||
|
||||
final Component infoMessage = Component.text().append(INFO_ICON_SERVER_PLUGIN).append(Component.text("Server Plugins (%s):".formatted(sizePlugins), NamedTextColor.WHITE)).build();
|
||||
|
||||
sender.sendMessage(infoMessage);
|
||||
|
||||
+ if (!leavesPlugins.isEmpty()) {
|
||||
+ sender.sendMessage(header("Leaves Plugins", 0x37D1AB, sizeLeavesPlugins, showSize));
|
||||
+ }
|
||||
+
|
||||
+ for (final Component component : formatProviders(leavesPlugins)) {
|
||||
+ sender.sendMessage(component);
|
||||
+ }
|
||||
+
|
||||
if (!paperPlugins.isEmpty()) {
|
||||
- sender.sendMessage(header("Paper Plugins", 0x0288D1, sizePaperPlugins, hasAllPluginTypes));
|
||||
+ sender.sendMessage(header("Paper Plugins", 0x0288D1, sizePaperPlugins, showSize));
|
||||
}
|
||||
|
||||
for (final Component component : formatProviders(paperPlugins)) {
|
||||
@@ -201,8 +214,9 @@ public class PaperPluginsCommand extends BukkitCommand {
|
||||
}
|
||||
|
||||
if (!spigotPlugins.isEmpty()) {
|
||||
- sender.sendMessage(header("Bukkit Plugins", 0xED8106, sizeSpigotPlugins, hasAllPluginTypes));
|
||||
+ sender.sendMessage(header("Bukkit Plugins", 0xED8106, sizeSpigotPlugins, showSize));
|
||||
}
|
||||
+ // Leaves end - leaves plugin
|
||||
|
||||
for (final Component component : formatProviders(spigotPlugins)) {
|
||||
sender.sendMessage(component);
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java b/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java
|
||||
index 70413fddd23ca1165cb5090cce4fddcb1bbca93f..2cdf32d5f08b575cf0fe755634242ddb05b59774 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java
|
||||
@@ -117,19 +117,30 @@ public class PluginInitializerManager {
|
||||
java.util.List<Path> files = ((java.util.List<File>) optionSet.valuesOf("add-plugin")).stream().map(File::toPath).toList();
|
||||
io.papermc.paper.plugin.util.EntrypointUtil.registerProvidersFromSource(io.papermc.paper.plugin.provider.source.PluginFlagProviderSource.INSTANCE, files);
|
||||
|
||||
+ // Leaves start - leaves plugin
|
||||
+ final Set<String> leavesPluginNames = new TreeSet<>();
|
||||
final Set<String> paperPluginNames = new TreeSet<>();
|
||||
final Set<String> legacyPluginNames = new TreeSet<>();
|
||||
LaunchEntryPointHandler.INSTANCE.getStorage().forEach((entrypoint, providerStorage) -> {
|
||||
providerStorage.getRegisteredProviders().forEach(provider -> {
|
||||
if (provider instanceof final SpigotPluginProvider legacy) {
|
||||
legacyPluginNames.add(String.format("%s (%s)", legacy.getMeta().getName(), legacy.getMeta().getVersion()));
|
||||
+ } else if (provider instanceof final PaperPluginParent.LeavesServerPluginProvider leaves) {
|
||||
+ leavesPluginNames.add(String.format("%s (%s)", provider.getMeta().getName(), provider.getMeta().getVersion()));
|
||||
} else if (provider instanceof final PaperPluginParent.PaperServerPluginProvider paper) {
|
||||
paperPluginNames.add(String.format("%s (%s)", provider.getMeta().getName(), provider.getMeta().getVersion()));
|
||||
}
|
||||
});
|
||||
});
|
||||
- final int total = paperPluginNames.size() + legacyPluginNames.size();
|
||||
+ final int total = leavesPluginNames.size() + paperPluginNames.size() + legacyPluginNames.size();
|
||||
LOGGER.info("Initialized {} plugin{}", total, total == 1 ? "" : "s");
|
||||
+ if (!leavesPluginNames.isEmpty()) {
|
||||
+ if (LOGGER.isDebugEnabled()) {
|
||||
+ LOGGER.info("Leaves plugins ({}):\n - {}", leavesPluginNames.size(), String.join("\n - ", leavesPluginNames));
|
||||
+ } else {
|
||||
+ LOGGER.info("Leaves plugins ({}):\n - {}", leavesPluginNames.size(), String.join(", ", leavesPluginNames));
|
||||
+ }
|
||||
+ } // Leaves end - leaves plugin
|
||||
if (!paperPluginNames.isEmpty()) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.info("Paper plugins ({}):\n - {}", paperPluginNames.size(), String.join("\n - ", paperPluginNames));
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java b/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java
|
||||
index 8cd649c977172f6b757d68565fcbb9eb8ae100a3..c18a94af99c827d73c31279e324e15ec8217a31d 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
-class LegacyPaperMeta {
|
||||
+public class LegacyPaperMeta {
|
||||
|
||||
|
||||
private static final TypeToken<Map<PluginDependencyLifeCycle, Map<String, DependencyConfiguration>>> TYPE_TOKEN = new TypeToken<>() {
|
||||
@@ -28,6 +28,12 @@ class LegacyPaperMeta {
|
||||
ConfigurationTransformation.chain(notVersioned()).apply(node);
|
||||
}
|
||||
|
||||
+ // Leaves start - leaves plugin
|
||||
+ public static void migrate(org.spongepowered.configurate.ConfigurationNode node) throws ConfigurateException {
|
||||
+ ConfigurationTransformation.chain(notVersioned()).apply(node);
|
||||
+ }
|
||||
+ // Leaves end - leaves plugin
|
||||
+
|
||||
private static ConfigurationTransformation notVersioned() {
|
||||
return ConfigurationTransformation.builder()
|
||||
.addAction(NodePath.path(), (path, value) -> {
|
||||
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 d3b3a8baca013909fa9c6204d964d7d7efeb2719..753fdb9782ee6b4cb8e232ebfdd52dea5d9e2a66 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
|
||||
@@ -55,7 +55,7 @@ public class PaperPluginMeta implements PluginMeta {
|
||||
@Required
|
||||
private String version;
|
||||
private String description;
|
||||
- private List<String> authors = List.of();
|
||||
+ protected List<String> authors = List.of(); // Leaves - leaves plugin
|
||||
private List<String> contributors = List.of();
|
||||
private String website;
|
||||
private String prefix;
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java b/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java
|
||||
index 8d0da6e46d4eb5eb05c3144510c4ef083559d0ec..331a4e98699f65adfad275bde923c0f57ef4dd18 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java
|
||||
@@ -23,6 +23,7 @@ import java.util.jar.JarFile;
|
||||
public abstract class PluginFileType<T, C extends PluginMeta> {
|
||||
|
||||
public static final String PAPER_PLUGIN_YML = "paper-plugin.yml";
|
||||
+ public static final String LEAVES_PLUGIN_JSON = "leaves-plugin.json"; // Leaves - leaves plugin
|
||||
private static final List<String> CONFIG_TYPES = new ArrayList<>();
|
||||
|
||||
public static final PluginFileType<PaperPluginParent, PaperPluginMeta> PAPER = new PluginFileType<>(PAPER_PLUGIN_YML, PaperPluginParent.FACTORY) {
|
||||
@@ -43,8 +44,21 @@ public abstract class PluginFileType<T, C extends PluginMeta> {
|
||||
entrypointHandler.register(Entrypoint.PLUGIN, provider);
|
||||
}
|
||||
};
|
||||
+ // Leaves start - leaves plugin
|
||||
+ public static final PluginFileType<PaperPluginParent, org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta> LEAVES = new PluginFileType<>(LEAVES_PLUGIN_JSON, PaperPluginParent.LEAVES_FACTORY) {
|
||||
+ @Override
|
||||
+ protected void register(EntrypointHandler entrypointHandler, PaperPluginParent parent) {
|
||||
+ PaperPluginParent.LeavesBootstrapProvider bootstrapPluginProvider = null;
|
||||
+ if (parent.shouldCreateBootstrap()) {
|
||||
+ bootstrapPluginProvider = parent.createLeavesBootstrapProvider();
|
||||
+ entrypointHandler.register(Entrypoint.BOOTSTRAPPER, bootstrapPluginProvider);
|
||||
+ }
|
||||
+ entrypointHandler.register(Entrypoint.PLUGIN, parent.createLeavesPluginProvider(bootstrapPluginProvider));
|
||||
+ }
|
||||
+ };
|
||||
|
||||
- private static final List<PluginFileType<?, ?>> VALUES = List.of(PAPER, SPIGOT);
|
||||
+ private static final List<PluginFileType<?, ?>> VALUES = List.of(LEAVES, PAPER, SPIGOT);
|
||||
+ // Leaves end - leaves plugin
|
||||
|
||||
private final String config;
|
||||
private final PluginTypeFactory<T, C> factory;
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
|
||||
index 55a6898e95704cddafda1ca5dc0951c7102fe10b..283f046c6f34c83f01e1ca1d80cbd7cc35a2b7d2 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
|
||||
@@ -27,6 +27,7 @@ import java.util.jar.JarFile;
|
||||
public class PaperPluginParent {
|
||||
|
||||
public static final PluginTypeFactory<PaperPluginParent, PaperPluginMeta> FACTORY = new PaperPluginProviderFactory();
|
||||
+ public static final PluginTypeFactory<PaperPluginParent, org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta> LEAVES_FACTORY = new org.leavesmc.leaves.plugin.provider.LeavesPluginProviderFactory(); // Leaves - leaves plugin
|
||||
private final Path path;
|
||||
private final JarFile jarFile;
|
||||
private final PaperPluginMeta description;
|
||||
@@ -51,6 +52,32 @@ public class PaperPluginParent {
|
||||
return new PaperBootstrapProvider();
|
||||
}
|
||||
|
||||
+ // Leaves start - leaves plugin
|
||||
+ public LeavesBootstrapProvider createLeavesBootstrapProvider() {
|
||||
+ return new io.papermc.paper.plugin.provider.type.paper.PaperPluginParent.LeavesBootstrapProvider();
|
||||
+ }
|
||||
+ public LeavesServerPluginProvider createLeavesPluginProvider(LeavesBootstrapProvider provider) {
|
||||
+ return new LeavesServerPluginProvider(provider);
|
||||
+ }
|
||||
+
|
||||
+ public class LeavesBootstrapProvider extends PaperBootstrapProvider {
|
||||
+ @Override
|
||||
+ public org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta getMeta() {
|
||||
+ return (org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta) super.getMeta();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public class LeavesServerPluginProvider extends PaperServerPluginProvider {
|
||||
+ LeavesServerPluginProvider(PaperPluginParent.LeavesBootstrapProvider bootstrapProvider) {
|
||||
+ super(bootstrapProvider);
|
||||
+ }
|
||||
+ @Override
|
||||
+ public org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta getMeta() {
|
||||
+ return (org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta) super.getMeta();
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaves end - leaves plugin
|
||||
+
|
||||
public PaperServerPluginProvider createPluginProvider(PaperBootstrapProvider provider) {
|
||||
return new PaperServerPluginProvider(provider);
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/storage/SimpleProviderStorage.java b/src/main/java/io/papermc/paper/plugin/storage/SimpleProviderStorage.java
|
||||
index 26422904751647a061397ce978bba752149003cd..884ed63dab16acca83fe8f421762f2561400b1fb 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/storage/SimpleProviderStorage.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/storage/SimpleProviderStorage.java
|
||||
@@ -26,6 +26,16 @@ public abstract class SimpleProviderStorage<T> implements ProviderStorage<T> {
|
||||
|
||||
@Override
|
||||
public void register(PluginProvider<T> provider) {
|
||||
+ // Leaves start - leaves plugin
|
||||
+ if (provider instanceof final io.papermc.paper.plugin.provider.type.paper.PaperPluginParent.LeavesServerPluginProvider leaves) {
|
||||
+ org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta meta = leaves.getMeta();
|
||||
+ java.util.List<String> unavailableFeatures = meta.getFeatures().getRequired().stream().filter(feature -> !org.leavesmc.leaves.plugin.ServerFeatureManager.INSTANCE.isFeatureAvailable(feature)).toList();
|
||||
+ if (!unavailableFeatures.isEmpty()) {
|
||||
+ LOGGER.warn("The plugin {} ({}) requires some unavailable feature(s) {}. The plugin has been skipped.", meta.getName(), meta.getVersion(), unavailableFeatures);
|
||||
+ return;
|
||||
+ }
|
||||
+ }
|
||||
+ // Leaves end - leaves plugin
|
||||
this.providers.add(provider);
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java b/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java
|
||||
index 28857d0c9b53f2068d51b8f09ef40df7a2b97502..3160d5269c40031ad4f9e1444cdf662b7258da30 100644
|
||||
--- a/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java
|
||||
+++ b/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java
|
||||
@@ -333,7 +333,13 @@ public final class PluginRemapper {
|
||||
}
|
||||
index.skip(inputFile);
|
||||
return CompletableFuture.completedFuture(inputFile);
|
||||
- }
|
||||
+ } else if (ns == null && Files.exists(fs.getPath(PluginFileType.LEAVES_PLUGIN_JSON))) { // Leaves start - leaves plugin
|
||||
+ if (DEBUG_LOGGING) {
|
||||
+ LOGGER.info("Plugin '{}' is a Leaves plugin with no namespace specified.", inputFile);
|
||||
+ }
|
||||
+ index.skip(inputFile);
|
||||
+ return CompletableFuture.completedFuture(inputFile);
|
||||
+ } // Leaves end - leaves plugin
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
return CompletableFuture.failedFuture(new RuntimeException("Failed to open plugin jar " + inputFile, ex));
|
||||
@@ -1,145 +0,0 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MC_XiaoHei <xiaohei.xor7@outlook.com>
|
||||
Date: Mon, 22 Jul 2024 09:05:56 +0000
|
||||
Subject: [PATCH] Leaves plugins
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java b/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java
|
||||
index 41c95f00b4b2bea6d31f85e268c33d7f6184823e..9f87a63ec3bd568b187a8358b6a364174fae5493 100644
|
||||
--- a/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java
|
||||
+++ b/src/main/java/io/papermc/paper/command/PaperPluginsCommand.java
|
||||
@@ -172,6 +172,8 @@ public class PaperPluginsCommand extends BukkitCommand {
|
||||
|
||||
final TreeMap<String, PluginProvider<JavaPlugin>> paperPlugins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
final TreeMap<String, PluginProvider<JavaPlugin>> spigotPlugins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
+ // Leaves start - leaves plugin
|
||||
+ final TreeMap<String, PluginProvider<JavaPlugin>> leavesPlugins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
for (final PluginProvider<JavaPlugin> provider : LaunchEntryPointHandler.INSTANCE.get(Entrypoint.PLUGIN).getRegisteredProviders()) {
|
||||
final PluginMeta configuration = provider.getMeta();
|
||||
@@ -179,19 +181,30 @@ public class PaperPluginsCommand extends BukkitCommand {
|
||||
if (provider instanceof SpigotPluginProvider) {
|
||||
spigotPlugins.put(configuration.getDisplayName(), provider);
|
||||
} else if (provider instanceof PaperPluginParent.PaperServerPluginProvider) {
|
||||
- paperPlugins.put(configuration.getDisplayName(), provider);
|
||||
+ if (provider.getMeta() instanceof org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta) leavesPlugins.put(configuration.getDisplayName(), provider);
|
||||
+ else paperPlugins.put(configuration.getDisplayName(), provider);
|
||||
}
|
||||
}
|
||||
|
||||
+ final int sizeLeavesPlugins = leavesPlugins.size();
|
||||
final int sizePaperPlugins = paperPlugins.size();
|
||||
final int sizeSpigotPlugins = spigotPlugins.size();
|
||||
- final int sizePlugins = sizePaperPlugins + sizeSpigotPlugins;
|
||||
- final boolean hasAllPluginTypes = (sizePaperPlugins > 0 && sizeSpigotPlugins > 0);
|
||||
+ final int sizePlugins = sizePaperPlugins + sizeSpigotPlugins + sizeLeavesPlugins;
|
||||
+ final boolean hasAllPluginTypes = (sizePaperPlugins > 0 && sizeSpigotPlugins > 0 && sizeLeavesPlugins > 0);
|
||||
|
||||
final Component infoMessage = Component.text().append(INFO_ICON_SERVER_PLUGIN).append(Component.text("Server Plugins (%s):".formatted(sizePlugins), NamedTextColor.WHITE)).build();
|
||||
|
||||
sender.sendMessage(infoMessage);
|
||||
|
||||
+ if (!leavesPlugins.isEmpty()) {
|
||||
+ sender.sendMessage(header("Leaves Plugins", 0x37D1AB, sizeLeavesPlugins, hasAllPluginTypes));
|
||||
+ }
|
||||
+
|
||||
+ for (final Component component : formatProviders(leavesPlugins)) {
|
||||
+ sender.sendMessage(component);
|
||||
+ }
|
||||
+ // Leaves end - leaves plugin
|
||||
+
|
||||
if (!paperPlugins.isEmpty()) {
|
||||
sender.sendMessage(header("Paper Plugins", 0x0288D1, sizePaperPlugins, hasAllPluginTypes));
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java b/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java
|
||||
index 8cd649c977172f6b757d68565fcbb9eb8ae100a3..390625fbf54139b205a23b94d89a860fbb2c92d9 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/configuration/LegacyPaperMeta.java
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
-class LegacyPaperMeta {
|
||||
+public class LegacyPaperMeta { // Leaves - leaves plugins
|
||||
|
||||
|
||||
private static final TypeToken<Map<PluginDependencyLifeCycle, Map<String, DependencyConfiguration>>> TYPE_TOKEN = new TypeToken<>() {
|
||||
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 d3b3a8baca013909fa9c6204d964d7d7efeb2719..cdde16a4999fbf56c334c65e23d995b7a3604518 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
|
||||
@@ -55,7 +55,7 @@ public class PaperPluginMeta implements PluginMeta {
|
||||
@Required
|
||||
private String version;
|
||||
private String description;
|
||||
- private List<String> authors = List.of();
|
||||
+ protected List<String> authors = List.of(); // Leaves - leaves plugins
|
||||
private List<String> contributors = List.of();
|
||||
private String website;
|
||||
private String prefix;
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java b/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java
|
||||
index 8d0da6e46d4eb5eb05c3144510c4ef083559d0ec..72a69ed1d4cdeecd25bfa4fddc3ecc2b21550bad 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/PluginFileType.java
|
||||
@@ -23,6 +23,7 @@ import java.util.jar.JarFile;
|
||||
public abstract class PluginFileType<T, C extends PluginMeta> {
|
||||
|
||||
public static final String PAPER_PLUGIN_YML = "paper-plugin.yml";
|
||||
+ public static final String LEAVES_PLUGIN_CONF = "leaves-plugin.conf"; // Leaves - leaves plugins
|
||||
private static final List<String> CONFIG_TYPES = new ArrayList<>();
|
||||
|
||||
public static final PluginFileType<PaperPluginParent, PaperPluginMeta> PAPER = new PluginFileType<>(PAPER_PLUGIN_YML, PaperPluginParent.FACTORY) {
|
||||
@@ -43,8 +44,21 @@ public abstract class PluginFileType<T, C extends PluginMeta> {
|
||||
entrypointHandler.register(Entrypoint.PLUGIN, provider);
|
||||
}
|
||||
};
|
||||
+ // Leaves start - leaves plugins
|
||||
+ public static final PluginFileType<PaperPluginParent, org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta> LEAVES = new PluginFileType<>(LEAVES_PLUGIN_CONF, PaperPluginParent.LEAVES_FACTORY) {
|
||||
+ @Override
|
||||
+ protected void register(EntrypointHandler entrypointHandler, PaperPluginParent parent) {
|
||||
+ PaperPluginParent.PaperBootstrapProvider bootstrapPluginProvider = null;
|
||||
+ if (parent.shouldCreateBootstrap()) {
|
||||
+ bootstrapPluginProvider = parent.createBootstrapProvider();
|
||||
+ entrypointHandler.register(Entrypoint.BOOTSTRAPPER, bootstrapPluginProvider);
|
||||
+ }
|
||||
+ entrypointHandler.register(Entrypoint.PLUGIN, parent.createPluginProvider(bootstrapPluginProvider));
|
||||
+ }
|
||||
+ };
|
||||
|
||||
- private static final List<PluginFileType<?, ?>> VALUES = List.of(PAPER, SPIGOT);
|
||||
+ private static final List<PluginFileType<?, ?>> VALUES = List.of(LEAVES, PAPER, SPIGOT);
|
||||
+ // Leaves end - leaves plugins
|
||||
|
||||
private final String config;
|
||||
private final PluginTypeFactory<T, C> factory;
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
|
||||
index 55a6898e95704cddafda1ca5dc0951c7102fe10b..ebde8a79143a5e314d5054f2d125d276eaa1e734 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/type/paper/PaperPluginParent.java
|
||||
@@ -27,6 +27,7 @@ import java.util.jar.JarFile;
|
||||
public class PaperPluginParent {
|
||||
|
||||
public static final PluginTypeFactory<PaperPluginParent, PaperPluginMeta> FACTORY = new PaperPluginProviderFactory();
|
||||
+ public static final PluginTypeFactory<PaperPluginParent, org.leavesmc.leaves.plugin.provider.configuration.LeavesPluginMeta> LEAVES_FACTORY = new org.leavesmc.leaves.plugin.provider.LeavesPluginProviderFactory(); // Leaves - leaves plugins
|
||||
private final Path path;
|
||||
private final JarFile jarFile;
|
||||
private final PaperPluginMeta description;
|
||||
diff --git a/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java b/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java
|
||||
index 28857d0c9b53f2068d51b8f09ef40df7a2b97502..b4d2d7280237a9ad7df095e26773e01211201b84 100644
|
||||
--- a/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java
|
||||
+++ b/src/main/java/io/papermc/paper/pluginremap/PluginRemapper.java
|
||||
@@ -333,7 +333,13 @@ public final class PluginRemapper {
|
||||
}
|
||||
index.skip(inputFile);
|
||||
return CompletableFuture.completedFuture(inputFile);
|
||||
- }
|
||||
+ } else if (ns == null && Files.exists(fs.getPath(PluginFileType.LEAVES_PLUGIN_CONF))) { // Leaves start - leaves plugins
|
||||
+ if (DEBUG_LOGGING) {
|
||||
+ LOGGER.info("Plugin '{}' is a Leaves plugin with no namespace specified.", inputFile);
|
||||
+ }
|
||||
+ index.skip(inputFile);
|
||||
+ return CompletableFuture.completedFuture(inputFile);
|
||||
+ } // Leaves end - leaves plugins
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
return CompletableFuture.failedFuture(new RuntimeException("Failed to open plugin jar " + inputFile, ex));
|
||||
@@ -0,0 +1,32 @@
|
||||
// This file is licensed under the MIT license.
|
||||
package org.leavesmc.leaves.plugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.leavesmc.leaves.plugin.Features.*;
|
||||
|
||||
public class ServerFeatureManager implements FeatureManager {
|
||||
public static ServerFeatureManager INSTANCE = new ServerFeatureManager();
|
||||
private final Set<String> availableFeatures = new HashSet<>();
|
||||
|
||||
private ServerFeatureManager() {
|
||||
availableFeatures.addAll(Set.of(
|
||||
FAKEPLAYER,
|
||||
PHOTOGRAPHER
|
||||
));
|
||||
if (Boolean.getBoolean("leavesclip.enable.mixin")) {
|
||||
availableFeatures.add(MIXIN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAvailableFeatures() {
|
||||
return availableFeatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFeatureAvailable(String feature) {
|
||||
return availableFeatures.contains(feature);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// This file is licensed under the MIT license.
|
||||
package org.leavesmc.leaves.plugin.provider.configuration;
|
||||
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@ConfigSerializable
|
||||
public class FeaturesConfiguration {
|
||||
private List<String> required = List.of();
|
||||
private List<String> optional = List.of();
|
||||
|
||||
public List<String> getRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public List<String> getOptional() {
|
||||
return optional;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// This file is licensed under the MIT license.
|
||||
package org.leavesmc.leaves.plugin.provider.configuration;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -11,9 +12,9 @@ import io.papermc.paper.plugin.provider.configuration.serializer.PermissionConfi
|
||||
import io.papermc.paper.plugin.provider.configuration.serializer.constraints.PluginConfigConstraints;
|
||||
import io.papermc.paper.plugin.provider.configuration.type.PermissionConfiguration;
|
||||
import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.gson.GsonConfigurationLoader;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
import org.spongepowered.configurate.serialize.ScalarSerializer;
|
||||
@@ -21,19 +22,17 @@ import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
@ConfigSerializable
|
||||
public class LeavesPluginMeta extends PaperPluginMeta {
|
||||
private List<String> mixins;
|
||||
static final ApiVersion MINIMUM = ApiVersion.getOrCreateVersion("1.21");
|
||||
private FeaturesConfiguration features = new FeaturesConfiguration();
|
||||
private MixinConfiguration mixin = new MixinConfiguration();
|
||||
static final ApiVersion MINIMUM = ApiVersion.getOrCreateVersion("1.21.4");
|
||||
|
||||
public static LeavesPluginMeta create(BufferedReader reader) throws ConfigurateException {
|
||||
HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
|
||||
.prettyPrinting(true)
|
||||
.emitComments(true)
|
||||
.emitJsonCompatible(true)
|
||||
GsonConfigurationLoader loader = GsonConfigurationLoader.builder()
|
||||
.source(() -> reader)
|
||||
.defaultOptions((options) ->
|
||||
options.serializers((serializers) ->
|
||||
@@ -70,21 +69,30 @@ public class LeavesPluginMeta extends PaperPluginMeta {
|
||||
)
|
||||
)
|
||||
.build();
|
||||
CommentedConfigurationNode node = loader.load();
|
||||
ConfigurationNode node = loader.load();
|
||||
LegacyPaperMeta.migrate(node);
|
||||
LeavesPluginMeta pluginConfiguration = node.require(LeavesPluginMeta.class);
|
||||
|
||||
if (!node.node("author").virtual()) {
|
||||
pluginConfiguration.authors = ImmutableList.<String>builder()
|
||||
var authorNode = node.node("author");
|
||||
if (!authorNode.virtual()) {
|
||||
String author = authorNode.getString();
|
||||
var authorsBuilder = ImmutableList.<String>builder();
|
||||
if (author != null) {
|
||||
authorsBuilder.add(author);
|
||||
}
|
||||
pluginConfiguration.authors = authorsBuilder
|
||||
.addAll(pluginConfiguration.authors)
|
||||
.add(node.node("author").getString())
|
||||
.build();
|
||||
}
|
||||
|
||||
return pluginConfiguration;
|
||||
}
|
||||
|
||||
public List<String> getMixins() {
|
||||
return mixins;
|
||||
public FeaturesConfiguration getFeatures() {
|
||||
return features;
|
||||
}
|
||||
|
||||
public MixinConfiguration getMixin() {
|
||||
return mixin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// This file is licensed under the MIT license.
|
||||
package org.leavesmc.leaves.plugin.provider.configuration;
|
||||
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.PostProcess;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@ConfigSerializable
|
||||
public class MixinConfiguration {
|
||||
private String packageName;
|
||||
private List<String> mixins = List.of();
|
||||
private String accessWidener;
|
||||
|
||||
@PostProcess
|
||||
public void postProcess() {
|
||||
if (mixins.isEmpty()) return;
|
||||
if (packageName == null) {
|
||||
throw new IllegalStateException("Already define mixins: " + mixins + ", but no mixin package-name provided");
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getMixins() {
|
||||
return mixins;
|
||||
}
|
||||
|
||||
public String getAccessWidener() {
|
||||
return accessWidener;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user