mirror of
https://github.com/PaperMC/Paper.git
synced 2024-09-27 14:12:45 +02:00
Add datapack registration lifecycle event
This commit is contained in:
parent
d9111ccec2
commit
3d5b27015f
211
patches/api/0477-Add-datapack-registration-lifecycle-event.patch
Normal file
211
patches/api/0477-Add-datapack-registration-lifecycle-event.patch
Normal file
@ -0,0 +1,211 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Sun, 12 May 2024 17:30:54 -0700
|
||||
Subject: [PATCH] Add datapack registration lifecycle event
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/datapack/Datapack.java b/src/main/java/io/papermc/paper/datapack/Datapack.java
|
||||
index 7b2ab0be10a21e0496ad1d485ff8cb2c0b92a2cb..e6037cc5b79b5206e5da8d53c5009932e7c81c86 100644
|
||||
--- a/src/main/java/io/papermc/paper/datapack/Datapack.java
|
||||
+++ b/src/main/java/io/papermc/paper/datapack/Datapack.java
|
||||
@@ -29,4 +29,10 @@ public interface Datapack {
|
||||
COMPATIBLE,
|
||||
}
|
||||
|
||||
+ /**
|
||||
+ * Position of the pack in the load order.
|
||||
+ */
|
||||
+ enum Position {
|
||||
+ TOP, BOTTOM
|
||||
+ }
|
||||
}
|
||||
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..099383a3649f53cd17b01769f562fae878c73579
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datapack/DatapackRegistrar.java
|
||||
@@ -0,0 +1,153 @@
|
||||
+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;
|
||||
+import java.nio.file.Path;
|
||||
+import java.util.function.Consumer;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.Contract;
|
||||
+
|
||||
+/**
|
||||
+ * The registrar for datapacks. The event for this registrar
|
||||
+ * is called anytime the game tries to discover datapacks at any of the
|
||||
+ * configured locations. This means that if a datapack should stay available to the server,
|
||||
+ * it must always be discovered whenever this event fires.
|
||||
+ * <p>An example of a plugin loading a datapack from within it's own jar is below</p>
|
||||
+ * <pre>{@code
|
||||
+ * public class YourPluginBootstrap implements PluginBootstrap {
|
||||
+ * @Override
|
||||
+ * public void bootstrap(BoostrapContext context) {
|
||||
+ * final LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
|
||||
+ * manager.registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, event -> {
|
||||
+ * DatapackRegistrar registrar = event.registrar();
|
||||
+ * try {
|
||||
+ * final URI uri = Objects.requireNonNull(
|
||||
+ * YourPluginBootstrap.class.getResource("/pack")
|
||||
+ * ).toURI();
|
||||
+ * registrar.discoverPack(uri, "packId");
|
||||
+ * } catch (final URISyntaxException | IOException e) {
|
||||
+ * throw new RuntimeException(e);
|
||||
+ * }
|
||||
+ * });
|
||||
+ * }
|
||||
+ * }
|
||||
+ * }</pre>
|
||||
+ * @see io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents#DATAPACK_DISCOVERY
|
||||
+ */
|
||||
+@ApiStatus.NonExtendable
|
||||
+@ApiStatus.Experimental
|
||||
+public interface DatapackRegistrar extends Registrar {
|
||||
+
|
||||
+ /**
|
||||
+ * 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
|
||||
+ * @throws IOException if any IO error occurs
|
||||
+ */
|
||||
+ default void discoverPack(final @NonNull URI uri, final @NonNull String id) throws IOException {
|
||||
+ this.discoverPack(uri, id, c -> {});
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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
|
||||
+ * @param configurer a configurer for extra options
|
||||
+ * @throws IOException if any IO error occurs
|
||||
+ */
|
||||
+ void discoverPack(@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 path the location of the pack
|
||||
+ * @param id a unique id
|
||||
+ * @throws IOException if any IO error occurs
|
||||
+ */
|
||||
+ default void discoverPack(final @NonNull Path path, final @NonNull String id) throws IOException {
|
||||
+ this.discoverPack(path, id, c -> {});
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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
|
||||
+ * @param configurer a configurer for extra options
|
||||
+ * @throws IOException if any IO error occurs
|
||||
+ */
|
||||
+ 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
|
||||
+ @ApiStatus.Experimental
|
||||
+ interface Configurer {
|
||||
+
|
||||
+ /**
|
||||
+ * Changes the title of the datapack from the default which
|
||||
+ * is just the "id" in the {@code registerPack} methods.
|
||||
+ *
|
||||
+ * @param title the new title
|
||||
+ * @return the configurer for chaining
|
||||
+ */
|
||||
+ @Contract(value = "_ -> this", mutates = "this")
|
||||
+ @NonNull Configurer title(@NonNull Component title);
|
||||
+
|
||||
+ /**
|
||||
+ * Sets if this pack is required. Defaults to false.
|
||||
+ * A required pack cannot be disabled.
|
||||
+ *
|
||||
+ * @param required true to require the pack
|
||||
+ * @return the configurer for chaining
|
||||
+ */
|
||||
+ @Contract(value = "_ -> this", mutates = "this")
|
||||
+ @NonNull Configurer required(boolean required);
|
||||
+
|
||||
+ /**
|
||||
+ * Configures the position in the
|
||||
+ * load order of this datapack.
|
||||
+ *
|
||||
+ * @param fixed won't move around in the load order as packs are added/removed
|
||||
+ * @param position try to insert at the top of the order or bottom
|
||||
+ * @return the configurer for chaining
|
||||
+ */
|
||||
+ @Contract(value = "_, _ -> this", mutates = "this")
|
||||
+ @NonNull Configurer position(boolean fixed, Datapack.@NonNull Position position);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java
|
||||
index 1fab48593c567fe05b085ac6e12dc22556cf0b92..dcff07f8fe1627662726611602bd0f8213e39133 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java
|
||||
@@ -1,10 +1,12 @@
|
||||
package io.papermc.paper.plugin.lifecycle.event.types;
|
||||
|
||||
import io.papermc.paper.command.brigadier.Commands;
|
||||
+import io.papermc.paper.datapack.DatapackRegistrar;
|
||||
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent;
|
||||
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
||||
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.registrar.RegistrarEvent;
|
||||
import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -24,6 +26,13 @@ public final class LifecycleEvents {
|
||||
*/
|
||||
public static final LifecycleEventType.Prioritizable<LifecycleEventOwner, ReloadableRegistrarEvent<Commands>> COMMANDS = prioritized("commands", LifecycleEventOwner.class);
|
||||
|
||||
+ /**
|
||||
+ * This event is for informing the server about any available datapacks from other sources such as inside a plugin's jar. You
|
||||
+ * can register a handler for this event only in {@link io.papermc.paper.plugin.bootstrap.PluginBootstrap#bootstrap(BootstrapContext)}.
|
||||
+ * @see DatapackRegistrar an example of a datapack being discovered
|
||||
+ */
|
||||
+ public static final LifecycleEventType.Prioritizable<BootstrapContext, RegistrarEvent<DatapackRegistrar>> DATAPACK_DISCOVERY = prioritized("datapack_discovery", BootstrapContext.class);
|
||||
+
|
||||
//<editor-fold desc="helper methods" defaultstate="collapsed">
|
||||
@ApiStatus.Internal
|
||||
private static <E extends LifecycleEvent> LifecycleEventType.Monitorable<Plugin, E> plugin(final String name) {
|
@ -0,0 +1,240 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Date: Sun, 12 May 2024 17:30:50 -0700
|
||||
Subject: [PATCH] Add datapack registration lifecycle event
|
||||
|
||||
== AT ==
|
||||
public net/minecraft/server/packs/repository/FolderRepositorySource$FolderPackDetector
|
||||
public net/minecraft/server/packs/repository/FolderRepositorySource$FolderPackDetector <init>(Lnet/minecraft/world/level/validation/DirectoryValidator;)V
|
||||
|
||||
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..1930efce70a392d570c237c6bc4bb814d130f64d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datapack/PaperDatapackRegistrarImpl.java
|
||||
@@ -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;
|
||||
+import java.nio.file.Path;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.List;
|
||||
+import java.util.Optional;
|
||||
+import java.util.function.Consumer;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.minecraft.server.packs.PackLocationInfo;
|
||||
+import net.minecraft.server.packs.PackSelectionConfig;
|
||||
+import net.minecraft.server.packs.PackType;
|
||||
+import net.minecraft.server.packs.VanillaPackResourcesBuilder;
|
||||
+import net.minecraft.server.packs.repository.FolderRepositorySource;
|
||||
+import net.minecraft.server.packs.repository.Pack;
|
||||
+import net.minecraft.server.packs.repository.PackDetector;
|
||||
+import net.minecraft.world.level.validation.ContentValidationException;
|
||||
+import net.minecraft.world.level.validation.DirectoryValidator;
|
||||
+import net.minecraft.world.level.validation.ForbiddenSymlinkInfo;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.slf4j.Logger;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public class PaperDatapackRegistrarImpl implements PaperRegistrar<BootstrapContext>, DatapackRegistrar {
|
||||
+
|
||||
+ private static final Logger LOGGER = LogUtils.getClassLogger();
|
||||
+
|
||||
+ private final PackDetector<Pack.ResourcesSupplier> detector;
|
||||
+ private final Consumer<Pack> packAdder;
|
||||
+ private @Nullable BootstrapContext owner;
|
||||
+
|
||||
+ PaperDatapackRegistrarImpl(final DirectoryValidator symlinkValidator, final Consumer<Pack> packAdder) {
|
||||
+ this.detector = new FolderRepositorySource.FolderPackDetector(symlinkValidator);
|
||||
+ this.packAdder = packAdder;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCurrentContext(final @Nullable BootstrapContext owner) {
|
||||
+ this.owner = owner;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void discoverPack(final URI uri, 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(), 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 = pluginMeta.getName() + "/" + id;
|
||||
+ final ConfigurerImpl configurerImpl = new ConfigurerImpl(Component.text(packId));
|
||||
+ configurer.accept(configurerImpl);
|
||||
+ final PackLocationInfo locInfo = new PackLocationInfo(packId,
|
||||
+ PaperAdventure.asVanilla(configurerImpl.title),
|
||||
+ PluginPackSource.INSTANCE,
|
||||
+ Optional.empty()
|
||||
+ );
|
||||
+ final @Nullable Pack pack = Pack.readMetaAndCreate(locInfo,
|
||||
+ resourcesSupplier,
|
||||
+ PackType.SERVER_DATA,
|
||||
+ new PackSelectionConfig(
|
||||
+ configurerImpl.required,
|
||||
+ configurerImpl.position,
|
||||
+ configurerImpl.fixedPosition
|
||||
+ ));
|
||||
+ if (pack != null) {
|
||||
+ this.packAdder.accept(pack);
|
||||
+ }
|
||||
+ } else {
|
||||
+ LOGGER.info("Found non-pack entry '{}', ignoring", path);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ static final class ConfigurerImpl implements Configurer {
|
||||
+
|
||||
+ private Component title;
|
||||
+ private boolean required = false;
|
||||
+ private boolean fixedPosition = false;
|
||||
+ private Pack.Position position = Pack.Position.TOP;
|
||||
+
|
||||
+ ConfigurerImpl(final Component title) {
|
||||
+ this.title = title;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Configurer title(final Component title) {
|
||||
+ this.title = title;
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Configurer required(final boolean required) {
|
||||
+ this.required = required;
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Configurer position(final boolean fixed, final Datapack.Position position) {
|
||||
+ this.fixedPosition = fixed;
|
||||
+ this.position = switch (position) {
|
||||
+ case TOP -> Pack.Position.TOP;
|
||||
+ case BOTTOM -> Pack.Position.BOTTOM;
|
||||
+ };
|
||||
+ return this;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datapack/PluginDatapackRepositorySource.java b/src/main/java/io/papermc/paper/datapack/PluginDatapackRepositorySource.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..b1f0b20c4464de96c416c2d692b3e9e8976b9cfe
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datapack/PluginDatapackRepositorySource.java
|
||||
@@ -0,0 +1,29 @@
|
||||
+package io.papermc.paper.datapack;
|
||||
+
|
||||
+import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner;
|
||||
+import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
+import java.util.function.Consumer;
|
||||
+import net.minecraft.server.packs.repository.Pack;
|
||||
+import net.minecraft.server.packs.repository.RepositorySource;
|
||||
+import net.minecraft.world.level.validation.DirectoryValidator;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public class PluginDatapackRepositorySource implements RepositorySource {
|
||||
+
|
||||
+ private final DirectoryValidator validator;
|
||||
+
|
||||
+ public PluginDatapackRepositorySource(final DirectoryValidator validator) {
|
||||
+ this.validator = validator;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void loadPacks(final Consumer<Pack> packAdder) {
|
||||
+ LifecycleEventRunner.INSTANCE.callStaticRegistrarEvent(LifecycleEvents.DATAPACK_DISCOVERY,
|
||||
+ new PaperDatapackRegistrarImpl(this.validator, packAdder),
|
||||
+ BootstrapContext.class
|
||||
+ );
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datapack/PluginPackSource.java b/src/main/java/io/papermc/paper/datapack/PluginPackSource.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..dfea23ddde7b929f4d47c5de9539cf8bb96bcfff
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datapack/PluginPackSource.java
|
||||
@@ -0,0 +1,26 @@
|
||||
+package io.papermc.paper.datapack;
|
||||
+
|
||||
+import net.minecraft.ChatFormatting;
|
||||
+import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.server.packs.repository.PackSource;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+final class PluginPackSource implements PackSource {
|
||||
+
|
||||
+ static final PackSource INSTANCE = new PluginPackSource();
|
||||
+
|
||||
+ private PluginPackSource() {
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Component decorate(final Component packDisplayName) {
|
||||
+ return Component.translatable("pack.nameAndSource", packDisplayName, "plugin").withStyle(ChatFormatting.GRAY);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean shouldAddAutomatically() {
|
||||
+ return true;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
index cca76f2d1623952017a83fdb027f77a601c79b3e..9770bd30943b81d85e3ccdf1ebdbdf0524bff243 100644
|
||||
--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
+++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/LifecycleEventRunner.java
|
||||
@@ -27,7 +27,8 @@ public class LifecycleEventRunner {
|
||||
|
||||
private static final Logger LOGGER = LogUtils.getClassLogger();
|
||||
private static final Supplier<Set<LifecycleEventType<?, ?, ?>>> BLOCKS_RELOADING = Suppliers.memoize(() -> Set.of( // lazy due to cyclic initialization
|
||||
- LifecycleEvents.COMMANDS
|
||||
+ LifecycleEvents.COMMANDS,
|
||||
+ LifecycleEvents.DATAPACK_DISCOVERY
|
||||
));
|
||||
public static final LifecycleEventRunner INSTANCE = new LifecycleEventRunner();
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/packs/repository/ServerPacksSource.java b/src/main/java/net/minecraft/server/packs/repository/ServerPacksSource.java
|
||||
index 396ec10a76bdadbf5be2f0e15e88eed47619004d..047775cd5528a19e4e3ed40d2e054bcee39d1c74 100644
|
||||
--- a/src/main/java/net/minecraft/server/packs/repository/ServerPacksSource.java
|
||||
+++ b/src/main/java/net/minecraft/server/packs/repository/ServerPacksSource.java
|
||||
@@ -85,6 +85,7 @@ public class ServerPacksSource extends BuiltInPackSource {
|
||||
public static PackRepository createPackRepository(Path dataPacksPath, DirectoryValidator symlinkFinder) {
|
||||
return new PackRepository(
|
||||
new ServerPacksSource(symlinkFinder), new FolderRepositorySource(dataPacksPath, PackType.SERVER_DATA, PackSource.WORLD, symlinkFinder)
|
||||
+ , new io.papermc.paper.datapack.PluginDatapackRepositorySource(symlinkFinder) // Paper - event for finding custom datapacks
|
||||
);
|
||||
}
|
||||
|
@ -1,14 +1,33 @@
|
||||
package io.papermc.testplugin;
|
||||
|
||||
import io.papermc.paper.datapack.DatapackRegistrar;
|
||||
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
|
||||
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
|
||||
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
|
||||
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class TestPluginBootstrap implements PluginBootstrap {
|
||||
|
||||
@Override
|
||||
public void bootstrap(@NotNull BootstrapContext context) {
|
||||
// io.papermc.testplugin.brigtests.Registration.registerViaBootstrap(context);
|
||||
final LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
|
||||
manager.registerEventHandler(LifecycleEvents.DATAPACK_DISCOVERY, event -> {
|
||||
final DatapackRegistrar registrar = event.registrar();
|
||||
try {
|
||||
final URI uri = Objects.requireNonNull(TestPluginBootstrap.class.getResource("/pack")).toURI();
|
||||
registrar.discoverPack(uri, "test");
|
||||
} catch (final URISyntaxException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"values": [
|
||||
"minecraft:zombie",
|
||||
"minecraft:spider"
|
||||
]
|
||||
}
|
6
test-plugin/src/main/resources/pack/pack.mcmeta
Normal file
6
test-plugin/src/main/resources/pack/pack.mcmeta
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"pack":{
|
||||
"pack_format": 41,
|
||||
"description": "Test datapack for tags"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user