diff --git a/patches/unapplied/server/Add-FeatureFlag-API.patch b/patches/server/Add-FeatureFlag-API.patch similarity index 100% rename from patches/unapplied/server/Add-FeatureFlag-API.patch rename to patches/server/Add-FeatureFlag-API.patch diff --git a/patches/unapplied/server/Tag-Lifecycle-Events.patch b/patches/server/Tag-Lifecycle-Events.patch similarity index 69% rename from patches/unapplied/server/Tag-Lifecycle-Events.patch rename to patches/server/Tag-Lifecycle-Events.patch index 945b166a2b..4a32a8277c 100644 --- a/patches/unapplied/server/Tag-Lifecycle-Events.patch +++ b/patches/server/Tag-Lifecycle-Events.patch @@ -71,6 +71,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + +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..00000000000000000000000000000000 +@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..00000000000000000000000000000000 + @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..00000000000000000000000000000000 + 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..00000000000000000000000000000000 + + @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)); + } @@ -377,8 +378,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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..00000000000000000000000000000000 + preFlatten, + postFlatten, + cause, -+ registry::getHolder, ++ registry::get, + h -> ((Holder.Reference) h).key().location(), + PaperRegistries.registryFromNms(registry.key()) + ); @@ -459,6 +460,45 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + RegistryKey apiRegistryKey +) { +} +diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java ++++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java ++++ b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/ServerFunctionLibrary.java @@ -472,66 +512,84 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 }, applyExecutor ); +diff --git a/src/main/java/net/minecraft/server/WorldLoader.java b/src/main/java/net/minecraft/server/WorldLoader.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/WorldLoader.java ++++ b/src/main/java/net/minecraft/server/WorldLoader.java +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/tags/TagLoader.java +++ b/src/main/java/net/minecraft/tags/TagLoader.java @@ -0,0 +0,0 @@ public class TagLoader { - return list.isEmpty() ? Either.right(builder.build()) : Either.left(list); + 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 @@ -0,0 +0,0 @@ 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) { +@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/tags/TagManager.java -+++ b/src/main/java/net/minecraft/tags/TagManager.java -@@ -0,0 +0,0 @@ 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) -@@ -0,0 +0,0 @@ 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) {