Skip to content

Commit 9bdcbdb

Browse files
committed
Dialog registry API
1 parent 4e1a255 commit 9bdcbdb

File tree

114 files changed

+3497
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+3497
-170
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package io.papermc.paper.registry.keys;
2+
3+
import static net.kyori.adventure.key.Key.key;
4+
5+
import io.papermc.paper.dialog.Dialog;
6+
import io.papermc.paper.generated.GeneratedFrom;
7+
import io.papermc.paper.registry.RegistryKey;
8+
import io.papermc.paper.registry.TypedKey;
9+
import net.kyori.adventure.key.Key;
10+
import org.jspecify.annotations.NullMarked;
11+
12+
/**
13+
* Vanilla keys for {@link RegistryKey#DIALOG}.
14+
*
15+
* @apiNote The fields provided here are a direct representation of
16+
* what is available from the vanilla game source. They may be
17+
* changed (including removals) on any Minecraft version
18+
* bump, so cross-version compatibility is not provided on the
19+
* same level as it is on most of the other API.
20+
*/
21+
@SuppressWarnings({
22+
"unused",
23+
"SpellCheckingInspection"
24+
})
25+
@NullMarked
26+
@GeneratedFrom("1.21.6")
27+
public final class DialogKeys {
28+
/**
29+
* {@code minecraft:custom_options}
30+
*
31+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
32+
*/
33+
public static final TypedKey<Dialog> CUSTOM_OPTIONS = create(key("custom_options"));
34+
35+
/**
36+
* {@code minecraft:quick_actions}
37+
*
38+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
39+
*/
40+
public static final TypedKey<Dialog> QUICK_ACTIONS = create(key("quick_actions"));
41+
42+
/**
43+
* {@code minecraft:server_links}
44+
*
45+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
46+
*/
47+
public static final TypedKey<Dialog> SERVER_LINKS = create(key("server_links"));
48+
49+
private DialogKeys() {
50+
}
51+
52+
/**
53+
* Creates a typed key for {@link Dialog} in the registry {@code minecraft:dialog}.
54+
*
55+
* @param key the value's key in the registry
56+
* @return a new typed key
57+
*/
58+
public static TypedKey<Dialog> create(final Key key) {
59+
return TypedKey.create(RegistryKey.DIALOG, key);
60+
}
61+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.papermc.paper.registry.keys.tags;
2+
3+
import static net.kyori.adventure.key.Key.key;
4+
5+
import io.papermc.paper.dialog.Dialog;
6+
import io.papermc.paper.generated.GeneratedFrom;
7+
import io.papermc.paper.registry.RegistryKey;
8+
import io.papermc.paper.registry.tag.TagKey;
9+
import net.kyori.adventure.key.Key;
10+
import org.jetbrains.annotations.ApiStatus;
11+
import org.jspecify.annotations.NullMarked;
12+
13+
/**
14+
* Vanilla tag keys for {@link RegistryKey#DIALOG}.
15+
*
16+
* @apiNote The fields provided here are a direct representation of
17+
* what is available from the vanilla game source. They may be
18+
* changed (including removals) on any Minecraft version
19+
* bump, so cross-version compatibility is not provided on the
20+
* same level as it is on most of the other API.
21+
*/
22+
@SuppressWarnings({
23+
"unused",
24+
"SpellCheckingInspection"
25+
})
26+
@NullMarked
27+
@GeneratedFrom("1.21.6")
28+
@ApiStatus.Experimental
29+
public final class DialogTagKeys {
30+
/**
31+
* {@code #minecraft:pause_screen_additions}
32+
*
33+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
34+
*/
35+
public static final TagKey<Dialog> PAUSE_SCREEN_ADDITIONS = create(key("pause_screen_additions"));
36+
37+
/**
38+
* {@code #minecraft:quick_actions}
39+
*
40+
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
41+
*/
42+
public static final TagKey<Dialog> QUICK_ACTIONS = create(key("quick_actions"));
43+
44+
private DialogTagKeys() {
45+
}
46+
47+
/**
48+
* Creates a tag key for {@link Dialog} in the registry {@code minecraft:dialog}.
49+
*
50+
* @param key the tag key's key
51+
* @return a new tag key
52+
*/
53+
@ApiStatus.Experimental
54+
public static TagKey<Dialog> create(final Key key) {
55+
return TagKey.create(RegistryKey.DIALOG, key);
56+
}
57+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.papermc.paper.dialog;
2+
3+
import io.papermc.paper.registry.RegistryAccess;
4+
import io.papermc.paper.registry.RegistryBuilderFactory;
5+
import io.papermc.paper.registry.RegistryKey;
6+
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
7+
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
8+
import java.util.function.Consumer;
9+
import net.kyori.adventure.dialog.DialogLike;
10+
import net.kyori.adventure.key.Key;
11+
import net.kyori.adventure.key.KeyPattern;
12+
import org.bukkit.Keyed;
13+
import org.bukkit.Registry;
14+
import org.jetbrains.annotations.ApiStatus;
15+
16+
/**
17+
* Represents a dialog. Can be created during normal server operation via {@link #create(Consumer)}.
18+
* Can also be created during bootstrap via {@link io.papermc.paper.registry.event.RegistryEvents#DIALOG}.
19+
*/
20+
@ApiStatus.NonExtendable
21+
public interface Dialog extends Keyed, DialogLike {
22+
23+
/**
24+
* Creates a new dialog using the provided builder.
25+
*
26+
* @param value the builder to use for creating the dialog
27+
* @return a new dialog instance
28+
*/
29+
@ApiStatus.Experimental
30+
static Dialog create(final Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value) {
31+
return InlinedRegistryBuilderProvider.instance().createDialog(value);
32+
}
33+
34+
// Start generate - Dialog
35+
// @GeneratedFrom 1.21.6
36+
Dialog CUSTOM_OPTIONS = getDialog("custom_options");
37+
38+
Dialog QUICK_ACTIONS = getDialog("quick_actions");
39+
40+
Dialog SERVER_LINKS = getDialog("server_links");
41+
// End generate - Dialog
42+
43+
private static Dialog getDialog(@KeyPattern.Value final String value) {
44+
final Registry<Dialog> registry = RegistryAccess.registryAccess().getRegistry(RegistryKey.DIALOG);
45+
return registry.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, value));
46+
}
47+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.papermc.paper.dialog;
2+
3+
import net.kyori.adventure.nbt.api.BinaryTagHolder;
4+
import org.jetbrains.annotations.ApiStatus;
5+
import org.jetbrains.annotations.Contract;
6+
import org.jspecify.annotations.Nullable;
7+
8+
/**
9+
* A view for a possible response to a dialog.
10+
* There are no guarantees that this is an actual response to a
11+
* dialog form. It is on the plugin to validate that the response
12+
* is valid.
13+
*/
14+
@ApiStatus.Experimental
15+
@ApiStatus.NonExtendable
16+
public interface DialogResponseView {
17+
18+
/**
19+
* Gets the raw payload of the response.
20+
*
21+
* @return the raw payload
22+
*/
23+
@Contract(pure = true)
24+
BinaryTagHolder payload();
25+
26+
/**
27+
* Gets a text value at a key.
28+
*
29+
* @param key the key
30+
* @return the value (or null if it doesn't exist)
31+
*/
32+
@Contract(pure = true)
33+
@Nullable String getText(String key);
34+
35+
/**
36+
* Gets a boolean value at a key.
37+
*
38+
* @param key the key
39+
* @return the value (or null if it doesn't exist)
40+
*/
41+
@Contract(pure = true)
42+
@Nullable Boolean getBoolean(String key);
43+
44+
/**
45+
* Gets a float value at a key.
46+
*
47+
* @param key the key
48+
* @return the value (or null if it doesn't exist)
49+
*/
50+
@Contract(pure = true)
51+
@Nullable Float getFloat(String key);
52+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This package contains classes and interfaces related to the dialog system in Paper.
3+
*/
4+
@NullMarked
5+
package io.papermc.paper.dialog;
6+
7+
import org.jspecify.annotations.NullMarked;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.papermc.paper.event.player;
2+
3+
import io.papermc.paper.dialog.DialogResponseView;
4+
import io.papermc.paper.registry.data.dialog.action.DialogActionCallback;
5+
import net.kyori.adventure.key.Key;
6+
import net.kyori.adventure.nbt.api.BinaryTagHolder;
7+
import net.kyori.adventure.text.event.ClickCallback;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.event.Event;
10+
import org.bukkit.event.HandlerList;
11+
import org.jetbrains.annotations.ApiStatus;
12+
import org.jspecify.annotations.NullMarked;
13+
import org.jspecify.annotations.Nullable;
14+
15+
/**
16+
* This event is fired for any custom click events.
17+
* @see net.kyori.adventure.text.event.ClickEvent#custom(Key, BinaryTagHolder)
18+
* @see io.papermc.paper.registry.data.dialog.action.DialogAction#customClick(Key, DialogActionCallback, ClickCallback.Options)
19+
*/
20+
@ApiStatus.Experimental
21+
@ApiStatus.NonExtendable
22+
@NullMarked
23+
public abstract class PlayerCustomClickEvent extends Event {
24+
25+
private final Key identifier;
26+
private final Player player;
27+
28+
@ApiStatus.Internal
29+
protected PlayerCustomClickEvent(final Key identifier, final Player player) {
30+
this.identifier = identifier;
31+
this.player = player;
32+
}
33+
34+
/**
35+
* The identifier of the custom click event.
36+
*
37+
* @return the identifier
38+
*/
39+
public final Key getIdentifier() {
40+
return this.identifier;
41+
}
42+
43+
/**
44+
* The tag payload of the custom click event.
45+
*
46+
* @return the tag (if any)
47+
*/
48+
public abstract @Nullable BinaryTagHolder getTag();
49+
50+
/**
51+
* The dialog response view of the custom click event.
52+
*
53+
* @return the dialog response view
54+
*/
55+
public abstract @Nullable DialogResponseView getDialogResponseView();
56+
57+
public Player getPlayer() {
58+
return this.player;
59+
}
60+
61+
@Override
62+
public HandlerList getHandlers() {
63+
// this will be how handler lists will work on interfaces
64+
return PlayerCustomClickEvent.getHandlerList();
65+
}
66+
67+
public static HandlerList getHandlerList() {
68+
final class Holder {
69+
private static final HandlerList HANDLER_LIST = new HandlerList();
70+
}
71+
return Holder.HANDLER_LIST;
72+
}
73+
}

paper-api/src/main/java/io/papermc/paper/registry/RegistryKey.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.papermc.paper.registry;
22

33
import io.papermc.paper.datacomponent.DataComponentType;
4+
import io.papermc.paper.dialog.Dialog;
45
import io.papermc.paper.registry.tag.TagKey;
56
import net.kyori.adventure.key.Key;
67
import net.kyori.adventure.key.KeyPattern;
@@ -216,7 +217,11 @@ public sealed interface RegistryKey<T> extends Keyed permits RegistryKeyImpl {
216217
* @see io.papermc.paper.registry.keys.PigVariantKeys
217218
*/
218219
RegistryKey<Pig.Variant> PIG_VARIANT = create("pig_variant");
219-
220+
/**
221+
* Data-driven registry for dialogs.
222+
* @see io.papermc.paper.registry.keys.DialogKeys
223+
*/
224+
RegistryKey<Dialog> DIALOG = create("dialog");
220225

221226

222227
/* ******************* *
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
package io.papermc.paper.registry.data;
22

3+
import io.papermc.paper.dialog.Dialog;
34
import io.papermc.paper.registry.RegistryBuilderFactory;
5+
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
46
import java.util.Optional;
57
import java.util.ServiceLoader;
68
import java.util.function.Consumer;
7-
import org.bukkit.Art;
89
import org.jetbrains.annotations.ApiStatus;
910

1011
@ApiStatus.Internal
1112
@ApiStatus.NonExtendable
1213
public interface InlinedRegistryBuilderProvider {
1314

1415
static InlinedRegistryBuilderProvider instance() {
15-
class Holder {
16+
final class Holder {
1617
static final Optional<InlinedRegistryBuilderProvider> INSTANCE = ServiceLoader.load(InlinedRegistryBuilderProvider.class).findFirst();
1718
}
1819
return Holder.INSTANCE.orElseThrow();
1920
}
2021

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

0 commit comments

Comments
 (0)