Skip to content

Commit 93c2a05

Browse files
committed
Dialog registry API
1 parent 6fddc93 commit 93c2a05

File tree

62 files changed

+1317
-23
lines changed

Some content is hidden

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

62 files changed

+1317
-23
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-pre3")
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-pre3")
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.papermc.paper.dialog;
2+
3+
import io.papermc.paper.registry.RegistryBuilderFactory;
4+
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
5+
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
6+
import java.util.function.Consumer;
7+
import org.bukkit.Keyed;
8+
import org.jetbrains.annotations.ApiStatus;
9+
10+
@ApiStatus.NonExtendable
11+
public interface Dialog extends Keyed {
12+
13+
@ApiStatus.Experimental
14+
static Dialog create(final Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value) {
15+
return InlinedRegistryBuilderProvider.instance().createDialog(value);
16+
}
17+
}
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;

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

Lines changed: 6 additions & 0 deletions
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;
@@ -219,6 +220,11 @@ public sealed interface RegistryKey<T> extends Keyed permits RegistryKeyImpl {
219220
*/
220221
RegistryKey<Pig.Variant> PIG_VARIANT = create("pig_variant");
221222

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

223229

224230
/* ******************* *
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
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.papermc.paper.registry.data.dialog;
2+
3+
import io.papermc.paper.registry.data.dialog.action.DialogAction;
4+
import net.kyori.adventure.text.Component;
5+
import org.jspecify.annotations.Nullable;
6+
7+
public sealed interface ActionButton permits ActionButtonImpl {
8+
9+
static ActionButton create(final Component label, final @Nullable Component tooltip, final int width, final @Nullable DialogAction action) {
10+
return new ActionButtonImpl(label, tooltip, width, action);
11+
}
12+
13+
Component label();
14+
15+
@Nullable Component tooltip();
16+
17+
int width();
18+
19+
@Nullable DialogAction action();
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.papermc.paper.registry.data.dialog;
2+
3+
import io.papermc.paper.registry.data.dialog.action.DialogAction;
4+
import net.kyori.adventure.text.Component;
5+
import org.jspecify.annotations.Nullable;
6+
7+
record ActionButtonImpl(Component label, @Nullable Component tooltip, int width, @Nullable DialogAction action) implements ActionButton {
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package io.papermc.paper.registry.data.dialog;
2+
3+
import io.papermc.paper.registry.data.dialog.body.DialogBody;
4+
import io.papermc.paper.registry.data.dialog.input.DialogInput;
5+
import java.util.List;
6+
import net.kyori.adventure.text.Component;
7+
import net.kyori.adventure.util.Index;
8+
import org.jetbrains.annotations.Unmodifiable;
9+
import org.jspecify.annotations.Nullable;
10+
11+
public sealed interface DialogBase permits DialogBaseImpl {
12+
13+
static DialogBase create(
14+
final Component title,
15+
final @Nullable Component externalTitle,
16+
final boolean canCloseWithEscape,
17+
final boolean pause,
18+
final DialogAfterAction afterAction,
19+
final List<DialogBody> body,
20+
final List<DialogInput> inputs
21+
) {
22+
return new DialogBaseImpl(title, externalTitle, canCloseWithEscape, pause, afterAction, body, inputs);
23+
}
24+
25+
Component title();
26+
27+
@Nullable
28+
Component externalTitle();
29+
30+
boolean canCloseWithEscape();
31+
32+
boolean pause();
33+
34+
DialogAfterAction afterAction();
35+
36+
@Unmodifiable List<DialogBody> body();
37+
38+
@Unmodifiable List<DialogInput> inputs();
39+
40+
enum DialogAfterAction {
41+
CLOSE("close"), NONE("none"), WAIT_FOR_RESPONSE("wait_for_response");
42+
43+
public static final Index<String, DialogAfterAction> NAMES = Index.create(DialogAfterAction.class, DialogAfterAction::name);
44+
45+
private final String name;
46+
47+
DialogAfterAction(final String name) {
48+
this.name = name;
49+
}
50+
}
51+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.papermc.paper.registry.data.dialog;
2+
3+
import io.papermc.paper.registry.data.dialog.body.DialogBody;
4+
import io.papermc.paper.registry.data.dialog.input.DialogInput;
5+
import java.util.List;
6+
import net.kyori.adventure.text.Component;
7+
import org.jetbrains.annotations.Unmodifiable;
8+
import org.jspecify.annotations.Nullable;
9+
10+
record DialogBaseImpl(
11+
Component title,
12+
@Nullable Component externalTitle,
13+
boolean canCloseWithEscape,
14+
boolean pause,
15+
DialogAfterAction afterAction,
16+
@Unmodifiable List<DialogBody> body,
17+
@Unmodifiable List<DialogInput> inputs
18+
) implements DialogBase {
19+
20+
DialogBaseImpl {
21+
body = List.copyOf(body);
22+
inputs = List.copyOf(inputs);
23+
}
24+
}

0 commit comments

Comments
 (0)