From 227caac7f0facbf3b0f2d79925be649071eb82ca Mon Sep 17 00:00:00 2001 From: Bjarne Koll Date: Fri, 25 Oct 2024 12:06:49 +0200 Subject: [PATCH] Wrong attempt at Tag lifecycle --- .../1021-Add-FeatureFlag-API.patch} | 12 +- .../1022-Tag-Lifecycle-Events.patch} | 180 ++++++++++++------ 2 files changed, 125 insertions(+), 67 deletions(-) rename patches/{unapplied/server/1052-Add-FeatureFlag-API.patch => server/1021-Add-FeatureFlag-API.patch} (97%) rename patches/{unapplied/server/1053-Tag-Lifecycle-Events.patch => server/1022-Tag-Lifecycle-Events.patch} (67%) diff --git a/patches/unapplied/server/1052-Add-FeatureFlag-API.patch b/patches/server/1021-Add-FeatureFlag-API.patch similarity index 97% rename from patches/unapplied/server/1052-Add-FeatureFlag-API.patch rename to patches/server/1021-Add-FeatureFlag-API.patch index aa43543249..733275936a 100644 --- a/patches/unapplied/server/1052-Add-FeatureFlag-API.patch +++ b/patches/server/1021-Add-FeatureFlag-API.patch @@ -144,10 +144,10 @@ index da90e5c84a0cc4505a5fff0ed278a905978c6ce2..00000000000000000000000000000000 - } -} diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java -index 284234fcdd15c4c7a4567c7c887d47bf0b7967f4..c9ecec5da937bc5458f69736b68ff6ae50aa5ebc 100644 +index f0bd7d01f56bb792886354ca4f199e46c2cf7503..adc6741e0e017660fbd39a62b69be1e67e0e143f 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java -@@ -558,4 +558,11 @@ public abstract class CraftRegionAccessor implements RegionAccessor { +@@ -564,4 +564,11 @@ public abstract class CraftRegionAccessor implements RegionAccessor { return !this.getHandle().noCollision(aabb); } // Paper end @@ -160,10 +160,10 @@ index 284234fcdd15c4c7a4567c7c887d47bf0b7967f4..c9ecec5da937bc5458f69736b68ff6ae + // Paper end - feature flag API } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -index 74feb45c3199308652448c8448eb87fb8fbf6f11..7fc52f9f4f2e2cd8ea3abdf6c6f5d1f679779c47 100644 +index 8367f0f344d42b6ccdfbe761be1735ac9a64bfab..36c3024c188197a777c8077704e1b64552c02d0a 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java -@@ -2374,10 +2374,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { +@@ -2379,10 +2379,7 @@ public class CraftWorld extends CraftRegionAccessor implements World { return this.persistentDataContainer; } @@ -221,7 +221,7 @@ index c81455a4ee9a3185f125ebf8cec325f4ed2e501d..8d962b055bd6574df7eb5510dd0efd67 + // Paper end - feature flag API } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java -index 450c63c31d2f5d056d989aa00452231f50c8224d..b9d9f1df2720c301915c8b07c0bdc12970128324 100644 +index d3f650d040afae8cb962696381c692cd7884bb4d..1b57649d0d3db24ed32c78cf3d5ce1d9fb1353e0 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemType.java @@ -36,7 +36,7 @@ import org.bukkit.inventory.meta.ItemMeta; @@ -282,7 +282,7 @@ index 6cf790c9fa23ea313423fdaeb7c181bf530828c6..0bcb9df1103050441f8922a688b163dc public static PotionEffectType minecraftHolderToBukkit(Holder minecraft) { return CraftPotionEffectType.minecraftToBukkit(minecraft.value()); diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java -index 6adc18c40d5d62e2ebc8deec197cec630a366937..8b2dbdfcdc4e98602f6bfd48d2c53840730f4691 100644 +index 02745957a08a27af6a032453b8b20a8fed2911b3..293757b8e96ae7b0e807d807affa3fdab5181d39 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -47,7 +47,7 @@ import org.bukkit.advancement.Advancement; diff --git a/patches/unapplied/server/1053-Tag-Lifecycle-Events.patch b/patches/server/1022-Tag-Lifecycle-Events.patch similarity index 67% rename from patches/unapplied/server/1053-Tag-Lifecycle-Events.patch rename to patches/server/1022-Tag-Lifecycle-Events.patch index 4b148fce53..5df52ccc9d 100644 --- a/patches/unapplied/server/1053-Tag-Lifecycle-Events.patch +++ b/patches/server/1022-Tag-Lifecycle-Events.patch @@ -63,14 +63,15 @@ index 0000000000000000000000000000000000000000..1cf4a3caa8d630e95eb569eef2cd577b +} 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 +index 0000000000000000000000000000000000000000..2596586fd7e2546cd18cf6ac36a4eb5cf8d00359 --- /dev/null +++ b/src/main/java/io/papermc/paper/tag/PaperPostFlattenTagRegistrar.java -@@ -0,0 +1,118 @@ +@@ -0,0 +1,119 @@ +package io.papermc.paper.tag; + +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; @@ -95,13 +96,13 @@ index 0000000000000000000000000000000000000000..cc37618cbbad7f21d65c7753f4dd4416 +@DefaultQualifier(NonNull.class) +public class PaperPostFlattenTagRegistrar implements PaperRegistrar, PostFlattenTagRegistrar { + -+ public final Map> tags; ++ public final Map> tags; + private final Function> fromIdConverter; + private final Function toIdConverter; + private final RegistryKey registryKey; + + public PaperPostFlattenTagRegistrar( -+ final Map> tags, ++ final Map> tags, + final TagEventConfig config + ) { + this.tags = tags; @@ -122,16 +123,16 @@ index 0000000000000000000000000000000000000000..cc37618cbbad7f21d65c7753f4dd4416 + @Override + public Map, Collection>> getAllTags() { + final ImmutableMap.Builder, Collection>> tags = ImmutableMap.builderWithExpectedSize(this.tags.size()); -+ for (final Map.Entry> entry : this.tags.entrySet()) { ++ 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 List> convert(final List nms) { ++ return Collections.unmodifiableList( ++ Lists.transform(nms, m -> this.convert(this.toIdConverter.apply(m))) + ); + } + @@ -152,9 +153,9 @@ index 0000000000000000000000000000000000000000..cc37618cbbad7f21d65c7753f4dd4416 + return this.tags.containsKey(PaperAdventure.asVanilla(tagKey.key())); + } + -+ private Collection getNmsTag(final TagKey tagKey, final boolean create) { ++ private List getNmsTag(final TagKey tagKey, final boolean create) { + final ResourceLocation vanillaKey = PaperAdventure.asVanilla(tagKey.key()); -+ Collection tag = this.tags.get(vanillaKey); ++ List tag = this.tags.get(vanillaKey); + if (tag == null) { + if (create) { + tag = this.tags.computeIfAbsent(vanillaKey, k -> new ArrayList<>()); @@ -172,7 +173,7 @@ index 0000000000000000000000000000000000000000..cc37618cbbad7f21d65c7753f4dd4416 + + @Override + public void addToTag(final TagKey tagKey, final Collection> values) { -+ final Collection nmsTag = new ArrayList<>(this.getNmsTag(tagKey, true)); ++ final List nmsTag = new ArrayList<>(this.getNmsTag(tagKey, true)); + for (final TypedKey key : values) { + nmsTag.add(this.convert(key)); + } @@ -321,7 +322,7 @@ index 0000000000000000000000000000000000000000..44111b55eaa6d1cc93e2c556b23bb5c9 +} 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 +index 0000000000000000000000000000000000000000..e1ffb7f1df667dd9f92c00ff94b791feb1f14eed --- /dev/null +++ b/src/main/java/io/papermc/paper/tag/PaperTagListenerManager.java @@ -0,0 +1,105 @@ @@ -377,8 +378,8 @@ index 0000000000000000000000000000000000000000..f3e4019f9d55d3cce34248a806bf0ccb + return Map.copyOf(registrar.tags); + } + -+ public Map> firePostFlattenEvent( -+ final Map> initial, ++ public Map> firePostFlattenEvent( ++ final Map> initial, + final @Nullable TagEventConfig config + ) { + if (config == null || config.postFlatten() == null || !config.postFlatten().hasHandlers()) { @@ -412,7 +413,7 @@ index 0000000000000000000000000000000000000000..f3e4019f9d55d3cce34248a806bf0ccb + preFlatten, + postFlatten, + cause, -+ registry::getHolder, ++ registry::get, + h -> ((Holder.Reference) h).key().location(), + PaperRegistries.registryFromNms(registry.key()) + ); @@ -459,11 +460,50 @@ index 0000000000000000000000000000000000000000..d6d4bfc6f45d646afeace422a038c670 + RegistryKey apiRegistryKey +) { +} +diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java +index f2236665eaf3e6d0f9d44605db3cd5afe0cced4e..28d809a0e2fccd15a09bc6b55ca024526867ada7 100644 +--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java ++++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java +@@ -278,7 +278,7 @@ public class RegistryDataLoader { + } + } + +- TagLoader.loadTagsForRegistry(resourceManager, registry); ++ TagLoader.loadTagsForRegistry(resourceManager, registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); // Paper - tag lifecycle - add cause + } + + static void loadContentsFromNetwork( +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index dcf046dd1eb8c2b724c971c4adf4462895183f0a..448961d7bd80e7e84959866906e6a4e3ac9ab4f7 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -2251,7 +2251,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoopmap(resourcepackrepository::getPack).filter(Objects::nonNull).map(Pack::open).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error // Paper - decompile error // todo: is this needed anymore? + }, this).thenCompose((immutablelist) -> { + MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist); +- List> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess()); ++ List> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess(), io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.RELOAD); // Paper - tag lifecycle - add cause + + return ReloadableServerResources.loadResources(resourcemanager, this.registries, list, this.worldData.enabledFeatures(), this.isDedicatedServer() ? Commands.CommandSelection.DEDICATED : Commands.CommandSelection.INTEGRATED, this.getFunctionCompilationLevel(), this.executor, this).whenComplete((datapackresources, throwable) -> { + if (throwable != null) { +diff --git a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java +index b5ca1a0acb16d0cd8dccc854f309d425a48b070d..ea1cbd7a3897ea4a86877a557da264387ef78a38 100644 +--- a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java ++++ b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java +@@ -70,7 +70,7 @@ public class ReloadableServerRegistries { + String string = Registries.elementsDirPath(type.registryKey()); + SimpleJsonResourceReloadListener.scanDirectory(resourceManager, string, ops, type.codec(), map); + map.forEach((id, value) -> io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.registerWithListeners(writableRegistry, ResourceKey.create(type.registryKey(), id), value, DEFAULT_REGISTRATION_INFO, conversions)); // Paper - register with listeners +- TagLoader.loadTagsForRegistry(resourceManager, writableRegistry); ++ TagLoader.loadTagsForRegistry(resourceManager, writableRegistry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.RELOAD); // Paper - tag life cycle - reload + return writableRegistry; + }, prepareExecutor); + } diff --git a/src/main/java/net/minecraft/server/ServerFunctionLibrary.java b/src/main/java/net/minecraft/server/ServerFunctionLibrary.java -index 8ae2ca2435d84fee930d2931e45ad440245cbe0f..9fff5ca1e9707e4e6be5ecb92be936332d24bb96 100644 +index 7128f01308b60163afa9355b79cb4129b630663d..fa5d4bfd52eb36e48fc811dbbdc1341204cf171d 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 { +@@ -113,7 +113,7 @@ public class ServerFunctionLibrary implements PreparableReloadListener { return null; }).join()); this.functions = builder.build(); @@ -472,66 +512,84 @@ index 8ae2ca2435d84fee930d2931e45ad440245cbe0f..9fff5ca1e9707e4e6be5ecb92be93633 }, applyExecutor ); +diff --git a/src/main/java/net/minecraft/server/WorldLoader.java b/src/main/java/net/minecraft/server/WorldLoader.java +index f21ccc50f2d507afe1e0af394321020cb5667e60..fad1cc1be3d1b84acacde8736129b970824f48b8 100644 +--- a/src/main/java/net/minecraft/server/WorldLoader.java ++++ b/src/main/java/net/minecraft/server/WorldLoader.java +@@ -37,7 +37,7 @@ public class WorldLoader { + CloseableResourceManager closeableResourceManager = pair.getSecond(); + LayeredRegistryAccess layeredRegistryAccess = RegistryLayer.createRegistryAccess(); + List> list = TagLoader.loadTagsForExistingRegistries( +- closeableResourceManager, layeredRegistryAccess.getLayer(RegistryLayer.STATIC) ++ closeableResourceManager, layeredRegistryAccess.getLayer(RegistryLayer.STATIC), io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL // Paper - tag lifecycle - add cause + ); + RegistryAccess.Frozen frozen = layeredRegistryAccess.getAccessForLoading(RegistryLayer.WORLDGEN); + List> list2 = TagLoader.buildUpdatedLookups(frozen, list); diff --git a/src/main/java/net/minecraft/tags/TagLoader.java b/src/main/java/net/minecraft/tags/TagLoader.java -index b47afb0ce8d9517ac7ee9c651c160f99d70f8a98..0bde4f7ae7d1897c630513261d1d5fb75a762634 100644 +index 8d742805f7b44b832b532d4ee6d313c0d7659e1d..a81b2b47b909b3858046d2b152d31b2cfc5d5fe4 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); +@@ -86,7 +86,10 @@ public class TagLoader { + return list.isEmpty() ? Either.right(List.copyOf(sequencedSet)) : Either.left(list); } -- public Map> build(Map> tags) { +- public Map> build(Map> tags) { + // Paper start - fire tag registrar events -+ public Map> build(Map> tags, @Nullable io.papermc.paper.tag.TagEventConfig eventConfig) { ++ 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(); ++ // Paper end - fire tag registrar event + final Map> map = new HashMap<>(); TagEntry.Lookup lookup = new TagEntry.Lookup() { @Nullable -@@ -107,11 +110,13 @@ public class TagLoader { +@@ -114,7 +117,7 @@ public class TagLoader { ) - .ifRight(resolvedEntries -> map.put(id, (Collection)resolvedEntries)) + .ifRight(values -> map.put(id, (List)values)) ); - 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 void loadTagsFromNetwork(TagNetworkSerialization.NetworkPayload tags, WritableRegistry registry) { +@@ -122,28 +125,38 @@ public class TagLoader { } - 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 List> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryManager) { ++ // Paper start - tag lifecycle - add cause ++ return loadTagsForExistingRegistries(resourceManager, registryManager, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); ++ } ++ public static List> loadTagsForExistingRegistries(ResourceManager resourceManager, RegistryAccess registryManager, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { ++ // Paper end - tag lifecycle - add cause + return registryManager.registries() +- .map(registry -> loadPendingTags(resourceManager, registry.value())) ++ .map(registry -> loadPendingTags(resourceManager, registry.value(), cause)) // Paper - tag lifecycle - add cause + .flatMap(Optional::stream) + .collect(Collectors.toUnmodifiableList()); + } + + public static void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry registry) { ++ // Paper start - tag lifecycle - add registrar event cause ++ loadTagsForRegistry(resourceManager, registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL); ++ } ++ public static void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { ++ // Paper end - tag lifecycle - add registrar event cause + ResourceKey> resourceKey = registry.key(); + TagLoader> tagLoader = new TagLoader<>(TagLoader.ElementLookup.fromWritableRegistry(registry), Registries.tagsDirPath(resourceKey)); +- tagLoader.build(tagLoader.load(resourceManager)).forEach((id, entries) -> registry.bindTag(TagKey.create(resourceKey, id), (List>)entries)); ++ tagLoader.build(tagLoader.load(resourceManager), io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.createEventConfig(registry, cause)).forEach((id, entries) -> registry.bindTag(TagKey.create(resourceKey, id), (List>)entries)); // Paper - tag lifecycle - add registrar event cause + } + + private static Map, List>> wrapTags(ResourceKey> registryRef, Map>> tags) { + return tags.entrySet().stream().collect(Collectors.toUnmodifiableMap(entry -> TagKey.create(registryRef, entry.getKey()), Entry::getValue)); + } + +- private static Optional> loadPendingTags(ResourceManager resourceManager, Registry registry) { ++ private static Optional> loadPendingTags(ResourceManager resourceManager, Registry registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { // Paper - add registrar event cause + ResourceKey> resourceKey = registry.key(); + TagLoader> tagLoader = new TagLoader<>( + (TagLoader.ElementLookup>)TagLoader.ElementLookup.fromFrozenRegistry(registry), Registries.tagsDirPath(resourceKey) + ); +- TagLoader.LoadResult loadResult = new TagLoader.LoadResult<>(resourceKey, wrapTags(registry.key(), tagLoader.build(tagLoader.load(resourceManager)))); ++ TagLoader.LoadResult loadResult = new TagLoader.LoadResult<>(resourceKey, wrapTags(registry.key(), tagLoader.build(tagLoader.load(resourceManager), io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.createEventConfig(registry, cause)))); // Paper - add registrar event cause + return loadResult.tags().isEmpty() ? Optional.empty() : Optional.of(registry.prepareTagReload(loadResult)); } - public static record LoadResult(ResourceKey> key, Map>> tags) {