diff --git a/patches/api/0490-Custom-advancement-trigger-types.patch b/patches/api/0490-Custom-advancement-trigger-types.patch new file mode 100644 index 0000000000..f40f2c4bf1 --- /dev/null +++ b/patches/api/0490-Custom-advancement-trigger-types.patch @@ -0,0 +1,247 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Mon, 23 Sep 2024 14:49:16 -0700 +Subject: [PATCH] Custom advancement trigger types + + +diff --git a/src/main/java/io/papermc/paper/advancement/CriteriaTrigger.java b/src/main/java/io/papermc/paper/advancement/CriteriaTrigger.java +new file mode 100644 +index 0000000000000000000000000000000000000000..c6107335a0ecdee5e624699dbe5759f2b1cb9239 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/advancement/CriteriaTrigger.java +@@ -0,0 +1,26 @@ ++package io.papermc.paper.advancement; ++ ++import java.util.function.Predicate; ++import org.bukkit.Keyed; ++import org.bukkit.entity.Player; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++ ++/** ++ * Trigger type for advancements. ++ * ++ * @param the type of the instance for the trigger ++ */ ++@ApiStatus.NonExtendable ++@ApiStatus.Experimental ++public interface CriteriaTrigger extends Keyed { ++ ++ /** ++ * Activates the trigger for a specific player and predicate against the trigger instance. ++ * ++ * @param player the player to activate the trigger for ++ * @param instancePredicate the predicate to test the trigger instance against ++ * @apiNote Only works for custom triggers registered via {@link io.papermc.paper.registry.event.RegistryEvents#TRIGGER_TYPE} ++ */ ++ void trigger(@NonNull Player player, @NonNull Predicate instancePredicate); ++} +diff --git a/src/main/java/io/papermc/paper/registry/RegistryKey.java b/src/main/java/io/papermc/paper/registry/RegistryKey.java +index ccbe3fa2e01a80abb801d14891dce34ed179b5ee..47b25c63b5e0012a2dddb28d8492d6b1310a60ed 100644 +--- a/src/main/java/io/papermc/paper/registry/RegistryKey.java ++++ b/src/main/java/io/papermc/paper/registry/RegistryKey.java +@@ -1,5 +1,6 @@ + package io.papermc.paper.registry; + ++import io.papermc.paper.advancement.CriteriaTrigger; + import net.kyori.adventure.key.Keyed; + import org.bukkit.Art; + import org.bukkit.Fluid; +@@ -83,6 +84,9 @@ public sealed interface RegistryKey extends Keyed permits RegistryKeyImpl { + @ApiStatus.Experimental // Paper - already required for registry builders + RegistryKey ITEM = create("item"); + ++ @ApiStatus.Experimental ++ RegistryKey> TRIGGER_TYPE = create("trigger_type"); ++ + + /* ********************** * + * Data-driven Registries * +diff --git a/src/main/java/io/papermc/paper/registry/data/CriteriaTriggerRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/CriteriaTriggerRegistryEntry.java +new file mode 100644 +index 0000000000000000000000000000000000000000..f051cdd36eb99149b7876de1d39da3539a45f95f +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/data/CriteriaTriggerRegistryEntry.java +@@ -0,0 +1,52 @@ ++package io.papermc.paper.registry.data; ++ ++import com.google.gson.JsonElement; ++import io.papermc.paper.advancement.CriteriaTrigger; ++import io.papermc.paper.registry.RegistryBuilder; ++import java.util.function.Function; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++ ++/** ++ * A data-centric version-specific registry entry for the {@link CriteriaTrigger} type. ++ * ++ * @param the type of the instance for the trigger ++ */ ++@ApiStatus.Experimental ++@ApiStatus.NonExtendable ++public interface CriteriaTriggerRegistryEntry { ++ ++ /** ++ * Provides the deserializer for the trigger instance. ++ * ++ * @return the deserializer for the trigger instance ++ */ ++ @Contract(pure = true) ++ @NonNull Function<@NonNull JsonElement, @NonNull I> deserializer(); ++ ++ /** ++ * A mutable builder for {@link CriteriaTriggerRegistryEntry} which plugins may change ++ * in applicable registry events. ++ *

++ * The following values are required for each builder: ++ *

    ++ *
  • {@link #deserializer(Function)}
  • ++ *
++ * ++ * @param the type of the instance for the trigger ++ */ ++ @ApiStatus.Experimental ++ @ApiStatus.NonExtendable ++ interface Builder extends CriteriaTriggerRegistryEntry, RegistryBuilder> { ++ ++ /** ++ * Sets the deserializer for the trigger instance. ++ * ++ * @param deserializer the deserializer for the trigger instance ++ * @return this builder instance ++ */ ++ @Contract(value = "_ -> this", mutates = "this") ++ @NonNull Builder deserializer(@NonNull Function<@NonNull JsonElement, @NonNull I> deserializer); ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java +index a5d7385eae9dfb88b52aed0e42c09a10ef807385..b2be49db812158cbb54d11fc12701e7782019995 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java +@@ -18,7 +18,7 @@ import org.jetbrains.annotations.ApiStatus; + */ + @ApiStatus.Experimental + @ApiStatus.NonExtendable +-public interface RegistryEntryAddEvent> extends RegistryEvent { ++public interface RegistryEntryAddEvent> extends RegistryEvent { + + /** + * Gets the builder for the entry being added to the registry. +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventProvider.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventProvider.java +index 477ed0fd5acc923d429980529876f0dd7dd3a52a..e23315201219da378e9543482a82194be379aff4 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEventProvider.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventProvider.java +@@ -2,8 +2,6 @@ package io.papermc.paper.registry.event; + + import io.papermc.paper.plugin.bootstrap.BootstrapContext; + import io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler; +-import io.papermc.paper.plugin.lifecycle.event.handler.configuration.LifecycleEventHandlerConfiguration; +-import io.papermc.paper.plugin.lifecycle.event.handler.configuration.PrioritizedLifecycleEventHandlerConfiguration; + import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType; + import io.papermc.paper.registry.RegistryBuilder; + import io.papermc.paper.registry.RegistryKey; +@@ -25,7 +23,7 @@ import org.jetbrains.annotations.ApiStatus; + */ + @ApiStatus.Experimental + @ApiStatus.NonExtendable +-public interface RegistryEventProvider> { ++public interface RegistryEventProvider> { + + /** + * Gets the event type for {@link RegistryEntryAddEvent} which is fired just before +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventProviderImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventProviderImpl.java +index cfe47c8bd0888db6d00867acfefc8db42ef314aa..f9cdf7aa710e49cbb2cced49175aceb6094bca58 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEventProviderImpl.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventProviderImpl.java +@@ -11,9 +11,9 @@ import org.jetbrains.annotations.ApiStatus; + + @ApiStatus.Internal + @DefaultQualifier(NonNull.class) +-record RegistryEventProviderImpl>(RegistryKey registryKey) implements RegistryEventProvider { ++record RegistryEventProviderImpl>(RegistryKey registryKey) implements RegistryEventProvider { + +- static > RegistryEventProvider create(final RegistryKey registryKey) { ++ static > RegistryEventProvider create(final RegistryKey registryKey) { + return new RegistryEventProviderImpl<>(registryKey); + } + +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProvider.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProvider.java +index d807bd2f42c98e37a96cf110ad77820dfffc8398..5eb93ea0085607a96384e33044755d86f644d29e 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProvider.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProvider.java +@@ -18,7 +18,7 @@ interface RegistryEventTypeProvider { + return PROVIDER.orElseThrow(() -> new IllegalStateException("Could not find a %s service implementation".formatted(RegistryEventTypeProvider.class.getSimpleName()))); + } + +- > RegistryEntryAddEventType registryEntryAdd(RegistryEventProvider type); ++ > RegistryEntryAddEventType registryEntryAdd(RegistryEventProvider type); + +- > LifecycleEventType.Prioritizable> registryFreeze(RegistryEventProvider type); ++ > LifecycleEventType.Prioritizable> registryFreeze(RegistryEventProvider type); + } +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java b/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java +index b32ae215e976bcfcdd86b03037de61b3d896f57c..a176f89f40db1369158ecc4ea9f0cebbbd6bb01c 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java +@@ -1,6 +1,8 @@ + package io.papermc.paper.registry.event; + ++import io.papermc.paper.advancement.CriteriaTrigger; + import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.data.CriteriaTriggerRegistryEntry; + import io.papermc.paper.registry.data.EnchantmentRegistryEntry; + import io.papermc.paper.registry.data.GameEventRegistryEntry; + import org.bukkit.GameEvent; +@@ -18,6 +20,7 @@ public final class RegistryEvents { + + public static final RegistryEventProvider GAME_EVENT = create(RegistryKey.GAME_EVENT); + public static final RegistryEventProvider ENCHANTMENT = create(RegistryKey.ENCHANTMENT); ++ public static final RegistryEventProvider, CriteriaTriggerRegistryEntry.Builder> TRIGGER_TYPE = create(RegistryKey.TRIGGER_TYPE); + + private RegistryEvents() { + } +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java +index 12ec7e794a5047a30354a485acd40fa0f3438eea..a3b0ca85ca30803330dd4346cc433e2e45115738 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEvent.java +@@ -17,7 +17,7 @@ import org.jetbrains.annotations.ApiStatus; + */ + @ApiStatus.Experimental + @ApiStatus.NonExtendable +-public interface RegistryFreezeEvent> extends RegistryEvent { ++public interface RegistryFreezeEvent> extends RegistryEvent { + + /** + * Get the writable registry. +diff --git a/src/main/java/io/papermc/paper/registry/event/WritableRegistry.java b/src/main/java/io/papermc/paper/registry/event/WritableRegistry.java +index 6de377275097f065c38dd59c6db9704018ac81fc..a1ddf54c06e624ad10212fae7deca2e8935c0675 100644 +--- a/src/main/java/io/papermc/paper/registry/event/WritableRegistry.java ++++ b/src/main/java/io/papermc/paper/registry/event/WritableRegistry.java +@@ -14,7 +14,7 @@ import org.jetbrains.annotations.ApiStatus; + */ + @ApiStatus.NonExtendable + @ApiStatus.Experimental +-public interface WritableRegistry> { ++public interface WritableRegistry> { + + /** + * Register a new value with the specified key. This will +@@ -23,5 +23,5 @@ public interface WritableRegistry> { + * @param key the entry's key (must be unique from others) + * @param value a consumer for the entry's builder + */ +- void register(@NonNull TypedKey key, @NonNull Consumer value); ++ void register(@NonNull TypedKey key, @NonNull Consumer value); + } +diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventType.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventType.java +index f4d4ebf6cbed1b4a9955ceb2d0586782181d97e5..abd066b998dc752869b1e8e762ed09a077554998 100644 +--- a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventType.java ++++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventType.java +@@ -14,5 +14,5 @@ import org.jetbrains.annotations.ApiStatus; + */ + @ApiStatus.Experimental + @ApiStatus.NonExtendable +-public interface RegistryEntryAddEventType> extends LifecycleEventType, RegistryEntryAddConfiguration> { ++public interface RegistryEntryAddEventType> extends LifecycleEventType, RegistryEntryAddConfiguration> { + } diff --git a/patches/server/1059-Custom-advancement-trigger-types.patch b/patches/server/1059-Custom-advancement-trigger-types.patch new file mode 100644 index 0000000000..b2ecb31204 --- /dev/null +++ b/patches/server/1059-Custom-advancement-trigger-types.patch @@ -0,0 +1,650 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Mon, 23 Sep 2024 14:50:15 -0700 +Subject: [PATCH] Custom advancement trigger types + + +diff --git a/src/main/java/io/papermc/paper/advancement/PaperCriteriaTrigger.java b/src/main/java/io/papermc/paper/advancement/PaperCriteriaTrigger.java +new file mode 100644 +index 0000000000000000000000000000000000000000..8123e1c4cd16cef6cdfc6f882dbed7aa452e01f9 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/advancement/PaperCriteriaTrigger.java +@@ -0,0 +1,58 @@ ++package io.papermc.paper.advancement; ++ ++import java.util.function.Predicate; ++import net.minecraft.advancements.CriterionTrigger; ++import net.minecraft.advancements.CriterionTriggerInstance; ++import org.bukkit.NamespacedKey; ++import org.bukkit.craftbukkit.entity.CraftPlayer; ++import org.bukkit.craftbukkit.util.Handleable; ++import org.bukkit.entity.Player; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@DefaultQualifier(NonNull.class) ++public record PaperCriteriaTrigger(NamespacedKey key, CriterionTrigger criterionTrigger) implements Handleable>, CriteriaTrigger { ++ ++ @SuppressWarnings("unchecked") ++ public static CriteriaTrigger create(final NamespacedKey key, final CriterionTrigger criterionTrigger) { ++ if (criterionTrigger instanceof PaperCustomCriterionTrigger paperCustomCriterionTrigger) { ++ return new PaperCustomCriteriaTrigger<>(key, (PaperCustomCriterionTrigger) paperCustomCriterionTrigger); ++ } ++ return new PaperCriteriaTrigger<>(key, criterionTrigger); ++ } ++ ++ @Override ++ public NamespacedKey getKey() { ++ return this.key; ++ } ++ ++ @Override ++ public CriterionTrigger getHandle() { ++ return this.criterionTrigger; ++ } ++ ++ @Override ++ public void trigger(final Player player, final Predicate instancePredicate) { ++ throw new UnsupportedOperationException("Cannot trigger non-custom criteria trigger types"); ++ } ++ ++ public record PaperCustomCriteriaTrigger(NamespacedKey key, PaperCustomCriterionTrigger criterionTrigger) implements Handleable>>, CriteriaTrigger { ++ ++ @Override ++ public void trigger(final Player player, final Predicate instancePredicate) { ++ this.criterionTrigger().trigger(((CraftPlayer) player).getHandle(), wrapper -> { ++ return instancePredicate.test(wrapper.apiInstance()); ++ }); ++ } ++ ++ @Override ++ public NamespacedKey getKey() { ++ return this.key; ++ } ++ ++ @Override ++ public CriterionTrigger> getHandle() { ++ return this.criterionTrigger; ++ } ++ } ++} +diff --git a/src/main/java/io/papermc/paper/advancement/PaperCustomCriterionTrigger.java b/src/main/java/io/papermc/paper/advancement/PaperCustomCriterionTrigger.java +new file mode 100644 +index 0000000000000000000000000000000000000000..d7d4ee65faa8b632585beee07731d3a542d6c3d4 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/advancement/PaperCustomCriterionTrigger.java +@@ -0,0 +1,40 @@ ++package io.papermc.paper.advancement; ++ ++import com.google.gson.JsonElement; ++import com.mojang.serialization.Codec; ++import com.mojang.serialization.JsonOps; ++import java.util.Optional; ++import java.util.function.Function; ++import net.minecraft.advancements.critereon.ContextAwarePredicate; ++import net.minecraft.advancements.critereon.SimpleCriterionTrigger; ++import net.minecraft.util.ExtraCodecs; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@DefaultQualifier(NonNull.class) ++public final class PaperCustomCriterionTrigger extends SimpleCriterionTrigger> { ++ ++ private final Function deserializer; ++ ++ public PaperCustomCriterionTrigger(final Function deserializer) { ++ this.deserializer = deserializer; ++ } ++ ++ @Override ++ public Codec> codec() { ++ return ExtraCodecs.converter(JsonOps.INSTANCE).xmap(jsonElement -> { ++ return new PaperCustomTriggerInstance<>(this.deserializer.apply(jsonElement)); ++ }, instance -> { ++ throw new UnsupportedOperationException("Cannot encode custom criterion trigger instances"); ++ }); ++ } ++ ++ public record PaperCustomTriggerInstance(B apiInstance) implements SimpleCriterionTrigger.SimpleInstance { ++ ++ @Override ++ public Optional player() { ++ return Optional.empty(); ++ } ++ } ++ ++} +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java +index 98b096339fe48b2fc8169ae0376e05d59236fc9a..b348a1da6c79b19ae1d286ba1cd7391c9ce5c0eb 100644 +--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java +@@ -1,6 +1,9 @@ + package io.papermc.paper.registry; + ++import io.papermc.paper.advancement.CriteriaTrigger; ++import io.papermc.paper.advancement.PaperCriteriaTrigger; + import io.papermc.paper.adventure.PaperAdventure; ++import io.papermc.paper.registry.data.PaperCriteriaTriggerRegistryEntry; + import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry; + import io.papermc.paper.registry.data.PaperGameEventRegistryEntry; + import io.papermc.paper.registry.entry.RegistryEntry; +@@ -10,6 +13,7 @@ import java.util.IdentityHashMap; + import java.util.List; + import java.util.Map; + import java.util.Objects; ++import net.minecraft.advancements.CriterionTrigger; + import net.minecraft.core.Registry; + import net.minecraft.core.registries.Registries; + import net.minecraft.resources.ResourceKey; +@@ -84,6 +88,7 @@ public final class PaperRegistries { + entry(Registries.VILLAGER_TYPE, RegistryKey.VILLAGER_TYPE, Villager.Type.class, CraftVillager.CraftType::new), + entry(Registries.MAP_DECORATION_TYPE, RegistryKey.MAP_DECORATION_TYPE, MapCursor.Type.class, CraftMapCursor.CraftType::new), + entry(Registries.MENU, RegistryKey.MENU, MenuType.class, CraftMenuType::new), ++ RegistryEntry., CriteriaTrigger, PaperCriteriaTriggerRegistryEntry.PaperBuilder>addable(Registries.TRIGGER_TYPE, RegistryKey.TRIGGER_TYPE, CriteriaTrigger.class, PaperCriteriaTrigger::create, PaperCriteriaTriggerRegistryEntry.PaperBuilder::new), + + // data-drivens + entry(Registries.STRUCTURE, RegistryKey.STRUCTURE, Structure.class, CraftStructure::new).delayed(), +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java +index 1026b9c04f94ed73049b980822a2eafdbacea7fd..0fb89f4ec4435b892aca2ba73f7c29afed7cff83 100644 +--- a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java +@@ -83,7 +83,7 @@ public class PaperRegistryAccess implements RegistryAccess { + return possiblyUnwrap(registryHolder.get()); + } + +- public > WritableCraftRegistry getWritableRegistry(final RegistryKey key) { ++ public > WritableCraftRegistry getWritableRegistry(final RegistryKey key) { + final Registry registry = this.getRegistry(key); + if (registry instanceof WritableCraftRegistry) { + return (WritableCraftRegistry) registry; +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java b/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java +index 528c6ee1739d92f766f3904acd7fc5734c93388a..1ffc6343c88d5a92a03414b5e76c185b3e3f35b5 100644 +--- a/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistryBuilder.java +@@ -9,7 +9,7 @@ public interface PaperRegistryBuilder extends RegistryBuilder { + M build(); + + @FunctionalInterface +- interface Filler> { ++ interface Filler> { + + B fill(Conversions conversions, TypedKey key, @Nullable M nms); + +@@ -19,7 +19,7 @@ public interface PaperRegistryBuilder extends RegistryBuilder { + } + + @FunctionalInterface +- interface Factory> { ++ interface Factory> { + + B create(Conversions conversions, TypedKey key); + } +diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java +index 69e946173407eb05b18a2b19b0d45cbb3213570b..efb6bab43097505d338da0b2c68591872b4b1ba4 100644 +--- a/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java ++++ b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java +@@ -87,7 +87,7 @@ public class PaperRegistryListenerManager { + } + + // TODO remove Keyed +- public , R> R registerWithListeners( ++ public , R> R registerWithListeners( + final Registry registry, + final ResourceKey key, + final M nms, +@@ -106,7 +106,7 @@ public class PaperRegistryListenerManager { + return this.registerWithListeners(registry, modifiableEntry, key, nms, builder, registrationInfo, registerMethod, conversions); + } + +- > void registerWithListeners( // TODO remove Keyed ++ > void registerWithListeners( // TODO remove Keyed + final WritableRegistry registry, + final RegistryEntryInfo entry, + final ResourceKey key, +@@ -121,7 +121,7 @@ public class PaperRegistryListenerManager { + this.registerWithListeners(registry, RegistryEntry.Modifiable.asModifiable(entry), key, null, builder, registrationInfo, WritableRegistry::register, conversions); + } + +- public , R> R registerWithListeners( // TODO remove Keyed ++ public , R> R registerWithListeners( // TODO remove Keyed + final Registry registry, + final RegistryEntry.Modifiable entry, + final ResourceKey key, +@@ -156,7 +156,7 @@ public class PaperRegistryListenerManager { + R register(WritableRegistry writableRegistry, ResourceKey key, M value, RegistrationInfo registrationInfo); + } + +- public > void runFreezeListeners(final ResourceKey> resourceKey, final Conversions conversions) { ++ public > void runFreezeListeners(final ResourceKey> resourceKey, final Conversions conversions) { + final @Nullable RegistryEntryInfo entry = PaperRegistries.getEntry(resourceKey); + if (!RegistryEntry.Addable.isAddable(entry) || !this.freezeEventTypes.hasHandlers(entry.apiKey())) { + return; +@@ -167,14 +167,14 @@ public class PaperRegistryListenerManager { + LifecycleEventRunner.INSTANCE.callEvent(this.freezeEventTypes.getEventType(entry.apiKey()), event); + } + +- public > RegistryEntryAddEventType getRegistryValueAddEventType(final RegistryEventProvider type) { ++ 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.valueAddEventTypes.getOrCreate(type.registryKey(), RegistryEntryAddEventTypeImpl::new); + } + +- public > LifecycleEventType.Prioritizable> getRegistryFreezeEventType(final RegistryEventProvider type) { ++ public > LifecycleEventType.Prioritizable> getRegistryFreezeEventType(final RegistryEventProvider type) { + if (!RegistryEntry.Addable.isAddable(PaperRegistries.getEntry(type.registryKey()))) { + throw new IllegalArgumentException(type.registryKey() + " does not support RegistryFreezeEvent"); + } +diff --git a/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java b/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java +index 78317c7ab42a666f19634593a8f3b696700764c8..37aead2a4886866daa5e76708ff070e19d9ac8da 100644 +--- a/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java ++++ b/src/main/java/io/papermc/paper/registry/WritableCraftRegistry.java +@@ -4,6 +4,7 @@ import com.mojang.serialization.Lifecycle; + import io.papermc.paper.adventure.PaperAdventure; + import io.papermc.paper.registry.data.util.Conversions; + import io.papermc.paper.registry.entry.RegistryEntry; ++import io.papermc.paper.registry.entry.RegistryEntryInfo; + import io.papermc.paper.registry.event.WritableRegistry; + import java.util.Optional; + import java.util.function.BiFunction; +@@ -17,21 +18,21 @@ import org.bukkit.craftbukkit.CraftRegistry; + import org.bukkit.craftbukkit.util.ApiVersion; + import org.checkerframework.checker.nullness.qual.Nullable; + +-public class WritableCraftRegistry> extends CraftRegistry { ++public class WritableCraftRegistry> extends CraftRegistry { + + private static final RegistrationInfo FROM_PLUGIN = new RegistrationInfo(Optional.empty(), Lifecycle.experimental()); + +- private final RegistryEntry.BuilderHolder entry; ++ private final RegistryEntryInfo entry; + private final MappedRegistry registry; +- private final PaperRegistryBuilder.Factory builderFactory; ++ private final PaperRegistryBuilder.Factory builderFactory; + private final BiFunction minecraftToBukkit; + + public WritableCraftRegistry( +- final RegistryEntry.BuilderHolder entry, ++ final RegistryEntryInfo entry, + final Class classToPreload, + final MappedRegistry registry, + final BiFunction serializationUpdater, +- final PaperRegistryBuilder.Factory builderFactory, ++ final PaperRegistryBuilder.Factory builderFactory, + final BiFunction minecraftToBukkit + ) { + super(classToPreload, registry, null, serializationUpdater); +@@ -46,14 +47,18 @@ public class WritableCraftRegistry key, final Consumer value) { +- WritableCraftRegistry.this.register(key, value, this.conversions); ++ public void register(final TypedKey key, final Consumer value) { ++ WritableCraftRegistry.this.register((TypedKey) key, b -> value.accept((VB) b), this.conversions); + } + } + } +diff --git a/src/main/java/io/papermc/paper/registry/data/PaperCriteriaTriggerRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaperCriteriaTriggerRegistryEntry.java +new file mode 100644 +index 0000000000000000000000000000000000000000..602974ecc6c5eab9ef1b249b05d114cc151e43ae +--- /dev/null ++++ b/src/main/java/io/papermc/paper/registry/data/PaperCriteriaTriggerRegistryEntry.java +@@ -0,0 +1,45 @@ ++package io.papermc.paper.registry.data; ++ ++import com.google.gson.JsonElement; ++import io.papermc.paper.advancement.CriteriaTrigger; ++import io.papermc.paper.advancement.PaperCustomCriterionTrigger; ++import io.papermc.paper.registry.PaperRegistryBuilder; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.data.util.Conversions; ++import java.util.function.Function; ++import net.minecraft.advancements.CriterionTrigger; ++import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ++ ++import static io.papermc.paper.registry.data.util.Checks.asConfigured; ++ ++public class PaperCriteriaTriggerRegistryEntry implements CriteriaTriggerRegistryEntry { ++ ++ protected @MonotonicNonNull Function deserializer; ++ ++ public PaperCriteriaTriggerRegistryEntry(final Conversions conversions, final TypedKey key) { ++ } ++ ++ @Override ++ public Function deserializer() { ++ return asConfigured(this.deserializer, "deserializer"); ++ } ++ ++ public static final class PaperBuilder extends PaperCriteriaTriggerRegistryEntry ++ implements CriteriaTriggerRegistryEntry.Builder, PaperRegistryBuilder, CriteriaTrigger> { ++ ++ public PaperBuilder(final Conversions conversions, final TypedKey key) { ++ super(conversions, key); ++ } ++ ++ @Override ++ public PaperBuilder deserializer(final Function deserializer) { ++ this.deserializer = deserializer; ++ return this; ++ } ++ ++ @Override ++ public CriterionTrigger> build() { ++ return new PaperCustomCriterionTrigger<>(this.deserializer()); ++ } ++ } ++} +diff --git a/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java +index aeec9b3ae2911f041d000b3db72f37974020ba60..9fcc272b7828192f61b4bfe287bb1e8fc2180685 100644 +--- a/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java ++++ b/src/main/java/io/papermc/paper/registry/entry/AddableRegistryEntry.java +@@ -3,9 +3,7 @@ package io.papermc.paper.registry.entry; + import io.papermc.paper.registry.PaperRegistryBuilder; + import io.papermc.paper.registry.RegistryHolder; + import io.papermc.paper.registry.RegistryKey; +-import io.papermc.paper.registry.TypedKey; + import io.papermc.paper.registry.WritableCraftRegistry; +-import io.papermc.paper.registry.data.util.Conversions; + import java.util.function.BiFunction; + import net.minecraft.core.MappedRegistry; + import net.minecraft.core.Registry; +@@ -13,32 +11,27 @@ import net.minecraft.resources.ResourceKey; + import org.bukkit.Keyed; + import org.bukkit.NamespacedKey; + +-public class AddableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Addable { ++public class AddableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Addable { + +- private final PaperRegistryBuilder.Filler builderFiller; ++ private final PaperRegistryBuilder.Factory builderFactory; + + protected AddableRegistryEntry( + final ResourceKey> mcKey, + final RegistryKey apiKey, + final Class classToPreload, + final BiFunction minecraftToBukkit, +- final PaperRegistryBuilder.Filler builderFiller ++ final PaperRegistryBuilder.Factory builderFactory + ) { + super(mcKey, apiKey, classToPreload, minecraftToBukkit); +- this.builderFiller = builderFiller; ++ this.builderFactory = builderFactory; + } + + private WritableCraftRegistry createRegistry(final Registry registry) { +- return new WritableCraftRegistry<>(this, this.classToPreload, (MappedRegistry) registry, this.updater, this.builderFiller.asFactory(), this.minecraftToBukkit); ++ return new WritableCraftRegistry<>(this, this.classToPreload, (MappedRegistry) registry, this.updater, this.builderFactory, this.minecraftToBukkit); + } + + @Override + public RegistryHolder createRegistryHolder(final Registry nmsRegistry) { + return new RegistryHolder.Memoized<>(() -> this.createRegistry(nmsRegistry)); + } +- +- @Override +- public B fillBuilder(final Conversions conversions, final TypedKey key, final M nms) { +- return this.builderFiller.fill(conversions, key, nms); +- } + } +diff --git a/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java +index 515a995e3862f8e7cb93d149315ea32e04a08716..77084a2ade7cd7dfc712ab1275127fc8146a4fff 100644 +--- a/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java ++++ b/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java +@@ -10,7 +10,7 @@ import net.minecraft.resources.ResourceKey; + import org.bukkit.Keyed; + import org.bukkit.NamespacedKey; + +-public class ModifiableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Modifiable { ++public class ModifiableRegistryEntry> extends CraftRegistryEntry implements RegistryEntry.Modifiable { + + protected final PaperRegistryBuilder.Filler builderFiller; + +diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java +index f2e919705301cb23ed1938ca3c1976378249172c..25d5a61623f76ea54f758747fe1e31d9ade0625b 100644 +--- a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java ++++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java +@@ -39,7 +39,7 @@ public interface RegistryEntry extends RegistryEntryInfo(this); + } + +- interface BuilderHolder> extends RegistryEntryInfo { ++ interface BuilderHolder> extends RegistryEntryInfo { + + B fillBuilder(Conversions conversions, TypedKey key, M nms); + } +@@ -47,13 +47,13 @@ public interface RegistryEntry extends RegistryEntryInfo> extends BuilderHolder { ++ interface Modifiable> extends BuilderHolder { + + static boolean isModifiable(final @Nullable RegistryEntryInfo entry) { + return entry instanceof RegistryEntry.Modifiable || (entry instanceof final DelayedRegistryEntry delayed && delayed.delegate() instanceof RegistryEntry.Modifiable); + } + +- static > Modifiable asModifiable(final RegistryEntryInfo entry) { // TODO remove Keyed ++ static > Modifiable asModifiable(final RegistryEntryInfo entry) { // TODO remove Keyed + return (Modifiable) possiblyUnwrap(entry); + } + +@@ -65,7 +65,7 @@ public interface RegistryEntry extends RegistryEntryInfo> extends BuilderHolder { // TODO remove Keyed ++ interface Addable> extends RegistryEntryInfo { // TODO remove Keyed + + default RegistryFreezeEventImpl createFreezeEvent(final WritableCraftRegistry writableRegistry, final Conversions conversions) { + return new RegistryFreezeEventImpl<>(this.apiKey(), writableRegistry.createApiWritableRegistry(conversions), conversions); +@@ -75,7 +75,7 @@ public interface RegistryEntry extends RegistryEntryInfo || (entry instanceof final DelayedRegistryEntry delayed && delayed.delegate() instanceof RegistryEntry.Addable); + } + +- static > Addable asAddable(final RegistryEntryInfo entry) { ++ static > Addable asAddable(final RegistryEntryInfo entry) { + return (Addable) possiblyUnwrap(entry); + } + } +@@ -83,7 +83,7 @@ public interface RegistryEntry extends RegistryEntryInfo> extends Modifiable, Addable { // TODO remove Keyed ++ interface Writable> extends Modifiable, Addable { // TODO remove Keyed + + static boolean isWritable(final @Nullable RegistryEntryInfo entry) { + return entry instanceof RegistryEntry.Writable || (entry instanceof final DelayedRegistryEntry delayed && delayed.delegate() instanceof RegistryEntry.Writable); +@@ -115,7 +115,7 @@ public interface RegistryEntry extends RegistryEntryInfo(mcKey, apiKey, apiRegistrySupplier); + } + +- static > RegistryEntry modifiable( ++ static > RegistryEntry modifiable( + final ResourceKey> mcKey, + final RegistryKey apiKey, + final Class toPreload, +@@ -125,7 +125,17 @@ public interface RegistryEntry extends RegistryEntryInfo(mcKey, apiKey, toPreload, minecraftToBukkit, filler); + } + +- static > RegistryEntry writable( ++ static > RegistryEntry addable( ++ final ResourceKey> mcKey, ++ final RegistryKey apiKey, ++ final Class toPreload, ++ final BiFunction minecraftToBukkit, ++ final PaperRegistryBuilder.Factory factory ++ ) { ++ return new AddableRegistryEntry<>(mcKey, apiKey, toPreload, minecraftToBukkit, factory); ++ } ++ ++ static > RegistryEntry writable( + final ResourceKey> mcKey, + final RegistryKey apiKey, + final Class toPreload, +diff --git a/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java +index 562accce731630327d116afd1c9d559df7e386bd..70f84bddd59f6dfe7e19484e53686fcc315626c3 100644 +--- a/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java ++++ b/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java +@@ -2,13 +2,17 @@ package io.papermc.paper.registry.entry; + + import io.papermc.paper.registry.PaperRegistryBuilder; + import io.papermc.paper.registry.RegistryKey; ++import io.papermc.paper.registry.TypedKey; ++import io.papermc.paper.registry.data.util.Conversions; + import java.util.function.BiFunction; + import net.minecraft.core.Registry; + import net.minecraft.resources.ResourceKey; + import org.bukkit.Keyed; + import org.bukkit.NamespacedKey; + +-public class WritableRegistryEntry> extends AddableRegistryEntry implements RegistryEntry.Writable { // TODO remove Keyed ++public class WritableRegistryEntry> extends AddableRegistryEntry implements RegistryEntry.Writable { // TODO remove Keyed ++ ++ private final PaperRegistryBuilder.Filler builderFiller; + + protected WritableRegistryEntry( + final ResourceKey> mcKey, +@@ -17,6 +21,12 @@ public class WritableRegistryEntry minecraftToBukkit, + final PaperRegistryBuilder.Filler builderFiller + ) { +- super(mcKey, apiKey, classToPreload, minecraftToBukkit, builderFiller); ++ super(mcKey, apiKey, classToPreload, minecraftToBukkit, builderFiller.asFactory()); ++ this.builderFiller = builderFiller; ++ } ++ ++ @Override ++ public B fillBuilder(final Conversions conversions, final TypedKey key, final M nms) { ++ return this.builderFiller.fill(conversions, key, nms); + } + } +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java +index cc9c8fd313f530777af80ad79e03903f3f8f9829..0d17ed13e37d45cae5ba4877598e4a7e461b6c1a 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEventImpl.java +@@ -14,7 +14,7 @@ import net.minecraft.resources.RegistryOps; + import org.bukkit.Keyed; + import org.checkerframework.checker.nullness.qual.NonNull; + +-public record RegistryEntryAddEventImpl>( ++public record RegistryEntryAddEventImpl>( + TypedKey key, + B builder, + RegistryKey registryKey, +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java +index 34c842ffa355e3c8001dd7b8551bcb49229a6391..93fbebe980870f8f00bdc0ca146fe708c1421055 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryEventTypeProviderImpl.java +@@ -13,12 +13,12 @@ public class RegistryEventTypeProviderImpl implements RegistryEventTypeProvider + } + + @Override +- public > RegistryEntryAddEventType registryEntryAdd(final RegistryEventProvider type) { ++ public > RegistryEntryAddEventType registryEntryAdd(final RegistryEventProvider type) { + return PaperRegistryListenerManager.INSTANCE.getRegistryValueAddEventType(type); + } + + @Override +- public > LifecycleEventType.Prioritizable> registryFreeze(final RegistryEventProvider type) { ++ public > LifecycleEventType.Prioritizable> registryFreeze(final RegistryEventProvider type) { + return PaperRegistryListenerManager.INSTANCE.getRegistryFreezeEventType(type); + } + } +diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java +index 63957d2509e68ccc6eb2fd9ecaa35bfad7b71b81..cda1588667eae0e44ffa81e2376e278fe0b89a8d 100644 +--- a/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java ++++ b/src/main/java/io/papermc/paper/registry/event/RegistryFreezeEventImpl.java +@@ -13,7 +13,7 @@ import net.minecraft.resources.RegistryOps; + import org.bukkit.Keyed; + import org.checkerframework.checker.nullness.qual.NonNull; + +-public record RegistryFreezeEventImpl>( ++public record RegistryFreezeEventImpl>( + RegistryKey registryKey, + WritableRegistry registry, + Conversions conversions +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 +index 0655386f85148cdb840d43ada97ab86bb773a765..6185d2e81d12093be95acbff6700306bda78068b 100644 +--- a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java ++++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddEventTypeImpl.java +@@ -9,7 +9,7 @@ import io.papermc.paper.registry.event.RegistryEntryAddEvent; + import java.util.function.Consumer; + import java.util.function.Predicate; + +-public class RegistryEntryAddEventTypeImpl> extends PrioritizableLifecycleEventType, RegistryEntryAddConfiguration> implements RegistryEntryAddEventType { ++public class RegistryEntryAddEventTypeImpl> extends PrioritizableLifecycleEventType, RegistryEntryAddConfiguration> implements RegistryEntryAddEventType { + + public RegistryEntryAddEventTypeImpl(final RegistryKey registryKey, final String eventName) { + super(registryKey + " / " + eventName, BootstrapContext.class); +diff --git a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java +index 548f5bf979e88708e98d04dfe22ccaa300c91ddd..ed75bdb9f057066b85e8f50e33245c8ad9964b93 100644 +--- a/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java ++++ b/src/main/java/io/papermc/paper/registry/event/type/RegistryEntryAddHandlerConfiguration.java +@@ -11,7 +11,7 @@ import java.util.function.Predicate; + import org.checkerframework.checker.nullness.qual.Nullable; + import org.jetbrains.annotations.Contract; + +-public class RegistryEntryAddHandlerConfiguration> extends PrioritizedLifecycleEventHandlerConfigurationImpl> implements RegistryEntryAddConfiguration { ++public class RegistryEntryAddHandlerConfiguration> extends PrioritizedLifecycleEventHandlerConfigurationImpl> implements RegistryEntryAddConfiguration { + + private @Nullable Predicate> filter; + +diff --git a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java +index 35772110e9318df46a2729dbc0b5879b290011b7..3b37a861c111cfe1fa52332c0bdb27e28c102e01 100644 +--- a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java ++++ b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java +@@ -38,7 +38,7 @@ public abstract class SimpleCriterionTrigger predicate) { ++ public void trigger(ServerPlayer player, Predicate predicate) { // Paper - OBFHELPER + PlayerAdvancements playerAdvancements = player.getAdvancements(); + Set> set = (Set) playerAdvancements.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak + if (set != null && !set.isEmpty()) { +diff --git a/src/test/java/org/bukkit/registry/RegistryArgumentAddedTest.java b/src/test/java/org/bukkit/registry/RegistryArgumentAddedTest.java +index 0dd775ad1bd0bf9ba7ea05255d543a9df8b5fcfd..daf36c4a9b8267901e3ccb076ca7f0690bbfc1da 100644 +--- a/src/test/java/org/bukkit/registry/RegistryArgumentAddedTest.java ++++ b/src/test/java/org/bukkit/registry/RegistryArgumentAddedTest.java +@@ -38,6 +38,7 @@ public class RegistryArgumentAddedTest extends AbstractTestingBase { + } + }); + ++ loadedRegistries.remove(io.papermc.paper.registry.RegistryKey.TRIGGER_TYPE); // Paper - remove because it's only partially implemented (only supports adding custom ones for now) + assertTrue(loadedRegistries.isEmpty(), String.format(""" + There are registries present, which are not registered in RegistriesArgumentProvider. + diff --git a/test-plugin/src/main/java/io/papermc/testplugin/CustomTriggerInstance.java b/test-plugin/src/main/java/io/papermc/testplugin/CustomTriggerInstance.java new file mode 100644 index 0000000000..78271bbbeb --- /dev/null +++ b/test-plugin/src/main/java/io/papermc/testplugin/CustomTriggerInstance.java @@ -0,0 +1,4 @@ +package io.papermc.testplugin; + +public record CustomTriggerInstance(boolean isFlying) { +} diff --git a/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java b/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java index 671c37fa40..f01c323781 100644 --- a/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java +++ b/test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java @@ -1,10 +1,17 @@ package io.papermc.testplugin; +import io.papermc.paper.advancement.CriteriaTrigger; +import io.papermc.paper.event.player.ChatEvent; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; +import org.bukkit.Registry; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; public final class TestPlugin extends JavaPlugin implements Listener { + final CriteriaTrigger trigger = (CriteriaTrigger) RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIGGER_TYPE).get(TestPluginBootstrap.CUSTOM_TRIGGER_TYPE); @Override public void onEnable() { this.getServer().getPluginManager().registerEvents(this, this); @@ -12,4 +19,8 @@ public final class TestPlugin extends JavaPlugin implements Listener { // io.papermc.testplugin.brigtests.Registration.registerViaOnEnable(this); } + @EventHandler + public void onEvent(ChatEvent event) { + this.trigger.trigger(event.getPlayer(), custom -> custom.isFlying() == event.getPlayer().isFlying()); + } } diff --git a/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java b/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java index fe2b287b25..62fa1ceba3 100644 --- a/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java +++ b/test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java @@ -1,14 +1,34 @@ package io.papermc.testplugin; +import io.papermc.paper.advancement.CriteriaTrigger; import io.papermc.paper.plugin.bootstrap.BootstrapContext; import io.papermc.paper.plugin.bootstrap.PluginBootstrap; +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.TypedKey; +import io.papermc.paper.registry.data.CriteriaTriggerRegistryEntry; +import io.papermc.paper.registry.event.RegistryEvents; +import net.kyori.adventure.key.Key; +import org.intellij.lang.annotations.Subst; import org.jetbrains.annotations.NotNull; public class TestPluginBootstrap implements PluginBootstrap { + // this method will be in CriteriaTriggerKeys as a public method + private static TypedKey> create(@Subst("key") final String key) { + return TypedKey.create(RegistryKey.TRIGGER_TYPE, Key.key("test", key)); + } + + static final TypedKey> CUSTOM_TRIGGER_TYPE = create("trigger"); + @Override public void bootstrap(@NotNull BootstrapContext context) { // io.papermc.testplugin.brigtests.Registration.registerViaBootstrap(context); + + context.getLifecycleManager().registerEventHandler(RegistryEvents.TRIGGER_TYPE.freeze(), event -> { + event.registry().>register(CUSTOM_TRIGGER_TYPE, builder -> { + builder.deserializer(ignored -> new CustomTriggerInstance(ignored.getAsBoolean())); + }); + }); } }