Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
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 paper-api/src/main/java/io/papermc/paper/dialog/Dialog.java
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));
}
}
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);
}
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;
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.papermc.paper.registry;

import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.dialog.Dialog;
import io.papermc.paper.registry.tag.TagKey;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
Expand Down Expand Up @@ -215,7 +216,11 @@ public sealed interface RegistryKey<T> extends Keyed permits RegistryKeyImpl {
* @see io.papermc.paper.registry.keys.PigVariantKeys
*/
RegistryKey<Pig.Variant> PIG_VARIANT = create("pig_variant");

/**
* Data-driven registry for dialogs.
* @see io.papermc.paper.registry.keys.DialogKeys
*/
RegistryKey<Dialog> DIALOG = create("dialog");


/* ******************* *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.papermc.paper.registry.data;

import io.papermc.paper.dialog.Dialog;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.function.Consumer;
Expand All @@ -12,11 +14,13 @@
public interface InlinedRegistryBuilderProvider {

static InlinedRegistryBuilderProvider instance() {
class Holder {
final class Holder {
static final Optional<InlinedRegistryBuilderProvider> INSTANCE = ServiceLoader.load(InlinedRegistryBuilderProvider.class).findFirst();
}
return Holder.INSTANCE.orElseThrow();
}

MusicInstrument createInstrument(Consumer<RegistryBuilderFactory<MusicInstrument, ? extends InstrumentRegistryEntry.Builder>> value);

Dialog createDialog(Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value);
}
Loading
Loading