diff --git a/patches/api/0443-Add-Lifecycle-Event-system.patch b/patches/api/0443-Add-Lifecycle-Event-system.patch index 1cf5d6a813..cd999b16ab 100644 --- a/patches/api/0443-Add-Lifecycle-Event-system.patch +++ b/patches/api/0443-Add-Lifecycle-Event-system.patch @@ -8,7 +8,7 @@ meant for managing resources across reloads and from points in the PluginBootstrap. diff --git a/src/main/java/io/papermc/paper/plugin/bootstrap/BootstrapContext.java b/src/main/java/io/papermc/paper/plugin/bootstrap/BootstrapContext.java -index 08f2050356acaf74e3210416760e3873c2dafd2c..37dfdcfcbd14947e0550e7528aca68f452e53eb6 100644 +index 70d5f9802f90605a5120ff2a000a2e9395f0aecc..c319f3bbfabdd39ee571c59d7bfc144c58232abc 100644 --- a/src/main/java/io/papermc/paper/plugin/bootstrap/BootstrapContext.java +++ b/src/main/java/io/papermc/paper/plugin/bootstrap/BootstrapContext.java @@ -1,6 +1,9 @@ @@ -447,23 +447,27 @@ index 0000000000000000000000000000000000000000..92ea0374079a228ccc59c00fcf58abff +} diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProvider.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProvider.java new file mode 100644 -index 0000000000000000000000000000000000000000..1588f6943a909bed053a952e650e043c44028c2d +index 0000000000000000000000000000000000000000..3b17f056d162dd42cae0d33cbbb22fece82fe525 --- /dev/null +++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProvider.java -@@ -0,0 +1,18 @@ +@@ -0,0 +1,22 @@ +package io.papermc.paper.plugin.lifecycle.event.types; + +import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner; ++import java.util.Optional; +import java.util.ServiceLoader; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +interface LifecycleEventTypeProvider { + -+ LifecycleEventTypeProvider PROVIDER = ServiceLoader.load(LifecycleEventTypeProvider.class) -+ .findFirst() -+ .orElseThrow(); ++ Optional INSTANCE = ServiceLoader.load(LifecycleEventTypeProvider.class) ++ .findFirst(); ++ ++ static LifecycleEventTypeProvider provider() { ++ return INSTANCE.orElseThrow(); ++ } + + LifecycleEventType.Monitorable monitor(String name, Class ownerType); + @@ -471,7 +475,7 @@ index 0000000000000000000000000000000000000000..1588f6943a909bed053a952e650e043c +} 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 new file mode 100644 -index 0000000000000000000000000000000000000000..304f978e40e1759bb19704cc5cec399500905195 +index 0000000000000000000000000000000000000000..29476a1a82b3526ac03f21011d297d01462d153e --- /dev/null +++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEvents.java @@ -0,0 +1,52 @@ @@ -494,33 +498,33 @@ index 0000000000000000000000000000000000000000..304f978e40e1759bb19704cc5cec3995 + + // + @ApiStatus.Internal -+ private static LifecycleEventType.Monitorable plugin(final String name) { ++ static LifecycleEventType.Monitorable plugin(final String name) { + return monitor(name, Plugin.class); + } + + @ApiStatus.Internal -+ private static LifecycleEventType.Prioritizable pluginPrioritized(final String name) { ++ static LifecycleEventType.Prioritizable pluginPrioritized(final String name) { + return prioritized(name, Plugin.class); + } + + @ApiStatus.Internal -+ private static LifecycleEventType.Monitorable bootstrap(final String name) { ++ static LifecycleEventType.Monitorable bootstrap(final String name) { + return monitor(name, BootstrapContext.class); + } + + @ApiStatus.Internal -+ private static LifecycleEventType.Prioritizable bootstrapPrioritized(final String name) { ++ static LifecycleEventType.Prioritizable bootstrapPrioritized(final String name) { + return prioritized(name, BootstrapContext.class); + } + + @ApiStatus.Internal -+ private static LifecycleEventType.Monitorable monitor(final String name, final Class ownerType) { -+ return LifecycleEventTypeProvider.PROVIDER.monitor(name, ownerType); ++ static LifecycleEventType.Monitorable monitor(final String name, final Class ownerType) { ++ return LifecycleEventTypeProvider.provider().monitor(name, ownerType); + } + + @ApiStatus.Internal -+ private static LifecycleEventType.Prioritizable prioritized(final String name, final Class ownerType) { -+ return LifecycleEventTypeProvider.PROVIDER.prioritized(name, ownerType); ++ static LifecycleEventType.Prioritizable prioritized(final String name, final Class ownerType) { ++ return LifecycleEventTypeProvider.provider().prioritized(name, ownerType); + } + // + diff --git a/patches/api/0468-Brigadier-based-command-API.patch b/patches/api/0468-Brigadier-based-command-API.patch index 7598f0c8b0..6e20f39837 100644 --- a/patches/api/0468-Brigadier-based-command-API.patch +++ b/patches/api/0468-Brigadier-based-command-API.patch @@ -1540,7 +1540,7 @@ index 0000000000000000000000000000000000000000..159b691e7a1a7066f3e706e80d75ca8f +} diff --git a/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java new file mode 100644 -index 0000000000000000000000000000000000000000..e8c1c0f781bfc852af4a0f01452566ae994dc285 +index 0000000000000000000000000000000000000000..a36a36a46b5d71489e1b3e183d48e6e83721ebdf --- /dev/null +++ b/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProvider.java @@ -0,0 +1,107 @@ @@ -1587,8 +1587,8 @@ index 0000000000000000000000000000000000000000..e8c1c0f781bfc852af4a0f01452566ae + .findFirst(); + + static VanillaArgumentProvider provider() { -+ return PROVIDER.orElseThrow(); -+ } ++ return PROVIDER.orElseThrow(); ++ } + + ArgumentType entity(); + @@ -1914,7 +1914,7 @@ index 0000000000000000000000000000000000000000..906ce6eff30ebd9ec3010ce03b471418 +public interface SelectorArgumentResolver extends ArgumentResolver { +} 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 304f978e40e1759bb19704cc5cec399500905195..1fab48593c567fe05b085ac6e12dc22556cf0b92 100644 +index 29476a1a82b3526ac03f21011d297d01462d153e..dae4935d8e9f46c52f700927a43a9202dac13df6 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,9 +1,11 @@ @@ -1942,7 +1942,7 @@ index 304f978e40e1759bb19704cc5cec399500905195..1fab48593c567fe05b085ac6e12dc225 + // @ApiStatus.Internal - private static LifecycleEventType.Monitorable plugin(final String name) { + static LifecycleEventType.Monitorable plugin(final String name) { diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java index 03d2643d166824458c88a49f20270e93b14f3988..0a26fffe9b1e5080b5639767a03af11006108b4a 100644 --- a/src/main/java/org/bukkit/command/Command.java @@ -2046,7 +2046,7 @@ index 3ec32b46264cfff857b50129b5e0fa5584943ec6..bdfe68b386b5ca2878475e548d3c9a38 return true; diff --git a/src/main/java/org/bukkit/event/server/TabCompleteEvent.java b/src/main/java/org/bukkit/event/server/TabCompleteEvent.java -index b43c3cb5c88eada186d6f81712c244aaa18fb53e..ea26cb90d988d693f26e37229fbdee975c0b11f4 100644 +index 6465e290c090d82986352d5ab7ba5dc65bd3dc17..c71c122ccc4775d030688f7b8df0b4feb49136f4 100644 --- a/src/main/java/org/bukkit/event/server/TabCompleteEvent.java +++ b/src/main/java/org/bukkit/event/server/TabCompleteEvent.java @@ -18,6 +18,8 @@ import org.jetbrains.annotations.NotNull; diff --git a/patches/api/0475-Registry-Modification-API.patch b/patches/api/0475-Registry-Modification-API.patch index 899814f754..58de2e6b76 100644 --- a/patches/api/0475-Registry-Modification-API.patch +++ b/patches/api/0475-Registry-Modification-API.patch @@ -773,10 +773,10 @@ index 0000000000000000000000000000000000000000..a49d328e95f7fda6567ee6c4f5f1878a +} diff --git a/src/main/java/io/papermc/paper/registry/tag/TagKeyImpl.java b/src/main/java/io/papermc/paper/registry/tag/TagKeyImpl.java new file mode 100644 -index 0000000000000000000000000000000000000000..11d19e339c7c62f2eb4467277552c27e4e83069c +index 0000000000000000000000000000000000000000..5fde17e97eddcd1d01ee39694c9159d0ff2a09e3 --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/tag/TagKeyImpl.java -@@ -0,0 +1,12 @@ +@@ -0,0 +1,17 @@ +package io.papermc.paper.registry.tag; + +import io.papermc.paper.registry.RegistryKey; @@ -788,9 +788,14 @@ index 0000000000000000000000000000000000000000..11d19e339c7c62f2eb4467277552c27e +@ApiStatus.Internal +@DefaultQualifier(NonNull.class) +record TagKeyImpl(RegistryKey registryKey, Key key) implements TagKey { ++ ++ @Override ++ public String toString() { ++ return "#" + this.key + " (in " + this.registryKey + ")"; ++ } +} diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java -index cd1e38debbec745dd13cd895327f544dcf42594d..c0428edee6ecbbd646c0e58da39a7ca476914fd1 100644 +index 5d21459e9128c515508a2b4b2265d9824e10d9d5..20015393f91af405c99db2635a471fb6ff19e4bf 100644 --- a/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java @@ -358,6 +358,27 @@ public interface Registry extends Iterable { diff --git a/patches/api/0489-Tag-Lifecycle-Events.patch b/patches/api/0489-Tag-Lifecycle-Events.patch new file mode 100644 index 0000000000..d9fdf676e8 --- /dev/null +++ b/patches/api/0489-Tag-Lifecycle-Events.patch @@ -0,0 +1,406 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Thu, 20 Jun 2024 09:40:53 -0700 +Subject: [PATCH] Tag Lifecycle Events + + +diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProvider.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProvider.java +index 3b17f056d162dd42cae0d33cbbb22fece82fe525..a52ab9e09420768d89385c881fb7a4c424e5b8d6 100644 +--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProvider.java ++++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProvider.java +@@ -19,4 +19,6 @@ interface LifecycleEventTypeProvider { + LifecycleEventType.Monitorable monitor(String name, Class ownerType); + + LifecycleEventType.Prioritizable prioritized(String name, Class ownerType); ++ ++ TagEventTypeProvider tagProvider(); + } +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 dae4935d8e9f46c52f700927a43a9202dac13df6..720fe2546015838708ce794c291ca187cf7bca9c 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 +@@ -24,6 +24,12 @@ public final class LifecycleEvents { + */ + public static final LifecycleEventType.Prioritizable> COMMANDS = prioritized("commands", LifecycleEventOwner.class); + ++ /** ++ * These events are for registering tags to the server's tag system. You can register a handler for these events ++ * only in {@link io.papermc.paper.plugin.bootstrap.PluginBootstrap#bootstrap(BootstrapContext)}. ++ */ ++ public static final TagEventTypeProvider TAGS = LifecycleEventTypeProvider.provider().tagProvider(); ++ + // + @ApiStatus.Internal + static LifecycleEventType.Monitorable plugin(final String name) { +diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/TagEventTypeProvider.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/TagEventTypeProvider.java +new file mode 100644 +index 0000000000000000000000000000000000000000..61c5f6cc6986193eab596ee55e1a414afcf4fbd1 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/TagEventTypeProvider.java +@@ -0,0 +1,40 @@ ++package io.papermc.paper.plugin.lifecycle.event.types; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.tag.PostFlattenTagRegistrar; ++import io.papermc.paper.tag.PreFlattenTagRegistrar; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++ ++/** ++ * Provides event types for tag registration. ++ * ++ * @see PreFlattenTagRegistrar ++ * @see PostFlattenTagRegistrar ++ */ ++@ApiStatus.Experimental ++@ApiStatus.NonExtendable ++public interface TagEventTypeProvider { ++ ++ /** ++ * Get a prioritizable, reloadable registrar event for tags before they are flattened. ++ * ++ * @param registryKey the registry key for the tag type ++ * @return the registry event type ++ * @param the type of value in the tag ++ * @see PreFlattenTagRegistrar ++ */ ++ LifecycleEventType.@NonNull Prioritizable>> preFlatten(@NonNull RegistryKey registryKey); ++ ++ /** ++ * Get a prioritizable, reloadable registrar event for tags after they are flattened. ++ * ++ * @param registryKey the registry key for the tag type ++ * @return the registry event type ++ * @param the type of value in the tag ++ * @see PostFlattenTagRegistrar ++ */ ++ LifecycleEventType.@NonNull Prioritizable>> postFlatten(@NonNull RegistryKey registryKey); ++} +diff --git a/src/main/java/io/papermc/paper/tag/PostFlattenTagRegistrar.java b/src/main/java/io/papermc/paper/tag/PostFlattenTagRegistrar.java +new file mode 100644 +index 0000000000000000000000000000000000000000..32d79dac18c402c3d95edb642eef1563eddf5e9e +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/PostFlattenTagRegistrar.java +@@ -0,0 +1,103 @@ ++package io.papermc.paper.tag; ++ ++import io.papermc.paper.plugin.lifecycle.event.registrar.Registrar; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.tag.TagKey; ++import java.util.Collection; ++import java.util.Map; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++import org.jetbrains.annotations.Unmodifiable; ++ ++/** ++ * Registrar for tags after they have been flattened. Flattened ++ * tags are tags which have any nested tags resolved to the tagged ++ * values the nested tags point to. This registrar, being a post-flatten ++ * registrar, allows for modification after that flattening has happened, when ++ * tags only point to individual entries and not other nested tags. ++ *

++ * An example of a custom enchant being registered to the vanilla ++ * {@code #minecraft:in_enchanting_table} tag. ++ *

{@code
++ * class YourBootstrapClass implements PluginBootstrap {
++ *
++ *     @Override
++ *     public void bootstrap(@NotNull BootstrapContext context) {
++ *         LifecycleEventManager manager = context.getLifecycleManager();
++ *         manager.registerEventHandler(LifecycleEvents.TAGS.postFlatten(RegistryKey.ENCHANTMENT), event -> {
++ *             final PostFlattenTagRegistrar registrar = event.registrar();
++ *             registrar.addToTag(
++ *                 EnchantmentTagKeys.IN_ENCHANTING_TABLE,
++ *                 Set.of(CUSTOM_ENCHANT)
++ *             );
++ *         });
++ *     }
++ * }
++ * }
++ * ++ * @param the type of value in the tag ++ * @see PreFlattenTagRegistrar ++ */ ++@ApiStatus.Experimental ++@ApiStatus.NonExtendable ++public interface PostFlattenTagRegistrar extends Registrar { ++ ++ /** ++ * Get the registry key for this tag registrar. ++ * ++ * @return the registry key ++ */ ++ @NonNull RegistryKey registryKey(); ++ ++ /** ++ * Get a copy of all tags currently held in this registrar. ++ * ++ * @return an immutable map of all tags ++ */ ++ @Contract(value = "-> new", pure = true) ++ @Unmodifiable @NonNull Map, Collection>> getAllTags(); ++ ++ /** ++ * Checks if this registrar has a tag with the given key. ++ * ++ * @param tagKey the key to check for ++ * @return true if the tag exists, false otherwise ++ */ ++ @Contract(pure = true) ++ boolean hasTag(@NonNull TagKey tagKey); ++ ++ /** ++ * Get the tag with the given key. Use {@link #hasTag(TagKey)} to check ++ * if a tag exists first. ++ * ++ * @param tagKey the key of the tag to get ++ * @return an immutable list of tag entries ++ * @throws java.util.NoSuchElementException if the tag does not exist ++ * @see #hasTag(TagKey) ++ */ ++ @Contract(value = "_ -> new", pure = true) ++ @Unmodifiable @NonNull Collection> getTag(@NonNull TagKey tagKey); ++ ++ /** ++ * Adds values to the given tag. If the tag does not exist, it will be created. ++ * ++ * @param tagKey the key of the tag to add to ++ * @param values the values to add ++ * @see #setTag(TagKey, Collection) ++ */ ++ @Contract(mutates = "this") ++ void addToTag(@NonNull TagKey tagKey, @NonNull Collection> values); ++ ++ /** ++ * Sets the values of the given tag. If the tag does not exist, it will be created. ++ * If the tag does exist, it will be overwritten. ++ * ++ * @param tagKey the key of the tag to set ++ * @param values the values to set ++ * @see #addToTag(TagKey, Collection) ++ */ ++ @Contract(mutates = "this") ++ void setTag(@NonNull TagKey tagKey, @NonNull Collection> values); ++} +diff --git a/src/main/java/io/papermc/paper/tag/PreFlattenTagRegistrar.java b/src/main/java/io/papermc/paper/tag/PreFlattenTagRegistrar.java +new file mode 100644 +index 0000000000000000000000000000000000000000..44f7a9d3c2734fb00d11890ece9dc4ce2fafa796 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/PreFlattenTagRegistrar.java +@@ -0,0 +1,102 @@ ++package io.papermc.paper.tag; ++ ++import io.papermc.paper.plugin.lifecycle.event.registrar.Registrar; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.tag.TagKey; ++import java.util.Collection; ++import java.util.List; ++import java.util.Map; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++import org.jetbrains.annotations.Unmodifiable; ++ ++/** ++ * Registrar for tags before they are flattened. Flattened ++ * tags are tags which have any nested tags resolved to the tagged ++ * values the nested tags point to. This registrar, being a pre-flatten ++ * registrar, allows for modification before that flattening has happened, when ++ * tags both point to individual entries and other nested tags. ++ *

++ * An example of a tag being created in a pre-flatten registrar: ++ *

{@code
++ * class YourBootstrapClass implements PluginBootstrap {
++ *
++ *     @Override
++ *     public void bootstrap(@NotNull BootstrapContext context) {
++ *         LifecycleEventManager manager = context.getLifecycleManager();
++ *         manager.registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM), event -> {
++ *             final PreFlattenTagRegistrar registrar = event.registrar();
++ *             registrar.setTag(AXE_PICKAXE, Set.of(
++ *                 TagEntry.tagEntry(ItemTypeTagKeys.PICKAXES),
++ *                 TagEntry.tagEntry(ItemTypeTagKeys.AXES)
++ *             ));
++ *         });
++ *     }
++ * }
++ * }
++ * ++ * @param the type of value in the tag ++ * @see PostFlattenTagRegistrar ++ */ ++@ApiStatus.Experimental ++@ApiStatus.NonExtendable ++public interface PreFlattenTagRegistrar extends Registrar { ++ ++ /** ++ * Get the registry key for this tag registrar. ++ * ++ * @return the registry key ++ */ ++ @NonNull RegistryKey registryKey(); ++ ++ /** ++ * Get a copy of all tags currently held in this registrar. ++ * ++ * @return an immutable map of all tags ++ */ ++ @Contract(value = "-> new", pure = true) ++ @Unmodifiable @NonNull Map, Collection>> getAllTags(); ++ ++ /** ++ * Checks if this registrar has a tag with the given key. ++ * ++ * @param tagKey the key to check for ++ * @return true if the tag exists, false otherwise ++ */ ++ @Contract(pure = true) ++ boolean hasTag(@NonNull TagKey tagKey); ++ ++ /** ++ * Get the tag with the given key. Use {@link #hasTag(TagKey)} to check ++ * if a tag exists first. ++ * ++ * @param tagKey the key of the tag to get ++ * @return an immutable list of tag entries ++ * @throws java.util.NoSuchElementException if the tag does not exist ++ * @see #hasTag(TagKey) ++ */ ++ @Contract(value = "_ -> new", pure = true) ++ @Unmodifiable @NonNull List> getTag(@NonNull TagKey tagKey); ++ ++ /** ++ * Adds entries to the given tag. If the tag does not exist, it will be created. ++ * ++ * @param tagKey the key of the tag to add to ++ * @param entries the entries to add ++ * @see #setTag(TagKey, Collection) ++ */ ++ @Contract(mutates = "this") ++ void addToTag(@NonNull TagKey tagKey, @NonNull Collection> entries); ++ ++ /** ++ * Sets the entries of the given tag. If the tag does not exist, it will be created. ++ * If the tag does exist, it will be overwritten. ++ * ++ * @param tagKey the key of the tag to set ++ * @param entries the entries to set ++ * @see #addToTag(TagKey, Collection) ++ */ ++ @Contract(mutates = "this") ++ void setTag(@NonNull TagKey tagKey, @NonNull Collection> entries); ++} +diff --git a/src/main/java/io/papermc/paper/tag/TagEntry.java b/src/main/java/io/papermc/paper/tag/TagEntry.java +new file mode 100644 +index 0000000000000000000000000000000000000000..436b701f1231354a78a9e0ab04ffd9097343ecfc +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/TagEntry.java +@@ -0,0 +1,89 @@ ++package io.papermc.paper.tag; ++ ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.tag.TagKey; ++import net.kyori.adventure.key.Keyed; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++ ++/** ++ * An entry is a pre-flattened tag. Represents ++ * either an individual registry entry or a whole tag. ++ * ++ * @param the type of value in the tag ++ * @see PreFlattenTagRegistrar ++ */ ++@ApiStatus.Experimental ++@ApiStatus.NonExtendable ++public interface TagEntry extends Keyed { ++ ++ /** ++ * Create required tag entry for a single value. ++ * ++ * @param entryKey the key of the entry ++ * @return a new tag entry for a value ++ * @param the type of value ++ */ ++ @Contract(value = "_ -> new", pure = true) ++ static @NonNull TagEntry valueEntry(final @NonNull TypedKey entryKey) { ++ return valueEntry(entryKey, true); ++ } ++ ++ /** ++ * Create tag entry for a single value. ++ * ++ * @param entryKey the key of the entry ++ * @param isRequired if this entry is required (see {@link #isRequired()}) ++ * @return a new tag entry for a value ++ * @param the type of value ++ */ ++ @Contract(value = "_, _ -> new", pure = true) ++ static @NonNull TagEntry valueEntry(final @NonNull TypedKey entryKey, final boolean isRequired) { ++ return new TagEntryImpl<>(entryKey.key(), false, isRequired); ++ } ++ ++ /** ++ * Create a required tag entry for a nested tag. ++ * ++ * @param tagKey they key for the tag ++ * @return a new tag entry for a tag ++ * @param the type of value ++ */ ++ @Contract(value = "_ -> new", pure = true) ++ static @NonNull TagEntry tagEntry(final @NonNull TagKey tagKey) { ++ return tagEntry(tagKey, true); ++ } ++ ++ /** ++ * Create a tag entry for a nested tag. ++ * ++ * @param tagKey they key for the tag ++ * @param isRequired if this entry is required (see {@link #isRequired()}) ++ * @return a new tag entry for a tag ++ * @param the type of value ++ */ ++ @Contract(value = "_, _ -> new", pure = true) ++ static @NonNull TagEntry tagEntry(final @NonNull TagKey tagKey, final boolean isRequired) { ++ return new TagEntryImpl<>(tagKey.key(), true, isRequired); ++ } ++ ++ /** ++ * Returns if this entry represents a tag. ++ * ++ * @return true if this entry is a tag, false if it is an individual entry ++ */ ++ @Contract(pure = true) ++ boolean isTag(); ++ ++ /** ++ * Returns if this entry is required. If an entry is required, ++ * the value or tag must exist on the server in order for the tag ++ * to load correctly. A missing value will prevent the tag holding ++ * that missing value from being created. ++ * ++ * @return true if this entry is required, false if it is optional ++ */ ++ @Contract(pure = true) ++ boolean isRequired(); ++} +diff --git a/src/main/java/io/papermc/paper/tag/TagEntryImpl.java b/src/main/java/io/papermc/paper/tag/TagEntryImpl.java +new file mode 100644 +index 0000000000000000000000000000000000000000..c0ffd2b9f814d92d0d9b370dfa7e352f1241f614 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/TagEntryImpl.java +@@ -0,0 +1,8 @@ ++package io.papermc.paper.tag; ++ ++import net.kyori.adventure.key.Key; ++import org.jetbrains.annotations.ApiStatus; ++ ++@ApiStatus.Internal ++record TagEntryImpl(Key key, boolean isTag, boolean isRequired) implements TagEntry { ++} diff --git a/patches/server/0930-Add-Lifecycle-Event-system.patch b/patches/server/0930-Add-Lifecycle-Event-system.patch index 0b23164106..4e40ae8cf8 100644 --- a/patches/server/0930-Add-Lifecycle-Event-system.patch +++ b/patches/server/0930-Add-Lifecycle-Event-system.patch @@ -429,10 +429,10 @@ index 0000000000000000000000000000000000000000..6d530c52aaf0dc2cdfe3bd56af557274 +} diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/AbstractLifecycleEventType.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/AbstractLifecycleEventType.java new file mode 100644 -index 0000000000000000000000000000000000000000..9359a36d26970742da3a7abb0050158cd6c64e8e +index 0000000000000000000000000000000000000000..30f47879f87fc991c651416546c2f068209545f2 --- /dev/null +++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/AbstractLifecycleEventType.java -@@ -0,0 +1,54 @@ +@@ -0,0 +1,56 @@ +package io.papermc.paper.plugin.lifecycle.event.types; + +import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent; @@ -468,6 +468,8 @@ index 0000000000000000000000000000000000000000..9359a36d26970742da3a7abb0050158c + } + } + ++ public abstract boolean hasHandlers(); ++ + public abstract void forEachHandler(E event, Consumer> consumer, Predicate> predicate); + + public abstract void removeMatching(Predicate> predicate); @@ -489,7 +491,7 @@ index 0000000000000000000000000000000000000000..9359a36d26970742da3a7abb0050158c +} diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java new file mode 100644 -index 0000000000000000000000000000000000000000..af0cb3298d9c737417c6e54b360f8dc50a5caf04 +index 0000000000000000000000000000000000000000..7e84e0acd50ef04fa1ee2577f49e51c63f5ba5c3 --- /dev/null +++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java @@ -0,0 +1,25 @@ @@ -505,7 +507,7 @@ index 0000000000000000000000000000000000000000..af0cb3298d9c737417c6e54b360f8dc5 +public final class LifecycleEventTypeProviderImpl implements LifecycleEventTypeProvider { + + public static LifecycleEventTypeProviderImpl instance() { -+ return (LifecycleEventTypeProviderImpl) LifecycleEventTypeProvider.PROVIDER; ++ return (LifecycleEventTypeProviderImpl) LifecycleEventTypeProvider.provider(); + } + + @Override @@ -520,10 +522,10 @@ index 0000000000000000000000000000000000000000..af0cb3298d9c737417c6e54b360f8dc5 +} diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/MonitorableLifecycleEventType.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/MonitorableLifecycleEventType.java new file mode 100644 -index 0000000000000000000000000000000000000000..c71912f0050ce0cc6e416948a354c8a66da606a8 +index 0000000000000000000000000000000000000000..abb969cf6ed967fe7720c56d3b3157bd1b74700d --- /dev/null +++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/MonitorableLifecycleEventType.java -@@ -0,0 +1,58 @@ +@@ -0,0 +1,63 @@ +package io.papermc.paper.plugin.lifecycle.event.types; + +import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent; @@ -550,6 +552,11 @@ index 0000000000000000000000000000000000000000..c71912f0050ce0cc6e416948a354c8a6 + } + + @Override ++ public boolean hasHandlers() { ++ return !this.handlers.isEmpty(); ++ } ++ ++ @Override + public MonitorLifecycleEventHandlerConfigurationImpl newHandler(final LifecycleEventHandler handler) { + return new MonitorLifecycleEventHandlerConfigurationImpl<>(handler, this); + } @@ -605,10 +612,10 @@ index 0000000000000000000000000000000000000000..3e7e7474f301c0725fa2bcd6e19e476f +} diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/PrioritizableLifecycleEventType.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/PrioritizableLifecycleEventType.java new file mode 100644 -index 0000000000000000000000000000000000000000..76f92a6fc84c0315f3973dc4e92649b66babc3d5 +index 0000000000000000000000000000000000000000..2ed622a61ddc37b11888867770b513909b9a2ecc --- /dev/null +++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/PrioritizableLifecycleEventType.java -@@ -0,0 +1,74 @@ +@@ -0,0 +1,79 @@ +package io.papermc.paper.plugin.lifecycle.event.types; + +import com.google.common.base.Preconditions; @@ -652,6 +659,11 @@ index 0000000000000000000000000000000000000000..76f92a6fc84c0315f3973dc4e92649b6 + } + + @Override ++ public boolean hasHandlers() { ++ return !this.handlers.isEmpty(); ++ } ++ ++ @Override + protected void register(final O owner, final AbstractLifecycleEventHandlerConfiguration config) { + Preconditions.checkArgument(config instanceof PrioritizedLifecycleEventHandlerConfigurationImpl, "Configuration must be a PrioritizedLifecycleEventHandlerConfiguration"); + this.handlers.add(new RegisteredHandler<>(owner, config)); diff --git a/patches/server/1019-Registry-Modification-API.patch b/patches/server/1019-Registry-Modification-API.patch index 6f8f0a19fa..8a2f279596 100644 --- a/patches/server/1019-Registry-Modification-API.patch +++ b/patches/server/1019-Registry-Modification-API.patch @@ -97,7 +97,7 @@ index 0000000000000000000000000000000000000000..528c6ee1739d92f766f3904acd7fc573 +} diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..a7f2b264d4f37f5293ae72195b4c78faf35351c9 +index 0000000000000000000000000000000000000000..69e946173407eb05b18a2b19b0d45cbb3213570b --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java @@ -0,0 +1,183 @@ @@ -134,12 +134,12 @@ index 0000000000000000000000000000000000000000..a7f2b264d4f37f5293ae72195b4c78fa +import org.checkerframework.checker.nullness.qual.Nullable; +import org.intellij.lang.annotations.Subst; + -+public final class PaperRegistryListenerManager { ++public class PaperRegistryListenerManager { + + public static final PaperRegistryListenerManager INSTANCE = new PaperRegistryListenerManager(); + -+ public final RegistryEventMap valueAddHooks = new RegistryEventMap("value add"); -+ public final RegistryEventMap freezeHooks = new RegistryEventMap("freeze"); ++ public final RegistryEventMap valueAddEventTypes = new RegistryEventMap("value add"); ++ public final RegistryEventMap freezeEventTypes = new RegistryEventMap("freeze"); + + private PaperRegistryListenerManager() { + } @@ -200,7 +200,7 @@ index 0000000000000000000000000000000000000000..a7f2b264d4f37f5293ae72195b4c78fa + ) { + Preconditions.checkState(LaunchEntryPointHandler.INSTANCE.hasEntered(Entrypoint.BOOTSTRAPPER), registry.key() + " tried to run modification listeners before bootstrappers have been called"); // verify that bootstrappers have been called + final @Nullable RegistryEntryInfo entry = PaperRegistries.getEntry(registry.key()); -+ if (!RegistryEntry.Modifiable.isModifiable(entry) || !this.valueAddHooks.hasHooks(entry.apiKey())) { ++ if (!RegistryEntry.Modifiable.isModifiable(entry) || !this.valueAddEventTypes.hasHandlers(entry.apiKey())) { + return registerMethod.register((WritableRegistry) registry, key, nms, registrationInfo); + } + final RegistryEntry.Modifiable modifiableEntry = RegistryEntry.Modifiable.asModifiable(entry); @@ -217,7 +217,7 @@ index 0000000000000000000000000000000000000000..a7f2b264d4f37f5293ae72195b4c78fa + final RegistrationInfo registrationInfo, + final Conversions conversions + ) { -+ if (!RegistryEntry.Modifiable.isModifiable(entry) || !this.valueAddHooks.hasHooks(entry.apiKey())) { ++ if (!RegistryEntry.Modifiable.isModifiable(entry) || !this.valueAddEventTypes.hasHandlers(entry.apiKey())) { + registry.register(key, builder.build(), registrationInfo); + return; + } @@ -237,7 +237,7 @@ index 0000000000000000000000000000000000000000..a7f2b264d4f37f5293ae72195b4c78fa + @Subst("namespace:key") final ResourceLocation beingAdded = key.location(); + @SuppressWarnings("PatternValidation") final TypedKey typedKey = TypedKey.create(entry.apiKey(), Key.key(beingAdded.getNamespace(), beingAdded.getPath())); + final RegistryEntryAddEventImpl event = entry.createEntryAddEvent(typedKey, builder, conversions); -+ LifecycleEventRunner.INSTANCE.callEvent(this.valueAddHooks.getHook(entry.apiKey()), event); ++ LifecycleEventRunner.INSTANCE.callEvent(this.valueAddEventTypes.getEventType(entry.apiKey()), event); + if (oldNms != null) { + ((MappedRegistry) registry).clearIntrusiveHolder(oldNms); + } @@ -261,27 +261,27 @@ index 0000000000000000000000000000000000000000..a7f2b264d4f37f5293ae72195b4c78fa + + public > void runFreezeListeners(final ResourceKey> resourceKey, final Conversions conversions) { + final @Nullable RegistryEntryInfo entry = PaperRegistries.getEntry(resourceKey); -+ if (!RegistryEntry.Addable.isAddable(entry) || !this.freezeHooks.hasHooks(entry.apiKey())) { ++ if (!RegistryEntry.Addable.isAddable(entry) || !this.freezeEventTypes.hasHandlers(entry.apiKey())) { + return; + } + final RegistryEntry.Addable writableEntry = RegistryEntry.Addable.asAddable(entry); + final WritableCraftRegistry writableRegistry = PaperRegistryAccess.instance().getWritableRegistry(entry.apiKey()); + final RegistryFreezeEventImpl event = writableEntry.createFreezeEvent(writableRegistry, conversions); -+ LifecycleEventRunner.INSTANCE.callEvent(this.freezeHooks.getHook(entry.apiKey()), event); ++ LifecycleEventRunner.INSTANCE.callEvent(this.freezeEventTypes.getEventType(entry.apiKey()), event); + } + + public > RegistryEntryAddEventType getRegistryValueAddEventType(final RegistryEventProvider type) { + if (!RegistryEntry.Modifiable.isModifiable(PaperRegistries.getEntry(type.registryKey()))) { + throw new IllegalArgumentException(type.registryKey() + " does not support RegistryEntryAddEvent"); + } -+ return this.valueAddHooks.getOrCreate(type, RegistryEntryAddEventTypeImpl::new); ++ return this.valueAddEventTypes.getOrCreate(type.registryKey(), RegistryEntryAddEventTypeImpl::new); + } + + public > LifecycleEventType.Prioritizable> getRegistryFreezeEventType(final RegistryEventProvider type) { + if (!RegistryEntry.Addable.isAddable(PaperRegistries.getEntry(type.registryKey()))) { + throw new IllegalArgumentException(type.registryKey() + " does not support RegistryFreezeEvent"); + } -+ return this.freezeHooks.getOrCreate(type, RegistryLifecycleEventType::new); ++ return this.freezeEventTypes.getOrCreate(type.registryKey(), RegistryLifecycleEventType::new); + } +} diff --git a/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java b/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java @@ -695,16 +695,17 @@ index 0000000000000000000000000000000000000000..cc9c8fd313f530777af80ad79e03903f +} diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java new file mode 100644 -index 0000000000000000000000000000000000000000..f5ea23173dcbe491742c3dd051c147ef397307a0 +index 0000000000000000000000000000000000000000..5e09cebc3893ab788f7b1d169c5ac48a3e45afc1 --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventMap.java -@@ -0,0 +1,44 @@ +@@ -0,0 +1,46 @@ +package io.papermc.paper.registry.event; + +import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent; +import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner; ++import io.papermc.paper.plugin.lifecycle.event.types.AbstractLifecycleEventType; +import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; -+import io.papermc.paper.registry.RegistryBuilder; +import io.papermc.paper.registry.RegistryKey; +import java.util.HashMap; +import java.util.Map; @@ -713,7 +714,7 @@ index 0000000000000000000000000000000000000000..f5ea23173dcbe491742c3dd051c147ef + +public final class RegistryEventMap { + -+ private final Map, LifecycleEventType, ?>> hooks = new HashMap<>(); ++ private final Map, LifecycleEventType> eventTypes = new HashMap<>(); + private final String name; + + public RegistryEventMap(final String name) { @@ -721,25 +722,26 @@ index 0000000000000000000000000000000000000000..f5ea23173dcbe491742c3dd051c147ef + } + + @SuppressWarnings("unchecked") -+ public , E extends RegistryEvent, ET extends LifecycleEventType> ET getOrCreate(final RegistryEventProvider type, final BiFunction, ? super String, ET> eventTypeCreator) { -+ final ET registerHook; -+ if (this.hooks.containsKey(type.registryKey())) { -+ registerHook = (ET) this.hooks.get(type.registryKey()); ++ public > ET getOrCreate(final RegistryKey registryKey, final BiFunction, ? super String, ET> eventTypeCreator) { ++ final ET eventType; ++ if (this.eventTypes.containsKey(registryKey)) { ++ eventType = (ET) this.eventTypes.get(registryKey); + } else { -+ registerHook = eventTypeCreator.apply(type, this.name); -+ LifecycleEventRunner.INSTANCE.addEventType(registerHook); -+ this.hooks.put(type.registryKey(), registerHook); ++ eventType = eventTypeCreator.apply(registryKey, this.name); ++ LifecycleEventRunner.INSTANCE.addEventType(eventType); ++ this.eventTypes.put(registryKey, eventType); + } -+ return registerHook; ++ return eventType; + } + + @SuppressWarnings("unchecked") -+ public > LifecycleEventType getHook(final RegistryKey registryKey) { -+ return (LifecycleEventType) Objects.requireNonNull(this.hooks.get(registryKey), "No hook for " + registryKey); ++ public LifecycleEventType getEventType(final RegistryKey registryKey) { ++ return (LifecycleEventType) Objects.requireNonNull(this.eventTypes.get(registryKey), "No hook for " + registryKey); + } + -+ public boolean hasHooks(final RegistryKey registryKey) { -+ return this.hooks.containsKey(registryKey); ++ public boolean hasHandlers(final RegistryKey registryKey) { ++ final AbstractLifecycleEventType type = ((AbstractLifecycleEventType) this.eventTypes.get(registryKey)); ++ return type != null && type.hasHandlers(); + } + +} @@ -820,7 +822,7 @@ index 0000000000000000000000000000000000000000..14d2d9766b8dee763f220c397aba3ad4 +import org.checkerframework.framework.qual.DefaultQualifier; diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java new file mode 100644 -index 0000000000000000000000000000000000000000..5d709ed04e1078b631f5b9c74ca35f042251e14f +index 0000000000000000000000000000000000000000..0655386f85148cdb840d43ada97ab86bb773a765 --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java @@ -0,0 +1,32 @@ @@ -830,15 +832,15 @@ index 0000000000000000000000000000000000000000..5d709ed04e1078b631f5b9c74ca35f04 +import io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler; +import io.papermc.paper.plugin.lifecycle.event.types.PrioritizableLifecycleEventType; +import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.event.RegistryEntryAddEvent; -+import io.papermc.paper.registry.event.RegistryEventProvider; +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class RegistryEntryAddEventTypeImpl> extends PrioritizableLifecycleEventType, RegistryEntryAddConfiguration> implements RegistryEntryAddEventType { + -+ public RegistryEntryAddEventTypeImpl(final RegistryEventProvider type, final String eventName) { -+ super(type.registryKey() + " / " + eventName, BootstrapContext.class); ++ public RegistryEntryAddEventTypeImpl(final RegistryKey registryKey, final String eventName) { ++ super(registryKey + " / " + eventName, BootstrapContext.class); + } + + @Override @@ -906,22 +908,21 @@ index 0000000000000000000000000000000000000000..548f5bf979e88708e98d04dfe22ccaa3 +} diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java new file mode 100644 -index 0000000000000000000000000000000000000000..dcc0f6b337840a78d38abdf2eb3f4bbd1676f58f +index 0000000000000000000000000000000000000000..159bb82c27e8fc8f350985f03082fe218fda3568 --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryLifecycleEventType.java -@@ -0,0 +1,14 @@ +@@ -0,0 +1,13 @@ +package io.papermc.paper.registry.event.type; + +import io.papermc.paper.plugin.bootstrap.BootstrapContext; +import io.papermc.paper.plugin.lifecycle.event.types.PrioritizableLifecycleEventType; -+import io.papermc.paper.registry.RegistryBuilder; ++import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.event.RegistryEvent; -+import io.papermc.paper.registry.event.RegistryEventProvider; + -+public final class RegistryLifecycleEventType, E extends RegistryEvent> extends PrioritizableLifecycleEventType.Simple { ++public final class RegistryLifecycleEventType> extends PrioritizableLifecycleEventType.Simple { + -+ public RegistryLifecycleEventType(final RegistryEventProvider type, final String eventName) { -+ super(type.registryKey() + " / " + eventName, BootstrapContext.class); ++ public RegistryLifecycleEventType(final RegistryKey registryKey, final String eventName) { ++ super(registryKey + " / " + eventName, BootstrapContext.class); + } +} diff --git a/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistry.java diff --git a/patches/server/1020-Add-registry-entry-and-builders.patch b/patches/server/1020-Add-registry-entry-and-builders.patch index 7978bd6ce2..9125594884 100644 --- a/patches/server/1020-Add-registry-entry-and-builders.patch +++ b/patches/server/1020-Add-registry-entry-and-builders.patch @@ -37,7 +37,7 @@ index 32ade3ed8533b127e8f5c1cc8b3466249e5444a3..6ec9d9b9acf557aa2ebf39d38a14225b diff --git a/src/main/java/io/papermc/paper/registry/data/PaperEnchantmentRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaperEnchantmentRegistryEntry.java new file mode 100644 -index 0000000000000000000000000000000000000000..b9501554a0738776c265852184c7dbae3fe98c8c +index 0000000000000000000000000000000000000000..481f5f0cfae1fada3bc3f873fb7e04c3086ea9bf --- /dev/null +++ b/src/main/java/io/papermc/paper/registry/data/PaperEnchantmentRegistryEntry.java @@ -0,0 +1,234 @@ @@ -96,7 +96,7 @@ index 0000000000000000000000000000000000000000..b9501554a0738776c265852184c7dbae + protected HolderSet exclusiveWith = HolderSet.empty(); // Paper added default to empty. + + // Effects -+ protected final DataComponentMap effects; ++ protected DataComponentMap effects; + + protected final Conversions conversions; + diff --git a/patches/server/1059-Tag-Lifecycle-Events.patch b/patches/server/1059-Tag-Lifecycle-Events.patch new file mode 100644 index 0000000000..547a10d9e3 --- /dev/null +++ b/patches/server/1059-Tag-Lifecycle-Events.patch @@ -0,0 +1,537 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Thu, 20 Jun 2024 09:40:57 -0700 +Subject: [PATCH] Tag Lifecycle Events + +== AT == +public net/minecraft/tags/TagEntry id +public net/minecraft/tags/TagEntry tag +public net/minecraft/tags/TagEntry required + +diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java +index 7e84e0acd50ef04fa1ee2577f49e51c63f5ba5c3..05ceb6a0556c5e958237cd8e17525343dc3e8458 100644 +--- a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java ++++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/LifecycleEventTypeProviderImpl.java +@@ -13,6 +13,8 @@ public final class LifecycleEventTypeProviderImpl implements LifecycleEventTypeP + return (LifecycleEventTypeProviderImpl) LifecycleEventTypeProvider.provider(); + } + ++ private final PaperTagEventTypeProvider provider = new PaperTagEventTypeProvider(); ++ + @Override + public LifecycleEventType.Monitorable monitor(final String name, final Class ownerType) { + return LifecycleEventRunner.INSTANCE.addEventType(new MonitorableLifecycleEventType<>(name, ownerType)); +@@ -22,4 +24,9 @@ public final class LifecycleEventTypeProviderImpl implements LifecycleEventTypeP + public LifecycleEventType.Prioritizable prioritized(final String name, final Class ownerType) { + return LifecycleEventRunner.INSTANCE.addEventType(new PrioritizableLifecycleEventType.Simple<>(name, ownerType)); + } ++ ++ @Override ++ public PaperTagEventTypeProvider tagProvider() { ++ return this.provider; ++ } + } +diff --git a/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/PaperTagEventTypeProvider.java b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/PaperTagEventTypeProvider.java +new file mode 100644 +index 0000000000000000000000000000000000000000..1cf4a3caa8d630e95eb569eef2cd577bba1a97a9 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/plugin/lifecycle/event/types/PaperTagEventTypeProvider.java +@@ -0,0 +1,24 @@ ++package io.papermc.paper.plugin.lifecycle.event.types; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.tag.PaperTagListenerManager; ++import io.papermc.paper.tag.PostFlattenTagRegistrar; ++import io.papermc.paper.tag.PreFlattenTagRegistrar; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@DefaultQualifier(NonNull.class) ++public class PaperTagEventTypeProvider implements TagEventTypeProvider { ++ ++ @Override ++ public PrioritizableLifecycleEventType.Simple>> preFlatten(final RegistryKey registryKey) { ++ return PaperTagListenerManager.INSTANCE.getPreFlattenType(registryKey); ++ } ++ ++ @Override ++ public PrioritizableLifecycleEventType.Simple>> postFlatten(final RegistryKey registryKey) { ++ return PaperTagListenerManager.INSTANCE.getPostFlattenType(registryKey); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/tag/PaperPostFlattenTagRegistrar.java b/src/main/java/io/papermc/paper/tag/PaperPostFlattenTagRegistrar.java +new file mode 100644 +index 0000000000000000000000000000000000000000..cc37618cbbad7f21d65c7753f4dd4416042d2146 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/PaperPostFlattenTagRegistrar.java +@@ -0,0 +1,118 @@ ++package io.papermc.paper.tag; ++ ++import com.google.common.collect.Collections2; ++import com.google.common.collect.ImmutableMap; ++import io.papermc.paper.adventure.PaperAdventure; ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.registrar.PaperRegistrar; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.tag.TagKey; ++import java.util.ArrayList; ++import java.util.Collection; ++import java.util.Collections; ++import java.util.List; ++import java.util.Map; ++import java.util.NoSuchElementException; ++import java.util.Optional; ++import java.util.function.Function; ++import net.minecraft.resources.ResourceLocation; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.checker.nullness.qual.Nullable; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@SuppressWarnings("BoundedWildcard") ++@DefaultQualifier(NonNull.class) ++public class PaperPostFlattenTagRegistrar implements PaperRegistrar, PostFlattenTagRegistrar { ++ ++ public final Map> tags; ++ private final Function> fromIdConverter; ++ private final Function toIdConverter; ++ private final RegistryKey registryKey; ++ ++ public PaperPostFlattenTagRegistrar( ++ final Map> tags, ++ final TagEventConfig config ++ ) { ++ this.tags = tags; ++ this.fromIdConverter = config.fromIdConverter(); ++ this.toIdConverter = config.toIdConverter(); ++ this.registryKey = config.apiRegistryKey(); ++ } ++ ++ @Override ++ public void setCurrentContext(final @Nullable BootstrapContext owner) { ++ } ++ ++ @Override ++ public RegistryKey registryKey() { ++ return this.registryKey; ++ } ++ ++ @Override ++ public Map, Collection>> getAllTags() { ++ final ImmutableMap.Builder, Collection>> tags = ImmutableMap.builderWithExpectedSize(this.tags.size()); ++ for (final Map.Entry> entry : this.tags.entrySet()) { ++ final TagKey key = TagKey.create(this.registryKey, CraftNamespacedKey.fromMinecraft(entry.getKey())); ++ tags.put(key, this.convert(entry.getValue())); ++ } ++ return tags.build(); ++ } ++ ++ private Collection> convert(final Collection nms) { ++ return Collections.unmodifiableCollection( ++ Collections2.transform(nms, m -> this.convert(this.toIdConverter.apply(m))) ++ ); ++ } ++ ++ private TypedKey convert(final ResourceLocation location) { ++ return TypedKey.create(this.registryKey, CraftNamespacedKey.fromMinecraft(location)); ++ } ++ ++ private M convert(final TypedKey key) { ++ final Optional optional = this.fromIdConverter.apply(PaperAdventure.asVanilla(key.key())); ++ if (optional.isEmpty()) { ++ throw new IllegalArgumentException(key + " doesn't exist"); ++ } ++ return optional.get(); ++ } ++ ++ @Override ++ public boolean hasTag(final TagKey tagKey) { ++ return this.tags.containsKey(PaperAdventure.asVanilla(tagKey.key())); ++ } ++ ++ private Collection getNmsTag(final TagKey tagKey, final boolean create) { ++ final ResourceLocation vanillaKey = PaperAdventure.asVanilla(tagKey.key()); ++ Collection tag = this.tags.get(vanillaKey); ++ if (tag == null) { ++ if (create) { ++ tag = this.tags.computeIfAbsent(vanillaKey, k -> new ArrayList<>()); ++ } else { ++ throw new NoSuchElementException("Tag " + tagKey + " is not present"); ++ } ++ } ++ return tag; ++ } ++ ++ @Override ++ public Collection> getTag(final TagKey tagKey) { ++ return this.convert(this.getNmsTag(tagKey, false)); ++ } ++ ++ @Override ++ public void addToTag(final TagKey tagKey, final Collection> values) { ++ final Collection nmsTag = new ArrayList<>(this.getNmsTag(tagKey, true)); ++ for (final TypedKey key : values) { ++ nmsTag.add(this.convert(key)); ++ } ++ this.tags.put(PaperAdventure.asVanilla(tagKey.key()), nmsTag); ++ } ++ ++ @Override ++ public void setTag(final TagKey tagKey, final Collection> values) { ++ final List newList = List.copyOf(Collections2.transform(values, this::convert)); ++ this.tags.put(PaperAdventure.asVanilla(tagKey.key()), newList); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/tag/PaperPreFlattenTagRegistrar.java b/src/main/java/io/papermc/paper/tag/PaperPreFlattenTagRegistrar.java +new file mode 100644 +index 0000000000000000000000000000000000000000..44111b55eaa6d1cc93e2c556b23bb5c97953caac +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/PaperPreFlattenTagRegistrar.java +@@ -0,0 +1,128 @@ ++package io.papermc.paper.tag; ++ ++import com.google.common.base.Preconditions; ++import com.google.common.collect.Collections2; ++import com.google.common.collect.ImmutableMap; ++import com.google.common.collect.Lists; ++import io.papermc.paper.adventure.PaperAdventure; ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.registrar.PaperRegistrar; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.tag.TagKey; ++import java.util.ArrayList; ++import java.util.Collection; ++import java.util.Collections; ++import java.util.HashMap; ++import java.util.List; ++import java.util.Map; ++import java.util.NoSuchElementException; ++import net.minecraft.resources.ResourceLocation; ++import net.minecraft.tags.TagLoader; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.checker.nullness.qual.Nullable; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@SuppressWarnings("BoundedWildcard") ++@DefaultQualifier(NonNull.class) ++public class PaperPreFlattenTagRegistrar implements PaperRegistrar, PreFlattenTagRegistrar { ++ ++ public final Map> tags; ++ private final RegistryKey registryKey; ++ ++ private @Nullable BootstrapContext owner; ++ ++ public PaperPreFlattenTagRegistrar( ++ final Map> tags, ++ final TagEventConfig config ++ ) { ++ this.tags = new HashMap<>(tags); ++ this.registryKey = config.apiRegistryKey(); ++ } ++ ++ @Override ++ public void setCurrentContext(final @Nullable BootstrapContext owner) { ++ this.owner = owner; ++ } ++ ++ @Override ++ public RegistryKey registryKey() { ++ return this.registryKey; ++ } ++ ++ @Override ++ public Map, Collection>> getAllTags() { ++ final ImmutableMap.Builder, Collection>> builder = ImmutableMap.builderWithExpectedSize(this.tags.size()); ++ for (final Map.Entry> entry : this.tags.entrySet()) { ++ final TagKey key = TagKey.create(this.registryKey, CraftNamespacedKey.fromMinecraft(entry.getKey())); ++ builder.put(key, convert(entry.getValue())); ++ } ++ return builder.build(); ++ } ++ ++ private static List> convert(final List nmsEntries) { ++ return Collections.unmodifiableList(Lists.transform(nmsEntries, PaperPreFlattenTagRegistrar::convert)); ++ } ++ ++ private static io.papermc.paper.tag.TagEntry convert(final TagLoader.EntryWithSource nmsEntry) { ++ return new TagEntryImpl<>(CraftNamespacedKey.fromMinecraft(nmsEntry.entry().id), nmsEntry.entry().tag, nmsEntry.entry().required); ++ } ++ ++ private TagLoader.EntryWithSource convert(final TagEntry entry) { ++ Preconditions.checkState(this.owner != null, "Owner is not set"); ++ final ResourceLocation vanilla = PaperAdventure.asVanilla(entry.key()); ++ final net.minecraft.tags.TagEntry nmsEntry; ++ if (entry.isTag()) { ++ if (entry.isRequired()) { ++ nmsEntry = net.minecraft.tags.TagEntry.tag(vanilla); ++ } else { ++ nmsEntry = net.minecraft.tags.TagEntry.optionalTag(vanilla); ++ } ++ } else { ++ if (entry.isRequired()) { ++ nmsEntry = net.minecraft.tags.TagEntry.element(vanilla); ++ } else { ++ nmsEntry = net.minecraft.tags.TagEntry.optionalElement(vanilla); ++ } ++ } ++ return new TagLoader.EntryWithSource(nmsEntry, this.owner.getPluginMeta().getDisplayName()); ++ } ++ ++ @Override ++ public boolean hasTag(final TagKey tagKey) { ++ return this.tags.containsKey(PaperAdventure.asVanilla(tagKey.key())); ++ } ++ ++ private List getNmsTag(final TagKey tagKey, boolean create) { ++ final ResourceLocation vanillaKey = PaperAdventure.asVanilla(tagKey.key()); ++ List tag = this.tags.get(vanillaKey); ++ if (tag == null) { ++ if (create) { ++ tag = this.tags.computeIfAbsent(vanillaKey, k -> new ArrayList<>()); ++ } else { ++ throw new NoSuchElementException("Tag " + tagKey + " is not present"); ++ } ++ } ++ return tag; ++ } ++ ++ @Override ++ public List> getTag(final TagKey tagKey) { ++ return convert(this.getNmsTag(tagKey, false)); ++ } ++ ++ @Override ++ public void addToTag(final TagKey tagKey, final Collection> entries) { ++ final List nmsTag = new ArrayList<>(this.getNmsTag(tagKey, true)); ++ for (final TagEntry tagEntry : entries) { ++ nmsTag.add(this.convert(tagEntry)); ++ } ++ this.tags.put(PaperAdventure.asVanilla(tagKey.key()), nmsTag); ++ } ++ ++ @Override ++ public void setTag(final TagKey tagKey, final Collection> entries) { ++ final List newList = List.copyOf(Collections2.transform(entries, this::convert)); ++ this.tags.put(PaperAdventure.asVanilla(tagKey.key()), newList); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/tag/PaperTagListenerManager.java b/src/main/java/io/papermc/paper/tag/PaperTagListenerManager.java +new file mode 100644 +index 0000000000000000000000000000000000000000..f3e4019f9d55d3cce34248a806bf0ccb37c8e7b1 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/PaperTagListenerManager.java +@@ -0,0 +1,105 @@ ++package io.papermc.paper.tag; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.LifecycleEventRunner; ++import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent; ++import io.papermc.paper.plugin.lifecycle.event.types.AbstractLifecycleEventType; ++import io.papermc.paper.plugin.lifecycle.event.types.PrioritizableLifecycleEventType; ++import io.papermc.paper.registry.PaperRegistries; ++import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.event.RegistryEventMap; ++import java.util.Collection; ++import java.util.List; ++import java.util.Map; ++import net.minecraft.core.Holder; ++import net.minecraft.core.Registry; ++import net.minecraft.resources.ResourceLocation; ++import net.minecraft.tags.TagLoader; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.checker.nullness.qual.Nullable; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@DefaultQualifier(NonNull.class) ++public class PaperTagListenerManager { ++ ++ public static final String PRE_FLATTEN_EVENT_NAME = "pre-flatten"; ++ public static final String POST_FLATTEN_EVENT_NAME = "post-flatten"; ++ ++ public static final PaperTagListenerManager INSTANCE = new PaperTagListenerManager(); ++ ++ public final RegistryEventMap preFlatten = new RegistryEventMap(PRE_FLATTEN_EVENT_NAME); ++ public final RegistryEventMap postFlatten = new RegistryEventMap(POST_FLATTEN_EVENT_NAME); ++ ++ private PaperTagListenerManager() { ++ } ++ ++ public Map> firePreFlattenEvent( ++ final Map> initial, ++ final @Nullable TagEventConfig config ++ ) { ++ if (config == null || config.preFlatten() == null || !config.preFlatten().hasHandlers()) { ++ return initial; ++ } ++ final PaperPreFlattenTagRegistrar registrar = new PaperPreFlattenTagRegistrar<>(initial, config); ++ LifecycleEventRunner.INSTANCE.callReloadableRegistrarEvent( ++ config.preFlatten(), ++ registrar, ++ BootstrapContext.class, ++ config.cause() ++ ); ++ return Map.copyOf(registrar.tags); ++ } ++ ++ public Map> firePostFlattenEvent( ++ final Map> initial, ++ final @Nullable TagEventConfig config ++ ) { ++ if (config == null || config.postFlatten() == null || !config.postFlatten().hasHandlers()) { ++ return initial; ++ } ++ final PaperPostFlattenTagRegistrar registrar = new PaperPostFlattenTagRegistrar<>(initial, config); ++ LifecycleEventRunner.INSTANCE.callReloadableRegistrarEvent( ++ config.postFlatten(), ++ registrar, ++ BootstrapContext.class, ++ config.cause() ++ ); ++ return Map.copyOf(registrar.tags); ++ } ++ ++ public @Nullable TagEventConfig, B> createEventConfig(final Registry registry, final ReloadableRegistrarEvent.Cause cause) { ++ if (PaperRegistries.getEntry(registry.key()) == null) { ++ // TODO probably should be able to modify every registry ++ return null; ++ } ++ final RegistryKey registryKey = PaperRegistries.registryFromNms(registry.key()); ++ @Nullable AbstractLifecycleEventType>, ?> preFlatten = null; ++ if (this.preFlatten.hasHandlers(registryKey)) { ++ preFlatten = (AbstractLifecycleEventType>, ?>) this.preFlatten.>>getEventType(registryKey); ++ } ++ @Nullable AbstractLifecycleEventType>, ?> postFlatten = null; ++ if (this.postFlatten.hasHandlers(registryKey)) { ++ postFlatten = (AbstractLifecycleEventType>, ?>) this.postFlatten.>>getEventType(registryKey); ++ } ++ return new TagEventConfig<>( ++ preFlatten, ++ postFlatten, ++ cause, ++ registry::getHolder, ++ h -> ((Holder.Reference) h).key().location(), ++ PaperRegistries.registryFromNms(registry.key()) ++ ); ++ } ++ ++ public PrioritizableLifecycleEventType.Simple>> getPreFlattenType(final RegistryKey registryKey) { ++ return this.preFlatten.getOrCreate(registryKey, (ignored, name) -> { ++ return new PrioritizableLifecycleEventType.Simple<>(name, BootstrapContext.class); ++ }); ++ } ++ ++ public PrioritizableLifecycleEventType.Simple>> getPostFlattenType(final RegistryKey registryKey) { ++ return this.postFlatten.getOrCreate(registryKey, (ignored, name) -> { ++ return new PrioritizableLifecycleEventType.Simple<>(name, BootstrapContext.class); ++ }); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/tag/TagEventConfig.java b/src/main/java/io/papermc/paper/tag/TagEventConfig.java +new file mode 100644 +index 0000000000000000000000000000000000000000..d6d4bfc6f45d646afeace422a038c670e10aaf80 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/tag/TagEventConfig.java +@@ -0,0 +1,23 @@ ++package io.papermc.paper.tag; ++ ++import io.papermc.paper.plugin.bootstrap.BootstrapContext; ++import io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent; ++import io.papermc.paper.plugin.lifecycle.event.types.AbstractLifecycleEventType; ++import io.papermc.paper.registry.RegistryKey; ++import java.util.Optional; ++import java.util.function.Function; ++import net.minecraft.resources.ResourceLocation; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.checker.nullness.qual.Nullable; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@DefaultQualifier(NonNull.class) ++public record TagEventConfig( ++ @Nullable AbstractLifecycleEventType>, ?> preFlatten, ++ @Nullable AbstractLifecycleEventType>, ?> postFlatten, ++ ReloadableRegistrarEvent.Cause cause, ++ Function> fromIdConverter, ++ Function toIdConverter, ++ RegistryKey apiRegistryKey ++) { ++} +diff --git a/src/main/java/net/minecraft/server/ServerFunctionLibrary.java b/src/main/java/net/minecraft/server/ServerFunctionLibrary.java +index 8ae2ca2435d84fee930d2931e45ad440245cbe0f..9fff5ca1e9707e4e6be5ecb92be936332d24bb96 100644 +--- a/src/main/java/net/minecraft/server/ServerFunctionLibrary.java ++++ b/src/main/java/net/minecraft/server/ServerFunctionLibrary.java +@@ -118,7 +118,7 @@ public class ServerFunctionLibrary implements PreparableReloadListener { + return null; + }).join()); + this.functions = builder.build(); +- this.tags = this.tagsLoader.build((Map>)intermediate.getFirst()); ++ this.tags = this.tagsLoader.build((Map>)intermediate.getFirst(), null); // Paper - command function tags are not implemented yet + }, + applyExecutor + ); +diff --git a/src/main/java/net/minecraft/tags/TagLoader.java b/src/main/java/net/minecraft/tags/TagLoader.java +index b47afb0ce8d9517ac7ee9c651c160f99d70f8a98..0bde4f7ae7d1897c630513261d1d5fb75a762634 100644 +--- a/src/main/java/net/minecraft/tags/TagLoader.java ++++ b/src/main/java/net/minecraft/tags/TagLoader.java +@@ -79,7 +79,10 @@ public class TagLoader { + return list.isEmpty() ? Either.right(builder.build()) : Either.left(list); + } + +- public Map> build(Map> tags) { ++ // Paper start - fire tag registrar events ++ public Map> build(Map> tags, @Nullable io.papermc.paper.tag.TagEventConfig eventConfig) { ++ tags = io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePreFlattenEvent(tags, eventConfig); ++ // Paper end - fire tag registrar events + final Map> map = Maps.newHashMap(); + TagEntry.Lookup lookup = new TagEntry.Lookup() { + @Nullable +@@ -107,11 +110,13 @@ public class TagLoader { + ) + .ifRight(resolvedEntries -> map.put(id, (Collection)resolvedEntries)) + ); +- return map; ++ return io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePostFlattenEvent(map, eventConfig); // Paper - fire tag registrar events + } + +- public Map> loadAndBuild(ResourceManager manager) { +- return this.build(this.load(manager)); ++ // Paper start - fire tag registrar events ++ public Map> loadAndBuild(ResourceManager manager, @Nullable io.papermc.paper.tag.TagEventConfig eventConfig) { ++ return this.build(this.load(manager), eventConfig); ++ // Paper end - fire tag registrar events + } + + public static record EntryWithSource(TagEntry entry, String source) { +diff --git a/src/main/java/net/minecraft/tags/TagManager.java b/src/main/java/net/minecraft/tags/TagManager.java +index 7116362d798d7c28a4880c873a60507afa4673e6..2188274de5d1fe1aa5419be6247da6a3a2414a3b 100644 +--- a/src/main/java/net/minecraft/tags/TagManager.java ++++ b/src/main/java/net/minecraft/tags/TagManager.java +@@ -39,7 +39,7 @@ public class TagManager implements PreparableReloadListener { + ) { + List>> list = this.registryAccess + .registries() +- .map(registry -> this.createLoader(manager, prepareExecutor, (RegistryAccess.RegistryEntry)registry)) ++ .map(registry -> this.createLoader(manager, prepareExecutor, (RegistryAccess.RegistryEntry)registry, applyExecutor instanceof net.minecraft.server.MinecraftServer ? io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL : io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.RELOAD)) // Paper - add registrar event cause + .toList(); + return CompletableFuture.allOf(list.toArray(CompletableFuture[]::new)) + .thenCompose(synchronizer::wait) +@@ -48,11 +48,15 @@ public class TagManager implements PreparableReloadListener { + + private CompletableFuture> createLoader( + ResourceManager resourceManager, Executor prepareExecutor, RegistryAccess.RegistryEntry requirement ++ , io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause // Paper - add registrar event cause + ) { + ResourceKey> resourceKey = requirement.key(); + Registry registry = requirement.value(); + TagLoader> tagLoader = new TagLoader<>(registry::getHolder, Registries.tagsDirPath(resourceKey)); +- return CompletableFuture.supplyAsync(() -> new TagManager.LoadResult<>(resourceKey, tagLoader.loadAndBuild(resourceManager)), prepareExecutor); ++ // Paper start - fire tag registrar events ++ final io.papermc.paper.tag.TagEventConfig, ?> config = io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.createEventConfig(registry, cause); ++ return CompletableFuture.supplyAsync(() -> new TagManager.LoadResult<>(resourceKey, tagLoader.loadAndBuild(resourceManager, config)), prepareExecutor); ++ // Paper end - fire tag registrar events + } + + public static record LoadResult(ResourceKey> key, Map>> tags) {