3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-14 20:10:05 +01:00

Wrong attempt at Tag lifecycle

Dieser Commit ist enthalten in:
Bjarne Koll 2024-10-25 12:06:49 +02:00
Ursprung 6a315742d9
Commit 227caac7f0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 27F6CCCF55D2EE62
2 geänderte Dateien mit 125 neuen und 67 gelöschten Zeilen

Datei anzeigen

@ -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<MobEffect> 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;

Datei anzeigen

@ -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<M, T> implements PaperRegistrar<BootstrapContext>, PostFlattenTagRegistrar<T> {
+
+ public final Map<ResourceLocation, Collection<M>> tags;
+ public final Map<ResourceLocation, List<M>> tags;
+ private final Function<ResourceLocation, Optional<? extends M>> fromIdConverter;
+ private final Function<M, ResourceLocation> toIdConverter;
+ private final RegistryKey<T> registryKey;
+
+ public PaperPostFlattenTagRegistrar(
+ final Map<ResourceLocation, Collection<M>> tags,
+ final Map<ResourceLocation, List<M>> tags,
+ final TagEventConfig<M, T> config
+ ) {
+ this.tags = tags;
@ -122,16 +123,16 @@ index 0000000000000000000000000000000000000000..cc37618cbbad7f21d65c7753f4dd4416
+ @Override
+ public Map<TagKey<T>, Collection<TypedKey<T>>> getAllTags() {
+ final ImmutableMap.Builder<TagKey<T>, Collection<TypedKey<T>>> tags = ImmutableMap.builderWithExpectedSize(this.tags.size());
+ for (final Map.Entry<ResourceLocation, Collection<M>> entry : this.tags.entrySet()) {
+ for (final Map.Entry<ResourceLocation, List<M>> entry : this.tags.entrySet()) {
+ final TagKey<T> key = TagKey.create(this.registryKey, CraftNamespacedKey.fromMinecraft(entry.getKey()));
+ tags.put(key, this.convert(entry.getValue()));
+ }
+ return tags.build();
+ }
+
+ private Collection<TypedKey<T>> convert(final Collection<M> nms) {
+ return Collections.unmodifiableCollection(
+ Collections2.transform(nms, m -> this.convert(this.toIdConverter.apply(m)))
+ private List<TypedKey<T>> convert(final List<M> 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<M> getNmsTag(final TagKey<T> tagKey, final boolean create) {
+ private List<M> getNmsTag(final TagKey<T> tagKey, final boolean create) {
+ final ResourceLocation vanillaKey = PaperAdventure.asVanilla(tagKey.key());
+ Collection<M> tag = this.tags.get(vanillaKey);
+ List<M> 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<T> tagKey, final Collection<TypedKey<T>> values) {
+ final Collection<M> nmsTag = new ArrayList<>(this.getNmsTag(tagKey, true));
+ final List<M> nmsTag = new ArrayList<>(this.getNmsTag(tagKey, true));
+ for (final TypedKey<T> 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 <M, A> Map<ResourceLocation, Collection<M>> firePostFlattenEvent(
+ final Map<ResourceLocation, Collection<M>> initial,
+ public <M, A> Map<ResourceLocation, List<M>> firePostFlattenEvent(
+ final Map<ResourceLocation, List<M>> initial,
+ final @Nullable TagEventConfig<M, A> 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<M>) h).key().location(),
+ PaperRegistries.registryFromNms(registry.key())
+ );
@ -459,11 +460,50 @@ index 0000000000000000000000000000000000000000..d6d4bfc6f45d646afeace422a038c670
+ RegistryKey<A> 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 <E> 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 ReentrantBlockableEventLoop<TickTa
return stream.<Pack>map(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<Registry.PendingTags<?>> list = TagLoader.loadTagsForExistingRegistries(resourcemanager, this.registries.compositeAccess());
+ List<Registry.PendingTags<?>> 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<RegistryLayer> layeredRegistryAccess = RegistryLayer.createRegistryAccess();
List<Registry.PendingTags<?>> 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<HolderLookup.RegistryLookup<?>> 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<T> {
return list.isEmpty() ? Either.right(builder.build()) : Either.left(list);
@@ -86,7 +86,10 @@ public class TagLoader<T> {
return list.isEmpty() ? Either.right(List.copyOf(sequencedSet)) : Either.left(list);
}
- public Map<ResourceLocation, Collection<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tags) {
- public Map<ResourceLocation, List<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tags) {
+ // Paper start - fire tag registrar events
+ public Map<ResourceLocation, Collection<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tags, @Nullable io.papermc.paper.tag.TagEventConfig<T, ?> eventConfig) {
+ public Map<ResourceLocation, List<T>> build(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tags, @Nullable io.papermc.paper.tag.TagEventConfig<T, ?> eventConfig) {
+ tags = io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePreFlattenEvent(tags, eventConfig);
+ // Paper end - fire tag registrar events
final Map<ResourceLocation, Collection<T>> map = Maps.newHashMap();
+ // Paper end - fire tag registrar event
final Map<ResourceLocation, List<T>> map = new HashMap<>();
TagEntry.Lookup<T> lookup = new TagEntry.Lookup<T>() {
@Nullable
@@ -107,11 +110,13 @@ public class TagLoader<T> {
@@ -114,7 +117,7 @@ public class TagLoader<T> {
)
.ifRight(resolvedEntries -> map.put(id, (Collection<T>)resolvedEntries))
.ifRight(values -> map.put(id, (List<T>)values))
);
- return map;
+ return io.papermc.paper.tag.PaperTagListenerManager.INSTANCE.firePostFlattenEvent(map, eventConfig); // Paper - fire tag registrar events
}
- public Map<ResourceLocation, Collection<T>> loadAndBuild(ResourceManager manager) {
- return this.build(this.load(manager));
+ // Paper start - fire tag registrar events
+ public Map<ResourceLocation, Collection<T>> loadAndBuild(ResourceManager manager, @Nullable io.papermc.paper.tag.TagEventConfig<T, ?> eventConfig) {
+ return this.build(this.load(manager), eventConfig);
+ // Paper end - fire tag registrar events
public static <T> void loadTagsFromNetwork(TagNetworkSerialization.NetworkPayload tags, WritableRegistry<T> registry) {
@@ -122,28 +125,38 @@ public class TagLoader<T> {
}
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<? extends CompletableFuture<? extends TagManager.LoadResult<?>>> 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 <T> CompletableFuture<TagManager.LoadResult<T>> createLoader(
ResourceManager resourceManager, Executor prepareExecutor, RegistryAccess.RegistryEntry<T> requirement
+ , io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause // Paper - add registrar event cause
) {
ResourceKey<? extends Registry<T>> resourceKey = requirement.key();
Registry<T> registry = requirement.value();
TagLoader<Holder<T>> 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<Holder<T>, ?> 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<Registry.PendingTags<?>> 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<Registry.PendingTags<?>> 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 <T> void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry<T> registry) {
+ // Paper start - tag lifecycle - add registrar event cause
+ loadTagsForRegistry(resourceManager, registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause.INITIAL);
+ }
+ public static <T> void loadTagsForRegistry(ResourceManager resourceManager, WritableRegistry<T> registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) {
+ // Paper end - tag lifecycle - add registrar event cause
ResourceKey<? extends Registry<T>> resourceKey = registry.key();
TagLoader<Holder<T>> 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<Holder<T>>)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<Holder<T>>)entries)); // Paper - tag lifecycle - add registrar event cause
}
private static <T> Map<TagKey<T>, List<Holder<T>>> wrapTags(ResourceKey<? extends Registry<T>> registryRef, Map<ResourceLocation, List<Holder<T>>> tags) {
return tags.entrySet().stream().collect(Collectors.toUnmodifiableMap(entry -> TagKey.create(registryRef, entry.getKey()), Entry::getValue));
}
- private static <T> Optional<Registry.PendingTags<T>> loadPendingTags(ResourceManager resourceManager, Registry<T> registry) {
+ private static <T> Optional<Registry.PendingTags<T>> loadPendingTags(ResourceManager resourceManager, Registry<T> registry, io.papermc.paper.plugin.lifecycle.event.registrar.ReloadableRegistrarEvent.Cause cause) { // Paper - add registrar event cause
ResourceKey<? extends Registry<T>> resourceKey = registry.key();
TagLoader<Holder<T>> tagLoader = new TagLoader<>(
(TagLoader.ElementLookup<Holder<T>>)TagLoader.ElementLookup.fromFrozenRegistry(registry), Registries.tagsDirPath(resourceKey)
);
- TagLoader.LoadResult<T> loadResult = new TagLoader.LoadResult<>(resourceKey, wrapTags(registry.key(), tagLoader.build(tagLoader.load(resourceManager))));
+ TagLoader.LoadResult<T> 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<T>(ResourceKey<? extends Registry<T>> key, Map<ResourceLocation, Collection<Holder<T>>> tags) {