Package io.papermc.paper.tag
Interface PreFlattenTagRegistrar<T>
- Type Parameters:
T
- the type of value in the tag
- All Superinterfaces:
Registrar
Registrar for tags before they are flattened. Flattened
tags are tags which have any nested tags resolved to the tagged
values the nested tags point to. This registrar, being a pre-flatten
registrar, allows for modification before that flattening has happened, when
tags both point to individual entries and other nested tags.
An example of a tag being created in a pre-flatten registrar:
class YourBootstrapClass implements PluginBootstrap {
@Override
public void bootstrap(@NotNull BootstrapContext context) {
LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
manager.registerEventHandler(LifecycleEvents.TAGS.preFlatten(RegistryKey.ITEM), event -> {
final PreFlattenTagRegistrar<ItemType> registrar = event.registrar();
registrar.setTag(AXE_PICKAXE, Set.of(
TagEntry.tagEntry(ItemTypeTagKeys.PICKAXES),
TagEntry.tagEntry(ItemTypeTagKeys.AXES)
));
});
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds entries to the given tag.@Unmodifiable @NonNull Map
<TagKey<T>, Collection<TagEntry<T>>> Get a copy of all tags currently held in this registrar.@Unmodifiable @NonNull List
<TagEntry<T>> Get the tag with the given key.boolean
Checks if this registrar has a tag with the given key.@NonNull RegistryKey
<T> Get the registry key for this tag registrar.void
Sets the entries of the given tag.
-
Method Details
-
registryKey
@NonNull RegistryKey<T> registryKey()Get the registry key for this tag registrar.- Returns:
- the registry key
-
getAllTags
@Contract(value="-> new", pure=true) @Unmodifiable @NonNull Map<TagKey<T>,Collection<TagEntry<T>>> getAllTags()Get a copy of all tags currently held in this registrar.- Returns:
- an immutable map of all tags
-
hasTag
Checks if this registrar has a tag with the given key.- Parameters:
tagKey
- the key to check for- Returns:
- true if the tag exists, false otherwise
-
getTag
@Contract(value="_ -> new", pure=true) @Unmodifiable @NonNull List<TagEntry<T>> getTag(@NonNull TagKey<T> tagKey) Get the tag with the given key. UsehasTag(TagKey)
to check if a tag exists first.- Parameters:
tagKey
- the key of the tag to get- Returns:
- an immutable list of tag entries
- Throws:
NoSuchElementException
- if the tag does not exist- See Also:
-
addToTag
@Contract(mutates="this") void addToTag(@NonNull TagKey<T> tagKey, @NonNull Collection<TagEntry<T>> entries) Adds entries to the given tag. If the tag does not exist, it will be created.- Parameters:
tagKey
- the key of the tag to add toentries
- the entries to add- See Also:
-
setTag
@Contract(mutates="this") void setTag(@NonNull TagKey<T> tagKey, @NonNull Collection<TagEntry<T>> entries) Sets the entries of the given tag. If the tag does not exist, it will be created. If the tag does exist, it will be overwritten.- Parameters:
tagKey
- the key of the tag to setentries
- the entries to set- See Also:
-