Skip to content

Commit

Permalink
enable specifying other PluginMeta as 'owners'
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed May 29, 2024
1 parent 7adb8a5 commit 6148b92
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
33 changes: 31 additions & 2 deletions patches/api/0481-Add-datapack-registration-lifecycle-event.patch
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ index 7b2ab0be10a21e0496ad1d485ff8cb2c0b92a2cb..e6037cc5b79b5206e5da8d53c5009932
}
diff --git a/src/main/java/io/papermc/paper/datapack/DatapackRegistrar.java b/src/main/java/io/papermc/paper/datapack/DatapackRegistrar.java
new file mode 100644
index 0000000000000000000000000000000000000000..cf1fd66e6212b007717e766026b76a5f8040f47a
index 0000000000000000000000000000000000000000..e3ac7601fa9f1e86172b817a538164dc8ee25111
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/DatapackRegistrar.java
@@ -0,0 +1,122 @@
@@ -0,0 +1,151 @@
+package io.papermc.paper.datapack;
+
+import io.papermc.paper.plugin.configuration.PluginMeta;
+import io.papermc.paper.plugin.lifecycle.event.registrar.Registrar;
+import java.io.IOException;
+import java.net.URI;
Expand Down Expand Up @@ -69,6 +70,7 @@ index 0000000000000000000000000000000000000000..cf1fd66e6212b007717e766026b76a5f
+
+ /**
+ * Discovers a datapack at the specified {@link URI} with the id.
+ * <p>Symlinks obey the {@code allowed_symlinks.txt} in the server root directory.</p>
+ *
+ * @param uri the location of the pack
+ * @param id a unique id
Expand All @@ -80,6 +82,7 @@ index 0000000000000000000000000000000000000000..cf1fd66e6212b007717e766026b76a5f
+
+ /**
+ * Discovers a datapack at the specified {@link URI} with the id.
+ * <p>Symlinks obey the {@code allowed_symlinks.txt} in the server root directory.</p>
+ *
+ * @param uri the location of the pack
+ * @param id a unique id
Expand All @@ -90,6 +93,7 @@ index 0000000000000000000000000000000000000000..cf1fd66e6212b007717e766026b76a5f
+
+ /**
+ * Discovers a datapack at the specified {@link Path} with the id.
+ * <p>Symlinks obey the {@code allowed_symlinks.txt} in the server root directory.</p>
+ *
+ * @param path the location of the pack
+ * @param id a unique id
Expand All @@ -101,6 +105,7 @@ index 0000000000000000000000000000000000000000..cf1fd66e6212b007717e766026b76a5f
+
+ /**
+ * Discovers a datapack at the specified {@link Path} with the id.
+ * <p>Symlinks obey the {@code allowed_symlinks.txt} in the server root directory.</p>
+ *
+ * @param path the location of the pack
+ * @param id a unique id
Expand All @@ -110,6 +115,30 @@ index 0000000000000000000000000000000000000000..cf1fd66e6212b007717e766026b76a5f
+ void discoverPack(@NonNull Path path, @NonNull String id, @NonNull Consumer<Configurer> configurer) throws IOException;
+
+ /**
+ * Discovers a datapack at the specified {@link URI} with the id.
+ * <p>Symlinks obey the {@code allowed_symlinks.txt} in the server root directory.</p>
+ *
+ * @param pluginMeta the plugin which will be the "owner" of this datapack
+ * @param uri the location of the pack
+ * @param id a unique id
+ * @param configurer a configurer for extra options
+ * @throws IOException if any IO error occurs
+ */
+ void discoverPack(@NonNull PluginMeta pluginMeta, @NonNull URI uri, @NonNull String id, @NonNull Consumer<Configurer> configurer) throws IOException;
+
+ /**
+ * Discovers a datapack at the specified {@link Path} with the id.
+ * <p>Symlinks obey the {@code allowed_symlinks.txt} in the server root directory.</p>
+ *
+ * @param pluginMeta the plugin which will be the "owner" of this datapack
+ * @param path the location of the pack
+ * @param id a unique id
+ * @param configurer a configurer for extra options
+ * @throws IOException if any IO error occurs
+ */
+ void discoverPack(@NonNull PluginMeta pluginMeta, @NonNull Path path, @NonNull String id, @NonNull Consumer<Configurer> configurer) throws IOException;
+
+ /**
+ * Configures additional, optional, details about a datapack.
+ */
+ @ApiStatus.NonExtendable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ public net/minecraft/server/packs/repository/FolderRepositorySource$FolderPackDe

diff --git a/src/main/java/io/papermc/paper/datapack/PaperDatapackRegistrarImpl.java b/src/main/java/io/papermc/paper/datapack/PaperDatapackRegistrarImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..bad03ce8f6a399f9b9903acf41570e471cdc41dc
index 0000000000000000000000000000000000000000..95247155dc8667748f4a780324922fcc030e6a3d
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datapack/PaperDatapackRegistrarImpl.java
@@ -0,0 +1,120 @@
@@ -0,0 +1,132 @@
+package io.papermc.paper.datapack;
+
+import com.google.common.base.Preconditions;
+import com.mojang.logging.LogUtils;
+import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
+import io.papermc.paper.plugin.configuration.PluginMeta;
+import io.papermc.paper.plugin.lifecycle.event.registrar.PaperRegistrar;
+import java.io.IOException;
+import java.net.URI;
Expand All @@ -42,8 +44,6 @@ index 0000000000000000000000000000000000000000..bad03ce8f6a399f9b9903acf41570e47
+import org.checkerframework.framework.qual.DefaultQualifier;
+import org.slf4j.Logger;
+
+import static java.util.Objects.requireNonNull;
+
+@DefaultQualifier(NonNull.class)
+public class PaperDatapackRegistrarImpl implements PaperRegistrar<BootstrapContext>, DatapackRegistrar {
+
Expand All @@ -65,17 +65,29 @@ index 0000000000000000000000000000000000000000..bad03ce8f6a399f9b9903acf41570e47
+
+ @Override
+ public void discoverPack(final URI uri, final String id, final Consumer<Configurer> configurer) throws IOException {
+ this.discoverPack(VanillaPackResourcesBuilder.safeGetPath(uri), id, configurer);
+ Preconditions.checkState(this.owner != null, "Cannot register a datapack without specifying a PluginMeta yet");
+ this.discoverPack(this.owner.getPluginMeta(), uri, id, configurer);
+ }
+
+ @Override
+ public void discoverPack(final Path path, final String id, final Consumer<Configurer> configurer) throws IOException {
+ Preconditions.checkState(this.owner != null, "Cannot register a datapack without specifying a PluginMeta yet");
+ this.discoverPack(this.owner.getPluginMeta(), path, id, configurer);
+ }
+
+ @Override
+ public void discoverPack(final PluginMeta pluginMeta, final URI uri, final String id, final Consumer<Configurer> configurer) throws IOException {
+ this.discoverPack(pluginMeta, VanillaPackResourcesBuilder.safeGetPath(uri), id, configurer);
+ }
+
+ @Override
+ public void discoverPack(final PluginMeta pluginMeta, final Path path, final String id, final Consumer<Configurer> configurer) throws IOException {
+ final List<ForbiddenSymlinkInfo> badLinks = new ArrayList<>();
+ final Pack.@Nullable ResourcesSupplier resourcesSupplier = this.detector.detectPackResources(path, badLinks);
+ if (!badLinks.isEmpty()) {
+ LOGGER.warn("Ignoring potential pack entry: {}", ContentValidationException.getMessage(path, badLinks));
+ } else if (resourcesSupplier != null) {
+ final String packId = requireNonNull(this.owner).getPluginMeta().getName() + "/" + id;
+ final String packId = pluginMeta.getName() + "/" + id;
+ final ConfigurerImpl configurerImpl = new ConfigurerImpl(Component.text(packId));
+ configurer.accept(configurerImpl);
+ final PackLocationInfo locInfo = new PackLocationInfo(packId,
Expand Down

0 comments on commit 6148b92

Please sign in to comment.