Skip to content

Commit 4dc3e95

Browse files
committed
rename methods
1 parent 814f7ce commit 4dc3e95

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public sealed interface DialogBody permits DialogBody.ItemBody, DialogBody.PlainMessageBody {
88

9-
static ItemBody itemBody(
9+
static ItemBody item(
1010
final ItemStack item,
1111
final @Nullable PlainMessageBody description,
1212
final boolean showDecorations,
@@ -17,7 +17,7 @@ static ItemBody itemBody(
1717
return new ItemBodyImpl(item, description, showDecorations, showTooltip, width, height);
1818
}
1919

20-
static PlainMessageBody plainMessageBody(final Component contents, final int width) {
20+
static PlainMessageBody plainMessage(final Component contents, final int width) {
2121
return new PlainMessageBodyImpl(contents, width);
2222
}
2323

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
public sealed interface DialogInputType permits BooleanDialogInputType, NumberRangeDialogInputType, SingleOptionDialogInputType, TextDialogInputType {
88

9-
static BooleanDialogInputType booleanInputType(final Component label, final boolean initial, final String onTrue, final String onFalse) {
9+
static BooleanDialogInputType bool(final Component label, final boolean initial, final String onTrue, final String onFalse) {
1010
return new BooleanDialogInputTypeImpl(label, initial, onTrue, onFalse);
1111
}
1212

13-
static NumberRangeDialogInputType numberRangeInputType(final int width, final Component label, final String labelFormat, final float start, final float end, final @Nullable Float initial, final @Nullable Float step) {
13+
static NumberRangeDialogInputType numberRange(final int width, final Component label, final String labelFormat, final float start, final float end, final @Nullable Float initial, final @Nullable Float step) {
1414
return new NumberRangeDialogInputTypeImpl(width, label, labelFormat, start, end, initial, step);
1515
}
1616

17-
static SingleOptionDialogInputType singleOptionInputType(final int width, final List<SingleOptionDialogInputType.OptionEntry> entries, final Component label, final boolean labelVisible) {
17+
static SingleOptionDialogInputType singleOption(final int width, final List<SingleOptionDialogInputType.OptionEntry> entries, final Component label, final boolean labelVisible) {
1818
return new SingleOptionDialogInputTypeImpl(width, entries, label, labelVisible);
1919
}
2020

21-
static TextDialogInputType textInputType(final int width, final Component label, final boolean labelVisible, final String initial, final int maxLength, final TextDialogInputType.@Nullable MultilineOptions multiline) {
21+
static TextDialogInputType text(final int width, final Component label, final boolean labelVisible, final String initial, final int maxLength, final TextDialogInputType.@Nullable MultilineOptions multiline) {
2222
return new TextDialogInputTypeImpl(width, label, labelVisible, initial, maxLength, multiline);
2323
}
2424
}

paper-server/src/main/java/io/papermc/paper/registry/data/dialog/PaperDialogCodecs.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ private PaperDialogCodecs() {
7575
private static final MapCodec<DialogBody.PlainMessageBody> PLAIN_MESSAGE_BODY_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
7676
AdventureCodecs.COMPONENT_CODEC.fieldOf("contents").forGetter(DialogBody.PlainMessageBody::contents),
7777
Dialog.WIDTH_CODEC.optionalFieldOf("width", PlainMessage.DEFAULT_WIDTH).forGetter(DialogBody.PlainMessageBody::width)
78-
).apply(instance, DialogBody::plainMessageBody)
78+
).apply(instance, DialogBody::plainMessage)
7979
);
80-
private static final Codec<DialogBody.PlainMessageBody> SIMPLE_PLAIN_MESSAGE_BODY_CODEC = Codec.withAlternative(PLAIN_MESSAGE_BODY_CODEC.codec(), AdventureCodecs.COMPONENT_CODEC, component -> DialogBody.plainMessageBody(component, PlainMessage.DEFAULT_WIDTH));
80+
private static final Codec<DialogBody.PlainMessageBody> SIMPLE_PLAIN_MESSAGE_BODY_CODEC = Codec.withAlternative(PLAIN_MESSAGE_BODY_CODEC.codec(), AdventureCodecs.COMPONENT_CODEC, component -> DialogBody.plainMessage(component, PlainMessage.DEFAULT_WIDTH));
8181
private static final MapCodec<DialogBody.ItemBody> ITEM_BODY_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
8282
ItemStack.STRICT_CODEC.xmap(CraftItemStack::asBukkitCopy, CraftItemStack::asNMSCopy).fieldOf("item").forGetter(DialogBody.ItemBody::item),
8383
SIMPLE_PLAIN_MESSAGE_BODY_CODEC.optionalFieldOf("description").forGetter(body -> Optional.ofNullable(body.description())),
8484
Codec.BOOL.optionalFieldOf("show_decorations", true).forGetter(DialogBody.ItemBody::showDecorations),
8585
Codec.BOOL.optionalFieldOf("show_tooltip", true).forGetter(DialogBody.ItemBody::showTooltip),
8686
Dialog.WIDTH_CODEC.optionalFieldOf("width", 16).forGetter(DialogBody.ItemBody::width),
8787
Dialog.WIDTH_CODEC.optionalFieldOf("height", 16).forGetter(DialogBody.ItemBody::height)
88-
).apply(instance, (itemStack, plainMessageBody, showDecorations, showTooltip, width, height) -> DialogBody.itemBody(itemStack, plainMessageBody.orElse(null), showDecorations, showTooltip, width, height))
88+
).apply(instance, (itemStack, plainMessageBody, showDecorations, showTooltip, width, height) -> DialogBody.item(itemStack, plainMessageBody.orElse(null), showDecorations, showTooltip, width, height))
8989
);
9090
private static final Registry<MapCodec<? extends DialogBody>> DIALOG_BODY_TYPES = Util.make(() -> {
9191
final MappedRegistry<MapCodec<? extends DialogBody>> registry = new MappedRegistry<>(ResourceKey.createRegistryKey(ResourceLocation.fromNamespaceAndPath(ResourceLocation.PAPER_NAMESPACE, "dialog_body_type")), Lifecycle.experimental());
@@ -106,7 +106,7 @@ private PaperDialogCodecs() {
106106
Codec.BOOL.optionalFieldOf("initial", false).forGetter(BooleanDialogInputType::initial),
107107
Codec.STRING.optionalFieldOf("on_true", "true").forGetter(BooleanDialogInputType::onTrue),
108108
Codec.STRING.optionalFieldOf("on_false", "false").forGetter(BooleanDialogInputType::onFalse)
109-
).apply(instance, DialogInputType::booleanInputType)
109+
).apply(instance, DialogInputType::bool)
110110
);
111111
private static final MapCodec<NumberRangeDialogInputType> NUMBER_RANGE_INPUT_MAP_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
112112
Dialog.WIDTH_CODEC.optionalFieldOf("width", PlainMessage.DEFAULT_WIDTH).forGetter(NumberRangeDialogInputType::width),
@@ -116,7 +116,7 @@ private PaperDialogCodecs() {
116116
Codec.FLOAT.fieldOf("end").forGetter(NumberRangeDialogInputType::end),
117117
Codec.FLOAT.optionalFieldOf("initial").forGetter(type -> Optional.ofNullable(type.initial())),
118118
ExtraCodecs.POSITIVE_FLOAT.optionalFieldOf("step").forGetter(type -> Optional.ofNullable(type.step()))
119-
).apply(instance, (width, label, labelFormat, start, end, initial, step) -> DialogInputType.numberRangeInputType(width, label, labelFormat, start, end, initial.orElse(null), step.orElse(null)))
119+
).apply(instance, (width, label, labelFormat, start, end, initial, step) -> DialogInputType.numberRange(width, label, labelFormat, start, end, initial.orElse(null), step.orElse(null)))
120120
);
121121
private static final Codec<SingleOptionDialogInputType.OptionEntry> SINGLE_OPTION_DIALOG_INPUT_ENTRY_FULL_CODEC = RecordCodecBuilder.create(instance -> instance.group(
122122
Codec.STRING.fieldOf("id").forGetter(SingleOptionDialogInputType.OptionEntry::id),
@@ -132,7 +132,7 @@ private PaperDialogCodecs() {
132132
ExtraCodecs.nonEmptyList(SINGLE_OPTION_DIALOG_INPUT_ENTRY_CODEC.listOf()).fieldOf("options").forGetter(SingleOptionDialogInputType::entries),
133133
AdventureCodecs.COMPONENT_CODEC.fieldOf("label").forGetter(SingleOptionDialogInputType::label),
134134
Codec.BOOL.optionalFieldOf("label_visible", true).forGetter(SingleOptionDialogInputType::labelVisible)
135-
).apply(instance, DialogInputType::singleOptionInputType)
135+
).apply(instance, DialogInputType::singleOption)
136136
);
137137
private static final Codec<TextDialogInputType.MultilineOptions> TEXT_DIALOG_INPUT_MULTILINE_OPTIONS_CODEC = RecordCodecBuilder.create(instance -> instance.group(
138138
ExtraCodecs.POSITIVE_INT.optionalFieldOf("max_lines").forGetter(options -> Optional.ofNullable(options.maxLines())),
@@ -147,7 +147,7 @@ private PaperDialogCodecs() {
147147
ExtraCodecs.POSITIVE_INT.optionalFieldOf("max_length", 32).forGetter(TextDialogInputType::maxLength),
148148
TEXT_DIALOG_INPUT_MULTILINE_OPTIONS_CODEC.optionalFieldOf("multiline").forGetter(inputType -> Optional.ofNullable(inputType.multiline()))
149149
).apply(instance, (width, label, labelVisible, initial, maxLength, multilineOptions) ->
150-
DialogInputType.textInputType(width, label, labelVisible, initial, maxLength, multilineOptions.orElse(null))
150+
DialogInputType.text(width, label, labelVisible, initial, maxLength, multilineOptions.orElse(null))
151151
)
152152
);
153153
private static final Registry<MapCodec<? extends DialogInputType>> DIALOG_INPUT_TYPES = Util.make(() -> {

test-plugin/src/main/java/io/papermc/testplugin/TestPluginBootstrap.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
44
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
5+
import io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager;
6+
import io.papermc.paper.registry.data.dialog.ActionButton;
57
import io.papermc.paper.registry.data.dialog.DialogBase;
8+
import io.papermc.paper.registry.data.dialog.action.DialogAction;
9+
import io.papermc.paper.registry.data.dialog.body.DialogBody;
10+
import io.papermc.paper.registry.data.dialog.input.DialogInput;
11+
import io.papermc.paper.registry.data.dialog.input.type.DialogInputType;
12+
import io.papermc.paper.registry.data.dialog.specialty.DialogSpecialty;
613
import io.papermc.paper.registry.event.RegistryEvents;
714
import io.papermc.paper.registry.keys.DialogKeys;
15+
import java.util.List;
16+
import net.kyori.adventure.key.Key;
817
import net.kyori.adventure.text.format.NamedTextColor;
918
import org.jetbrains.annotations.NotNull;
1019

@@ -16,7 +25,8 @@ public class TestPluginBootstrap implements PluginBootstrap {
1625
public void bootstrap(@NotNull BootstrapContext context) {
1726
// io.papermc.testplugin.brigtests.Registration.registerViaBootstrap(context);
1827

19-
context.getLifecycleManager().registerEventHandler(RegistryEvents.DIALOG.entryAdd().newHandler(event -> {
28+
final LifecycleEventManager<BootstrapContext> manager = context.getLifecycleManager();
29+
manager.registerEventHandler(RegistryEvents.DIALOG.entryAdd().newHandler(event -> {
2030
final DialogBase oldBase = event.builder().dialogBase();
2131
event.builder().dialogBase(DialogBase.create(
2232
text("New Better Title", NamedTextColor.LIGHT_PURPLE),
@@ -28,6 +38,20 @@ public void bootstrap(@NotNull BootstrapContext context) {
2838
oldBase.inputs()
2939
));
3040
}).filter(DialogKeys.SERVER_LINKS));
41+
42+
manager.registerEventHandler(RegistryEvents.DIALOG.freeze(), event -> {
43+
event.registry().register(DialogKeys.create(Key.key("mm:test")), builder -> {
44+
final List<DialogBody> body = List.of(DialogBody.plainMessage(text("Select relative coordinates", NamedTextColor.GREEN), 100));
45+
final List<DialogInput> inputs = List.of(DialogInput.create("x", DialogInputType.numberRange(100, text("X Coordinate", NamedTextColor.YELLOW), "options.generic_value", -1000f, 1000f, 0f, 1f)),
46+
DialogInput.create("y", DialogInputType.numberRange(100, text("Y Coordinate", NamedTextColor.YELLOW), "%s: ~%s", -1000f, 1000f, 0f, 1f)),
47+
DialogInput.create("z", DialogInputType.numberRange(100, text("Z Coordinate", NamedTextColor.YELLOW), "%s: ~%s", -1000f, 1000f, 0f, 1f))
48+
);
49+
builder.dialogBase(DialogBase.create(text("Teleport somewhere COOL", NamedTextColor.YELLOW), null, true, false, DialogBase.DialogAfterAction.CLOSE, body, inputs));
50+
final ActionButton cancel = ActionButton.create(text("Cancel", NamedTextColor.RED), null, 50, null);
51+
final ActionButton teleport = ActionButton.create(text("Teleport", NamedTextColor.GREEN), null, 50, DialogAction.commandTemplate("tp ~$(x) ~$(y) ~$(z)"));
52+
builder.dialogSpecialty(DialogSpecialty.confirmation(teleport, cancel));
53+
});
54+
});
3155
}
3256

3357
}

0 commit comments

Comments
 (0)