mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-26 09:42:06 -07:00
rename RegistryFreezeEvent to RegistryComposeEvent
This commit is contained in:
@@ -3,6 +3,7 @@ package io.papermc.paper.registry.data;
|
||||
import io.papermc.paper.registry.RegistryBuilder;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.registry.event.RegistryComposeEvent;
|
||||
import io.papermc.paper.registry.set.RegistryKeySet;
|
||||
import io.papermc.paper.registry.set.RegistrySet;
|
||||
import io.papermc.paper.registry.tag.TagKey;
|
||||
@@ -153,7 +154,7 @@ public interface EnchantmentRegistryEntry {
|
||||
/**
|
||||
* Configures the set of supported items this enchantment can be applied on. This
|
||||
* can be a {@link RegistryKeySet} created via {@link RegistrySet#keySet(io.papermc.paper.registry.RegistryKey, Iterable)} or
|
||||
* a tag obtained via {@link io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)} with
|
||||
* a tag obtained via {@link RegistryComposeEvent#getOrCreateTag(TagKey)} with
|
||||
* tag keys found in {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys} such as
|
||||
* {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_ARMOR} and
|
||||
* {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_SWORD}.
|
||||
@@ -161,7 +162,7 @@ public interface EnchantmentRegistryEntry {
|
||||
* @param supportedItems the registry key set representing the supported items.
|
||||
* @return this builder instance.
|
||||
* @see RegistrySet#keySet(RegistryKey, TypedKey[])
|
||||
* @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
|
||||
* @see RegistryComposeEvent#getOrCreateTag(TagKey)
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder supportedItems(RegistryKeySet<ItemType> supportedItems);
|
||||
@@ -170,7 +171,7 @@ public interface EnchantmentRegistryEntry {
|
||||
* Configures a set of item types this enchantment can naturally be applied to, when enchanting in an
|
||||
* enchantment table.This can be a {@link RegistryKeySet} created via
|
||||
* {@link RegistrySet#keySet(io.papermc.paper.registry.RegistryKey, Iterable)} or a tag obtained via
|
||||
* {@link io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)} with
|
||||
* {@link RegistryComposeEvent#getOrCreateTag(TagKey)} with
|
||||
* tag keys found in {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys} such as
|
||||
* {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_ARMOR} and
|
||||
* {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_SWORD}.
|
||||
@@ -182,7 +183,7 @@ public interface EnchantmentRegistryEntry {
|
||||
* @param primaryItems the registry key set representing the primary items.
|
||||
* @return this builder instance.
|
||||
* @see RegistrySet#keySet(RegistryKey, TypedKey[])
|
||||
* @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
|
||||
* @see RegistryComposeEvent#getOrCreateTag(TagKey)
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder primaryItems(@Nullable RegistryKeySet<ItemType> primaryItems);
|
||||
@@ -285,7 +286,7 @@ public interface EnchantmentRegistryEntry {
|
||||
* @param exclusiveWith a registry set of enchantments exclusive to this one.
|
||||
* @return this builder instance.
|
||||
* @see RegistrySet#keySet(RegistryKey, TypedKey[])
|
||||
* @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
|
||||
* @see RegistryComposeEvent#getOrCreateTag(TagKey)
|
||||
*/
|
||||
@Contract(value = "_ -> this", mutates = "this")
|
||||
Builder exclusiveWith(RegistryKeySet<Enchantment> exclusiveWith);
|
||||
|
@@ -0,0 +1,40 @@
|
||||
package io.papermc.paper.registry.event;
|
||||
|
||||
import io.papermc.paper.registry.RegistryBuilder;
|
||||
import io.papermc.paper.registry.tag.Tag;
|
||||
import io.papermc.paper.registry.tag.TagKey;
|
||||
import org.bukkit.Keyed;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Event object for {@link RegistryEventProvider#compose()} ()}. This
|
||||
* event is fired after a registry is loaded with its normal values.
|
||||
* It provides a way for plugins to add new objects to the registry.
|
||||
*
|
||||
* @param <T> registry entry type
|
||||
* @param <B> registry entry builder type
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@NullMarked
|
||||
@ApiStatus.NonExtendable
|
||||
public interface RegistryComposeEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T> {
|
||||
|
||||
/**
|
||||
* Get the writable registry.
|
||||
*
|
||||
* @return a writable registry
|
||||
*/
|
||||
WritableRegistry<T, B> registry();
|
||||
|
||||
/**
|
||||
* Gets or creates a tag for the given tag key. This tag
|
||||
* is then required to be filled either from the built-in or
|
||||
* custom datapack.
|
||||
*
|
||||
* @param tagKey the tag key
|
||||
* @return the tag
|
||||
* @param <V> the tag value type
|
||||
*/
|
||||
<V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey);
|
||||
}
|
@@ -15,7 +15,7 @@ import org.jspecify.annotations.NullMarked;
|
||||
* Supported events are:
|
||||
* <ul>
|
||||
* <li>{@link RegistryEntryAddEvent} (via {@link #entryAdd()})</li>
|
||||
* <li>{@link RegistryFreezeEvent} (via {@link #freeze()})</li>
|
||||
* <li>{@link RegistryComposeEvent} (via {@link #compose()})</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param <T> registry entry type
|
||||
@@ -45,8 +45,24 @@ public interface RegistryEventProvider<T, B extends RegistryBuilder<T>> {
|
||||
* to register a handler for {@link RegistryFreezeEvent}.
|
||||
*
|
||||
* @return the registry freeze event type
|
||||
* @deprecated use {@link #compose()} instead.
|
||||
*/
|
||||
LifecycleEventType.Prioritizable<BootstrapContext, RegistryFreezeEvent<T, B>> freeze();
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "1.21.7 or 1.22, whichever comes first")
|
||||
@Deprecated(forRemoval = true)
|
||||
default LifecycleEventType.Prioritizable<BootstrapContext, ? super RegistryFreezeEvent<T, B>> freeze() {
|
||||
return this.compose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event type for {@link RegistryComposeEvent} which is fired after
|
||||
* a registry is loaded of expected elements. It allows for the registration of new objects.
|
||||
* <p>
|
||||
* Can be used in {@link io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager#registerEventHandler(LifecycleEventType, LifecycleEventHandler)}
|
||||
* to register a handler for {@link RegistryComposeEvent}.
|
||||
*
|
||||
* @return the registry freeze event type
|
||||
*/
|
||||
LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<T, B>> compose();
|
||||
|
||||
/**
|
||||
* Gets the registry key associated with this event type provider.
|
||||
|
@@ -22,8 +22,7 @@ record RegistryEventProviderImpl<T, B extends RegistryBuilder<T>>(RegistryKey<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public LifecycleEventType.Prioritizable<BootstrapContext, RegistryFreezeEvent<T, B>> freeze() {
|
||||
return RegistryEventTypeProvider.provider().registryFreeze(this);
|
||||
public LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<T, B>> compose() {
|
||||
return RegistryEventTypeProvider.provider().registryCompose(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -20,5 +20,5 @@ interface RegistryEventTypeProvider {
|
||||
|
||||
<T, B extends RegistryBuilder<T>> RegistryEntryAddEventType<T, B> registryEntryAdd(RegistryEventProvider<T, B> type);
|
||||
|
||||
<T, B extends RegistryBuilder<T>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryFreezeEvent<T, B>> registryFreeze(RegistryEventProvider<T, B> type);
|
||||
<T, B extends RegistryBuilder<T>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<T, B>> registryCompose(RegistryEventProvider<T, B> type);
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import org.jspecify.annotations.NullMarked;
|
||||
import static io.papermc.paper.registry.event.RegistryEventProviderImpl.create;
|
||||
|
||||
/**
|
||||
* Holds providers for {@link RegistryEntryAddEvent} and {@link RegistryFreezeEvent}
|
||||
* Holds providers for {@link RegistryEntryAddEvent} and {@link RegistryComposeEvent}
|
||||
* handlers for each applicable registry.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
|
@@ -1,9 +1,6 @@
|
||||
package io.papermc.paper.registry.event;
|
||||
|
||||
import io.papermc.paper.registry.RegistryBuilder;
|
||||
import io.papermc.paper.registry.tag.Tag;
|
||||
import io.papermc.paper.registry.tag.TagKey;
|
||||
import org.bukkit.Keyed;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@@ -14,27 +11,11 @@ import org.jspecify.annotations.NullMarked;
|
||||
*
|
||||
* @param <T> registry entry type
|
||||
* @param <B> registry entry builder type
|
||||
* @deprecated renamed to {@link RegistryComposeEvent}
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "1.21.7 or 1.22, whichever comes first")
|
||||
@Deprecated(forRemoval = true)
|
||||
@NullMarked
|
||||
@ApiStatus.NonExtendable
|
||||
public interface RegistryFreezeEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T> {
|
||||
|
||||
/**
|
||||
* Get the writable registry.
|
||||
*
|
||||
* @return a writable registry
|
||||
*/
|
||||
WritableRegistry<T, B> registry();
|
||||
|
||||
/**
|
||||
* Gets or creates a tag for the given tag key. This tag
|
||||
* is then required to be filled either from the built-in or
|
||||
* custom datapack.
|
||||
*
|
||||
* @param tagKey the tag key
|
||||
* @return the tag
|
||||
* @param <V> the tag value type
|
||||
*/
|
||||
<V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey);
|
||||
public interface RegistryFreezeEvent<T, B extends RegistryBuilder<T>> extends RegistryComposeEvent<T, B> {
|
||||
}
|
||||
|
@@ -10,11 +10,12 @@ import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import io.papermc.paper.registry.entry.RegistryEntry;
|
||||
import io.papermc.paper.registry.entry.RegistryEntryMeta;
|
||||
import io.papermc.paper.registry.event.RegistryEntryAddEvent;
|
||||
import io.papermc.paper.registry.event.RegistryEntryAddEventImpl;
|
||||
import io.papermc.paper.registry.event.RegistryEventMap;
|
||||
import io.papermc.paper.registry.event.RegistryEventProvider;
|
||||
import io.papermc.paper.registry.event.RegistryFreezeEvent;
|
||||
import io.papermc.paper.registry.event.RegistryFreezeEventImpl;
|
||||
import io.papermc.paper.registry.event.RegistryComposeEventImpl;
|
||||
import io.papermc.paper.registry.event.RegistryComposeEvent;
|
||||
import io.papermc.paper.registry.event.type.RegistryEntryAddEventType;
|
||||
import io.papermc.paper.registry.event.type.RegistryEntryAddEventTypeImpl;
|
||||
import io.papermc.paper.registry.event.type.RegistryLifecycleEventType;
|
||||
@@ -37,7 +38,7 @@ public class PaperRegistryListenerManager {
|
||||
public static final PaperRegistryListenerManager INSTANCE = new PaperRegistryListenerManager();
|
||||
|
||||
public final RegistryEventMap valueAddEventTypes = new RegistryEventMap("value add");
|
||||
public final RegistryEventMap freezeEventTypes = new RegistryEventMap("freeze");
|
||||
public final RegistryEventMap composeEventType = new RegistryEventMap("compose");
|
||||
|
||||
private PaperRegistryListenerManager() {
|
||||
}
|
||||
@@ -157,28 +158,28 @@ public class PaperRegistryListenerManager {
|
||||
|
||||
public <M, T extends Keyed, B extends PaperRegistryBuilder<M, T>> void runFreezeListeners(final ResourceKey<? extends Registry<M>> resourceKey, final Conversions conversions) {
|
||||
final RegistryEntry<M, T> entry = PaperRegistries.getEntry(resourceKey);
|
||||
if (entry == null || !entry.meta().modificationApiSupport().canAdd() || !this.freezeEventTypes.hasHandlers(entry.apiKey())) {
|
||||
if (entry == null || !entry.meta().modificationApiSupport().canAdd() || !this.composeEventType.hasHandlers(entry.apiKey())) {
|
||||
return;
|
||||
}
|
||||
final RegistryEntryMeta.Buildable<M, T, B> writableEntry = (RegistryEntryMeta.Buildable<M, T, B>) entry.meta();
|
||||
final WritableCraftRegistry<M, T, B> writableRegistry = PaperRegistryAccess.instance().getWritableRegistry(entry.apiKey());
|
||||
final RegistryFreezeEventImpl<T, B> event = writableEntry.createFreezeEvent(writableRegistry, conversions);
|
||||
LifecycleEventRunner.INSTANCE.callEvent(this.freezeEventTypes.getEventType(entry.apiKey()), event);
|
||||
final RegistryComposeEventImpl<T, B> event = writableEntry.createPostLoadEvent(writableRegistry, conversions);
|
||||
LifecycleEventRunner.INSTANCE.callEvent(this.composeEventType.getEventType(entry.apiKey()), event);
|
||||
}
|
||||
|
||||
public <T, B extends RegistryBuilder<T>> RegistryEntryAddEventType<T, B> getRegistryValueAddEventType(final RegistryEventProvider<T, B> type) {
|
||||
final RegistryEntry<?, ?> entry = PaperRegistries.getEntry(type.registryKey());
|
||||
if (entry == null || !entry.meta().modificationApiSupport().canModify()) {
|
||||
throw new IllegalArgumentException(type.registryKey() + " does not support RegistryEntryAddEvent");
|
||||
throw new IllegalArgumentException(type.registryKey() + " does not support " + RegistryEntryAddEvent.class.getSimpleName());
|
||||
}
|
||||
return this.valueAddEventTypes.getOrCreate(type.registryKey(), RegistryEntryAddEventTypeImpl::new);
|
||||
}
|
||||
|
||||
public <T, B extends RegistryBuilder<T>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryFreezeEvent<T, B>> getRegistryFreezeEventType(final RegistryEventProvider<T, B> type) {
|
||||
public <T, B extends RegistryBuilder<T>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<T, B>> getRegistryComposeEventType(final RegistryEventProvider<T, B> type) {
|
||||
final RegistryEntry<?, ?> entry = PaperRegistries.getEntry(type.registryKey());
|
||||
if (entry == null || !entry.meta().modificationApiSupport().canAdd()) {
|
||||
throw new IllegalArgumentException(type.registryKey() + " does not support RegistryFreezeEvent");
|
||||
throw new IllegalArgumentException(type.registryKey() + " does not support " + RegistryComposeEvent.class.getSimpleName());
|
||||
}
|
||||
return this.freezeEventTypes.getOrCreate(type.registryKey(), RegistryLifecycleEventType::new);
|
||||
return this.composeEventType.getOrCreate(type.registryKey(), RegistryLifecycleEventType::new);
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.registry.WritableCraftRegistry;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import io.papermc.paper.registry.event.RegistryEntryAddEventImpl;
|
||||
import io.papermc.paper.registry.event.RegistryFreezeEventImpl;
|
||||
import io.papermc.paper.registry.event.RegistryComposeEventImpl;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
@@ -106,8 +106,8 @@ public sealed interface RegistryEntryMeta<M, A extends Keyed> permits RegistryEn
|
||||
return new RegistryEntryAddEventImpl<>(key, initialBuilder, this.apiKey(), conversions);
|
||||
}
|
||||
|
||||
public RegistryFreezeEventImpl<A, B> createFreezeEvent(final WritableCraftRegistry<M, A, B> writableRegistry, final Conversions conversions) {
|
||||
return new RegistryFreezeEventImpl<>(this.apiKey(), writableRegistry.createApiWritableRegistry(conversions), conversions);
|
||||
public RegistryComposeEventImpl<A, B> createPostLoadEvent(final WritableCraftRegistry<M, A, B> writableRegistry, final Conversions conversions) {
|
||||
return new RegistryComposeEventImpl<>(this.apiKey(), writableRegistry.createApiWritableRegistry(conversions), conversions);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -12,7 +12,7 @@ import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import org.bukkit.Keyed;
|
||||
|
||||
public record RegistryFreezeEventImpl<T, B extends RegistryBuilder<T>>(
|
||||
public record RegistryComposeEventImpl<T, B extends RegistryBuilder<T>>(
|
||||
RegistryKey<T> registryKey,
|
||||
WritableRegistry<T, B> registry,
|
||||
Conversions conversions
|
@@ -18,7 +18,7 @@ public class RegistryEventTypeProviderImpl implements RegistryEventTypeProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, B extends RegistryBuilder<T>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryFreezeEvent<T, B>> registryFreeze(final RegistryEventProvider<T, B> type) {
|
||||
return PaperRegistryListenerManager.INSTANCE.getRegistryFreezeEventType(type);
|
||||
public <T, B extends RegistryBuilder<T>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<T, B>> registryCompose(final RegistryEventProvider<T, B> type) {
|
||||
return PaperRegistryListenerManager.INSTANCE.getRegistryComposeEventType(type);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user