-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Dialog registry API #12671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Dialog registry API #12671
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
paper-api/src/generated/java/io/papermc/paper/registry/keys/DialogKeys.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package io.papermc.paper.registry.keys; | ||
|
|
||
| import static net.kyori.adventure.key.Key.key; | ||
|
|
||
| import io.papermc.paper.dialog.Dialog; | ||
| import io.papermc.paper.generated.GeneratedFrom; | ||
| import io.papermc.paper.registry.RegistryKey; | ||
| import io.papermc.paper.registry.TypedKey; | ||
| import net.kyori.adventure.key.Key; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Vanilla keys for {@link RegistryKey#DIALOG}. | ||
| * | ||
| * @apiNote The fields provided here are a direct representation of | ||
| * what is available from the vanilla game source. They may be | ||
| * changed (including removals) on any Minecraft version | ||
| * bump, so cross-version compatibility is not provided on the | ||
| * same level as it is on most of the other API. | ||
| */ | ||
| @SuppressWarnings({ | ||
| "unused", | ||
| "SpellCheckingInspection" | ||
| }) | ||
| @NullMarked | ||
| @GeneratedFrom("1.21.7-rc2") | ||
| public final class DialogKeys { | ||
| /** | ||
| * {@code minecraft:custom_options} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<Dialog> CUSTOM_OPTIONS = create(key("custom_options")); | ||
|
|
||
| /** | ||
| * {@code minecraft:quick_actions} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<Dialog> QUICK_ACTIONS = create(key("quick_actions")); | ||
|
|
||
| /** | ||
| * {@code minecraft:server_links} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<Dialog> SERVER_LINKS = create(key("server_links")); | ||
|
|
||
| private DialogKeys() { | ||
| } | ||
|
|
||
| /** | ||
| * Creates a typed key for {@link Dialog} in the registry {@code minecraft:dialog}. | ||
| * | ||
| * @param key the value's key in the registry | ||
| * @return a new typed key | ||
| */ | ||
| public static TypedKey<Dialog> create(final Key key) { | ||
| return TypedKey.create(RegistryKey.DIALOG, key); | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
paper-api/src/generated/java/io/papermc/paper/registry/keys/tags/DialogTagKeys.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package io.papermc.paper.registry.keys.tags; | ||
|
|
||
| import static net.kyori.adventure.key.Key.key; | ||
|
|
||
| import io.papermc.paper.dialog.Dialog; | ||
| import io.papermc.paper.generated.GeneratedFrom; | ||
| import io.papermc.paper.registry.RegistryKey; | ||
| import io.papermc.paper.registry.tag.TagKey; | ||
| import net.kyori.adventure.key.Key; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Vanilla tag keys for {@link RegistryKey#DIALOG}. | ||
| * | ||
| * @apiNote The fields provided here are a direct representation of | ||
| * what is available from the vanilla game source. They may be | ||
| * changed (including removals) on any Minecraft version | ||
| * bump, so cross-version compatibility is not provided on the | ||
| * same level as it is on most of the other API. | ||
| */ | ||
| @SuppressWarnings({ | ||
| "unused", | ||
| "SpellCheckingInspection" | ||
| }) | ||
| @NullMarked | ||
| @GeneratedFrom("1.21.7-rc2") | ||
| @ApiStatus.Experimental | ||
| public final class DialogTagKeys { | ||
| /** | ||
| * {@code #minecraft:pause_screen_additions} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TagKey<Dialog> PAUSE_SCREEN_ADDITIONS = create(key("pause_screen_additions")); | ||
|
|
||
| /** | ||
| * {@code #minecraft:quick_actions} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TagKey<Dialog> QUICK_ACTIONS = create(key("quick_actions")); | ||
|
|
||
| private DialogTagKeys() { | ||
| } | ||
|
|
||
| /** | ||
| * Creates a tag key for {@link Dialog} in the registry {@code minecraft:dialog}. | ||
| * | ||
| * @param key the tag key's key | ||
| * @return a new tag key | ||
| */ | ||
| @ApiStatus.Experimental | ||
| public static TagKey<Dialog> create(final Key key) { | ||
| return TagKey.create(RegistryKey.DIALOG, key); | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
paper-api/src/main/java/io/papermc/paper/dialog/Dialog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package io.papermc.paper.dialog; | ||
|
|
||
| import io.papermc.paper.registry.RegistryAccess; | ||
| import io.papermc.paper.registry.RegistryBuilderFactory; | ||
| import io.papermc.paper.registry.RegistryKey; | ||
| import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider; | ||
| import io.papermc.paper.registry.data.dialog.DialogRegistryEntry; | ||
| import java.util.function.Consumer; | ||
| import net.kyori.adventure.dialog.DialogLike; | ||
| import net.kyori.adventure.key.Key; | ||
| import net.kyori.adventure.key.KeyPattern; | ||
| import org.bukkit.Keyed; | ||
| import org.bukkit.Registry; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| /** | ||
| * Represents a dialog. Can be created during normal server operation via {@link #create(Consumer)}. | ||
| * Can also be created during bootstrap via {@link io.papermc.paper.registry.event.RegistryEvents#DIALOG}. | ||
| */ | ||
| @ApiStatus.NonExtendable | ||
| public interface Dialog extends Keyed, DialogLike { | ||
|
|
||
| /** | ||
| * Creates a new dialog using the provided builder. | ||
| * | ||
| * @param value the builder to use for creating the dialog | ||
| * @return a new dialog instance | ||
| */ | ||
| @ApiStatus.Experimental | ||
| static Dialog create(final Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value) { | ||
| return InlinedRegistryBuilderProvider.instance().createDialog(value); | ||
| } | ||
|
|
||
| // Start generate - Dialog | ||
| // @GeneratedFrom 1.21.7-rc2 | ||
| Dialog CUSTOM_OPTIONS = getDialog("custom_options"); | ||
|
|
||
| Dialog QUICK_ACTIONS = getDialog("quick_actions"); | ||
|
|
||
| Dialog SERVER_LINKS = getDialog("server_links"); | ||
| // End generate - Dialog | ||
|
|
||
| private static Dialog getDialog(@KeyPattern.Value final String value) { | ||
| final Registry<Dialog> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.DIALOG); | ||
| return registry.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, value)); | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
paper-api/src/main/java/io/papermc/paper/dialog/DialogResponseView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package io.papermc.paper.dialog; | ||
|
|
||
| import net.kyori.adventure.nbt.api.BinaryTagHolder; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.Contract; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * A view for a possible response to a dialog. | ||
| * There are no guarantees that this is an actual response to a | ||
| * dialog form. It is on the plugin to validate that the response | ||
| * is valid. | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @ApiStatus.NonExtendable | ||
| public interface DialogResponseView { | ||
|
|
||
| /** | ||
| * Gets the raw payload of the response. | ||
| * | ||
| * @return the raw payload | ||
| */ | ||
| @Contract(pure = true) | ||
| BinaryTagHolder payload(); | ||
|
|
||
| /** | ||
| * Gets a text value at a key. | ||
| * | ||
| * @param key the key | ||
| * @return the value (or null if it doesn't exist) | ||
| */ | ||
| @Contract(pure = true) | ||
| @Nullable String getText(String key); | ||
|
|
||
| /** | ||
| * Gets a boolean value at a key. | ||
| * | ||
| * @param key the key | ||
| * @return the value (or null if it doesn't exist) | ||
| */ | ||
| @Contract(pure = true) | ||
| @Nullable Boolean getBoolean(String key); | ||
|
|
||
| /** | ||
| * Gets a float value at a key. | ||
| * | ||
| * @param key the key | ||
| * @return the value (or null if it doesn't exist) | ||
| */ | ||
| @Contract(pure = true) | ||
| @Nullable Float getFloat(String key); | ||
| } |
7 changes: 7 additions & 0 deletions
7
paper-api/src/main/java/io/papermc/paper/dialog/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * This package contains classes and interfaces related to the dialog system in Paper. | ||
| */ | ||
| @NullMarked | ||
| package io.papermc.paper.dialog; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; |
79 changes: 79 additions & 0 deletions
79
paper-api/src/main/java/io/papermc/paper/event/player/PlayerCustomClickEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package io.papermc.paper.event.player; | ||
|
|
||
| import io.papermc.paper.connection.PlayerCommonConnection; | ||
| import io.papermc.paper.dialog.DialogResponseView; | ||
| import io.papermc.paper.registry.data.dialog.action.DialogActionCallback; | ||
| import net.kyori.adventure.key.Key; | ||
| import net.kyori.adventure.nbt.api.BinaryTagHolder; | ||
| import net.kyori.adventure.text.event.ClickCallback; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.Event; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * This event is fired for any custom click events. | ||
| * @see net.kyori.adventure.text.event.ClickEvent#custom(Key, BinaryTagHolder) | ||
| * @see io.papermc.paper.registry.data.dialog.action.DialogAction#customClick(DialogActionCallback, ClickCallback.Options) | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @ApiStatus.NonExtendable | ||
| @NullMarked | ||
| public abstract class PlayerCustomClickEvent extends Event { | ||
|
|
||
| private final Key identifier; | ||
| private final PlayerCommonConnection commonConnection; | ||
|
|
||
| @ApiStatus.Internal | ||
| protected PlayerCustomClickEvent(final Key identifier, final PlayerCommonConnection commonConnection) { | ||
| this.identifier = identifier; | ||
| this.commonConnection = commonConnection; | ||
| } | ||
|
|
||
| /** | ||
| * The identifier of the custom click event. | ||
| * | ||
| * @return the identifier | ||
| */ | ||
| public final Key getIdentifier() { | ||
| return this.identifier; | ||
| } | ||
|
|
||
| /** | ||
| * The tag payload of the custom click event. | ||
| * | ||
| * @return the tag (if any) | ||
| */ | ||
| public abstract @Nullable BinaryTagHolder getTag(); | ||
|
|
||
| /** | ||
| * The dialog response view of the custom click event. | ||
| * | ||
| * @return the dialog response view | ||
| */ | ||
| public abstract @Nullable DialogResponseView getDialogResponseView(); | ||
|
|
||
| /** | ||
| * The common connection of the player. | ||
| * | ||
| * @return the common connection | ||
| */ | ||
| public final PlayerCommonConnection getCommonConnection() { | ||
| return this.commonConnection; | ||
| } | ||
|
|
||
| @Override | ||
| public HandlerList getHandlers() { | ||
| // this will be how handler lists will work on interfaces | ||
| return PlayerCustomClickEvent.getHandlerList(); | ||
| } | ||
|
|
||
| public static HandlerList getHandlerList() { | ||
| final class Holder { | ||
| private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
| } | ||
| return Holder.HANDLER_LIST; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.