Skip to content

Commit 11a1e0f

Browse files
committed
address review
1 parent a2f9bf3 commit 11a1e0f

40 files changed

+582
-634
lines changed

paper-api/src/main/java/io/papermc/paper/registry/data/dialog/DialogBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ static DialogBase create(
3434
final boolean pause,
3535
final DialogAfterAction afterAction,
3636
final List<? extends DialogBody> body,
37-
final List<DialogInput> inputs
37+
final List<? extends DialogInput> inputs
3838
) {
39-
return new DialogBaseImpl(title, externalTitle, canCloseWithEscape, pause, afterAction, List.copyOf(body), inputs);
39+
return new DialogBaseImpl(title, externalTitle, canCloseWithEscape, pause, afterAction, List.copyOf(body), List.copyOf(inputs));
4040
}
4141

4242
/**
@@ -195,7 +195,7 @@ sealed interface Builder permits DialogBaseImpl.BuilderImpl {
195195
* @return this builder
196196
*/
197197
@Contract(value = "_ -> this", mutates = "this")
198-
Builder inputs(List<DialogInput> inputs);
198+
Builder inputs(List<? extends DialogInput> inputs);
199199

200200
/**
201201
* Builds the dialog base.

paper-api/src/main/java/io/papermc/paper/registry/data/dialog/DialogBaseImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public BuilderImpl body(final List<? extends DialogBody> body) {
6868
}
6969

7070
@Override
71-
public BuilderImpl inputs(final List<DialogInput> inputs) {
71+
public BuilderImpl inputs(final List<? extends DialogInput> inputs) {
7272
this.inputs = List.copyOf(inputs);
7373
return this;
7474
}

paper-api/src/main/java/io/papermc/paper/registry/data/dialog/DialogRegistryEntry.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import io.papermc.paper.dialog.Dialog;
44
import io.papermc.paper.registry.RegistryBuilder;
5-
import io.papermc.paper.registry.data.dialog.specialty.DialogSpecialty;
5+
import io.papermc.paper.registry.data.dialog.type.DialogListType;
6+
import io.papermc.paper.registry.data.dialog.type.DialogType;
67
import io.papermc.paper.registry.set.RegistryValueSetBuilder;
78
import org.jetbrains.annotations.ApiStatus;
89
import org.jetbrains.annotations.Contract;
@@ -13,52 +14,62 @@
1314
@ApiStatus.NonExtendable
1415
public interface DialogRegistryEntry {
1516

17+
/**
18+
* The base dialog for this entry.
19+
*
20+
* @return the base dialog
21+
*/
1622
@Contract(pure = true)
17-
DialogBase dialogBase();
23+
DialogBase base();
1824

25+
/**
26+
* The type of dialog for this entry.
27+
*
28+
* @return the dialog type
29+
*/
1930
@Contract(pure = true)
20-
DialogSpecialty dialogSpecialty();
31+
DialogType type();
2132

2233
/**
2334
* A mutable builder for the {@link DialogRegistryEntry} plugins may change in applicable registry events.
2435
* <p>
2536
* The following values are required for each builder:
2637
* <ul>
27-
* <li>{@link #dialogBase(DialogBase)}</li>
28-
* <li>{@link #dialogSpecialty(DialogSpecialty)}</li>
38+
* <li>{@link #base(DialogBase)}</li>
39+
* <li>{@link #type(DialogType)}</li>
2940
* </ul>
3041
*/
3142
@ApiStatus.NonExtendable
3243
interface Builder extends DialogRegistryEntry, RegistryBuilder<Dialog> {
3344

3445
/**
3546
* Provides a builder for dialog {@link io.papermc.paper.registry.set.RegistryValueSet} which
36-
* can be used inside {@link io.papermc.paper.registry.data.dialog.specialty.DialogListSpecialty}.
47+
* can be used inside {@link DialogListType}.
3748
* <p>Not a part of the registry entry.</p>
3849
*
3950
* @return a new registry value set builder
4051
*/
4152
@Contract(value = "-> new", pure = true)
42-
RegistryValueSetBuilder<Dialog, DialogRegistryEntry.Builder> registryValueSetBuilder();
53+
RegistryValueSetBuilder<Dialog, DialogRegistryEntry.Builder> registryValueSet();
4354

4455
/**
4556
* Sets the base dialog for this entry.
4657
*
4758
* @param dialogBase the base dialog
4859
* @return this builder instance
49-
* @see DialogRegistryEntry#dialogBase()
60+
* @see DialogRegistryEntry#base()
5061
*/
5162
@Contract(value = "_ -> this", mutates = "this")
52-
Builder dialogBase(DialogBase dialogBase);
63+
Builder base(DialogBase dialogBase);
5364

5465
/**
5566
* Sets the specialty dialog for this entry.
5667
*
57-
* @param dialogSpecialty the specialty dialog
68+
* @param dialogType the specialty dialog
5869
* @return this builder instance
59-
* @see DialogRegistryEntry#dialogSpecialty()
70+
* @see DialogRegistryEntry#type()
6071
*/
6172
@Contract(value = "_ -> this", mutates = "this")
62-
Builder dialogSpecialty(DialogSpecialty dialogSpecialty);
73+
Builder type(DialogType dialogType);
6374
}
6475
}

paper-api/src/main/java/io/papermc/paper/registry/data/dialog/input/type/BooleanDialogInputConfig.java renamed to paper-api/src/main/java/io/papermc/paper/registry/data/dialog/input/BooleanDialogInput.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
package io.papermc.paper.registry.data.dialog.input.type;
1+
package io.papermc.paper.registry.data.dialog.input;
22

33
import net.kyori.adventure.text.Component;
44
import org.jetbrains.annotations.Contract;
55

66
/**
7-
* A boolean dialog input configuration.
8-
* <p>Created via {@link DialogInputConfig#bool(Component, boolean, String, String)}</p>
7+
* A boolean dialog input.
8+
* <p>Created via {@link DialogInput#bool(String, Component, boolean, String, String)}</p>
99
*/
10-
public sealed interface BooleanDialogInputConfig extends DialogInputConfig permits BooleanDialogInputConfigImpl {
10+
public sealed interface BooleanDialogInput extends DialogInput permits BooleanDialogInputImpl {
1111

1212
/**
1313
* The label for the input.
@@ -42,10 +42,10 @@ public sealed interface BooleanDialogInputConfig extends DialogInputConfig permi
4242
String onFalse();
4343

4444
/**
45-
* A builder for a boolean dialog input configuration.
46-
* <p>Created via {@link DialogInputConfig#bool(Component)}</p>
45+
* A builder for a boolean dialog input.
46+
* <p>Created via {@link DialogInput#bool(String, Component)}</p>
4747
*/
48-
sealed interface Builder permits BooleanDialogInputConfigImpl.BuilderImpl {
48+
sealed interface Builder permits BooleanDialogInputImpl.BuilderImpl {
4949

5050
/**
5151
* Sets the initial value of the input.
@@ -80,6 +80,6 @@ sealed interface Builder permits BooleanDialogInputConfigImpl.BuilderImpl {
8080
* @return a new instance
8181
*/
8282
@Contract(value = "-> new", pure = true)
83-
BooleanDialogInputConfig build();
83+
BooleanDialogInput build();
8484
}
8585
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.papermc.paper.registry.data.dialog.input;
2+
3+
import net.kyori.adventure.text.Component;
4+
5+
record BooleanDialogInputImpl(String key, Component label, boolean initial, String onTrue, String onFalse) implements BooleanDialogInput {
6+
7+
static final class BuilderImpl implements BooleanDialogInput.Builder {
8+
9+
private final String key;
10+
private final Component label;
11+
private boolean initial = false;
12+
private String onTrue = "true";
13+
private String onFalse = "false";
14+
15+
BuilderImpl(final String key, final Component label) {
16+
this.key = key;
17+
this.label = label;
18+
}
19+
20+
@Override
21+
public BooleanDialogInput.Builder initial(final boolean initial) {
22+
this.initial = initial;
23+
return this;
24+
}
25+
26+
@Override
27+
public BooleanDialogInput.Builder onTrue(final String onTrue) {
28+
this.onTrue = onTrue;
29+
return this;
30+
}
31+
32+
@Override
33+
public BooleanDialogInput.Builder onFalse(final String onFalse) {
34+
this.onFalse = onFalse;
35+
return this;
36+
}
37+
38+
@Override
39+
public BooleanDialogInput build() {
40+
return new BooleanDialogInputImpl(this.key, this.label, this.initial, this.onTrue, this.onFalse);
41+
}
42+
}
43+
}
Lines changed: 116 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,137 @@
11
package io.papermc.paper.registry.data.dialog.input;
22

3-
import io.papermc.paper.registry.data.dialog.input.type.DialogInputConfig;
3+
import java.util.List;
4+
import net.kyori.adventure.text.Component;
45
import org.jetbrains.annotations.Contract;
6+
import org.jspecify.annotations.Nullable;
57

68
/**
7-
* Represents a configured input for a dialog.
9+
* Represents an input for dialog.
810
*/
9-
public sealed interface DialogInput permits DialogInputImpl {
11+
public sealed interface DialogInput permits BooleanDialogInput, NumberRangeDialogInput, SingleOptionDialogInput, TextDialogInput {
1012

1113
/**
12-
* Creates a new dialog input with the specified key and input type.
14+
* Creates a boolean dialog input.
1315
*
14-
* @param key the key for this input
15-
* @param inputType the type of this input
16-
* @return a new dialog input instance
16+
* @param key the key identifier for the input
17+
* @param label the label for the input
18+
* @param initial the initial value of the input
19+
* @param onTrue the input's value in a template when the value is true
20+
* @param onFalse the input's value in a template when the value is false
21+
* @return a new boolean dialog input instance
22+
*/
23+
@Contract(pure = true, value = "_, _, _, _, _ -> new")
24+
static BooleanDialogInput bool(final String key, final Component label, final boolean initial, final String onTrue, final String onFalse) {
25+
return new BooleanDialogInputImpl(key, label, initial, onTrue, onFalse);
26+
}
27+
28+
/**
29+
* Creates a new builder for a boolean dialog input.
30+
*
31+
* @param key the key identifier for the input
32+
* @param label the label for the input
33+
* @return a new builder instance
1734
*/
1835
@Contract(pure = true, value = "_, _ -> new")
19-
static DialogInput create(final String key, final DialogInputConfig inputType) {
20-
return new DialogInputImpl(key, inputType);
36+
static BooleanDialogInput.Builder bool(final String key, final Component label) {
37+
return new BooleanDialogInputImpl.BuilderImpl(key, label);
2138
}
2239

2340
/**
24-
* The key for this input.
25-
* <p>Used in dialog actions to identify this dialog input's value</p>
41+
* Creates a number range dialog input.
2642
*
27-
* @return the key of this input
43+
* @param key the key identifier for the input
44+
* @param width the width of the input
45+
* @param label the label for the input
46+
* @param labelFormat the format for the label (a translation key or format string)
47+
* @param start the start of the range
48+
* @param end the end of the range
49+
* @param initial the initial value, or null if not set
50+
* @param step the step size, or null if not set
51+
* @return a new number range dialog input instance
2852
*/
29-
@Contract(pure = true)
30-
String key();
53+
@Contract(pure = true, value = "_, _, _, _, _, _, _, _ -> new")
54+
static NumberRangeDialogInput numberRange(final String key, final int width, final Component label, final String labelFormat, final float start, final float end, final @Nullable Float initial, final @Nullable Float step) {
55+
return new NumberRangeDialogInputImpl(key, width, label, labelFormat, start, end, initial, step);
56+
}
57+
58+
/**
59+
* Creates a new builder for a number range dialog input.
60+
*
61+
* @param key the key identifier for the input
62+
* @param label the label for the input
63+
* @param start the start of the range
64+
* @param end the end of the range
65+
* @return a new builder instance
66+
*/
67+
@Contract(value = "_, _, _, _ -> new", pure = true)
68+
static NumberRangeDialogInput.Builder numberRange(final String key, final Component label, final float start, final float end) {
69+
return new NumberRangeDialogInputImpl.BuilderImpl(key, label, start, end);
70+
}
71+
72+
/**
73+
* Creates a single option dialog input (radio input).
74+
*
75+
* @param key the key identifier for the input
76+
* @param width the width of the input
77+
* @param entries the list of options for the input
78+
* @param label the label for the input
79+
* @param labelVisible whether the label should be visible
80+
* @return a new single option dialog input instance
81+
*/
82+
@Contract(pure = true, value = "_, _, _, _, _ -> new")
83+
static SingleOptionDialogInput singleOption(final String key, final int width, final List<SingleOptionDialogInput.OptionEntry> entries, final Component label, final boolean labelVisible) {
84+
return new SingleOptionDialogInputImpl(key, width, entries, label, labelVisible);
85+
}
3186

3287
/**
33-
* The type of this input.
34-
* <p>Used to determine how the input should be rendered and processed</p>
88+
* Creates a new builder for a single option dialog input.
3589
*
36-
* @return the type of this input
90+
* @param key the key identifier for the input
91+
* @param label the label for the input
92+
* @param entries the list of options for the input
93+
* @return a new builder instance
3794
*/
38-
@Contract(pure = true)
39-
DialogInputConfig inputType();
95+
@Contract(value = "_, _, _ -> new", pure = true)
96+
static SingleOptionDialogInput.Builder singleOption(final String key, final Component label, final List<SingleOptionDialogInput.OptionEntry> entries) {
97+
return new SingleOptionDialogInputImpl.BuilderImpl(key, entries, label);
98+
}
99+
100+
/**
101+
* Creates a text dialog input.
102+
*
103+
* @param key the key identifier for the input
104+
* @param width the width of the input
105+
* @param label the label for the input
106+
* @param labelVisible whether the label should be visible
107+
* @param initial the initial value of the input
108+
* @param maxLength the maximum length of the input
109+
* @param multilineOptions the multiline options
110+
* @return a new text dialog input instance
111+
*/
112+
@Contract(pure = true, value = "_, _, _, _, _, _, _ -> new")
113+
static TextDialogInput text(final String key, final int width, final Component label, final boolean labelVisible, final String initial, final int maxLength, final TextDialogInput.@Nullable MultilineOptions multilineOptions) {
114+
return new TextDialogInputImpl(key, width, label, labelVisible, initial, maxLength, multilineOptions);
115+
}
116+
117+
/**
118+
* Creates a new builder for a text dialog input.
119+
*
120+
* @param key the key identifier for the input
121+
* @param label the label for the input
122+
* @return a new builder instance
123+
*/
124+
@Contract(value = "_, _ -> new", pure = true)
125+
static TextDialogInput.Builder text(final String key, final Component label) {
126+
return new TextDialogInputImpl.BuilderImpl(key, label);
127+
}
128+
129+
/**
130+
* Gets the key for this input.
131+
* <p>Used in dialog actions to identify this dialog input's value</p>
132+
*
133+
* @return the key
134+
*/
135+
@Contract(pure = true, value = " -> new")
136+
String key();
40137
}

paper-api/src/main/java/io/papermc/paper/registry/data/dialog/input/DialogInputImpl.java

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.papermc.paper.registry.data.dialog.input;
2+
3+
import org.jspecify.annotations.Nullable;
4+
5+
record MultilineOptionsImpl(@Nullable Integer maxLines, @Nullable Integer height) implements TextDialogInput.MultilineOptions {
6+
}

0 commit comments

Comments
 (0)