Overview
Dialog Kit is a thin wrapper of Paper API’s Dialog API. Dialog Kit provides an object oriented design and access state around the Dialog API that is much more friendly and structured towards dialog construction.
The library is arranged around a DialogScreen, which “compiles” down into a Dialog object. Note: this API is only usable after bootstrap.
Usage
Requires Paper 26.3 or later and Java 25 or later. DialogKit is published to my personal repository and only requires paper.
Gradle
repositories {
maven("https://maven.miles.sh/snapshots")
}
dependencies {
implementation("sh.miles.dialogkit:dialogkit:1.0.0-SNAPSHOT")
}
Building with DialogKit
To show what it’s like to build with DialogKit let’s build a small warp plugin some Dialog’s
Elements
Elements are clickable buttons in the dialog. The most common kind of element you’ll probably use most often, so let’s make one that runs an action for us.
// we extend CustomElement, within DialogKit you build off of abstract
// classes like this
public final class RunElement extends CustomElement {
private final Consumer<Player> action;
public RunElement(Component text, Component tooltip, Consumer<Player> action) {
this.action = action;
setText(text);
setTooltip(tooltip);
// custom elements automatically have a 5 minute lifetime and one use only.
// setLifetime(Duration) useful for long living dialogs
// this can be customized but ultimately is a design restriction from adventure
}
// this is the core logic of our custom element
@Override
public void accept(DialogResponseView response, Audience audience) {
action.accept(assertPlayer(audience));
}
}
Now let’s scaffold out a basic close button we can re-use
// we extend ButtonElement which has no action
public final class CloseElement extends ButtonElement {
public CloseElement(Component text) {
setText(text);
}
@Override
protected DialogAction action() {
return null;
}
}
Screens
DialogKit has a singular DialogScreen class, which you can extend and build from. In this example we will being using a builtin extension of DialogScreen from sh.miles.dialogkit.builtin.dialogs.
As of 1.0.0 DialogKit only by default contains ConfirmationDialog and NavigableDialogScreen. In our example we will, and in practice you likely will too, mostly use NavigableDialogScreen.
NavigableDialogScreen has a built in close callback that can be set as well as a status component, which adds text to the top of dialog best used for tracking errors and re-opening.
Now let’s create our warp menu dialog:
public final class WarpMenuDialog extends NavigableDialogScreen {
// a good pattern to practice for DialogKit static open methods make life easy
public static void open(Player player) {
new WarpMenuDialog().show(player, null, null);
}
private WarpMenuDialog() {
// much like Java Swing or JavaFX these built in set methods make life easy
setTitle(Component.text("Warps"));
addText(ItemStack.of(Material.ENDER_PEARL), Component.text("Save a spot so others can teleport to it."));
// often in building you'll see it is also easiest to extend DialogShape's
MultiDialogShape shape = new MultiDialogShape();
shape.setColumns(2);
shape.addActions(
// Back on the form runs WarpMenuDialog::open, returning here.
new RunElement(Component.text("Create"), null,
player -> CreateWarpDialog.open(player, CreateWarpDialog.Draft.EMPTY, null, WarpMenuDialog::open)),
// this element navigates us to another dialog
new DialogElement(Component.text("Invite"), WarpDialogs.invite()),
new DialogElement(Component.text("Help"), WarpDialogs.help())
);
// NavigableDialogScreen has a built in leaveElement you can use!
shape.setExitAction(leaveElement(Component.text("Close"), null));
setShape(shape);
}
}
Next let’s move on to making our create warp dialog:
public final class CreateWarpDialog extends NavigableDialogScreen {
// Inputs reset each time a dialog is shown, so we pass what the player typed back in.
record Draft(String name, String category, boolean isPublic, int cost) {
static final Draft EMPTY = new Draft("", "spawn", true, 0);
}
public static void open(Player player, Draft draft, Component status, Consumer<Player> onClose) {
new CreateWarpDialog(draft).show(player, status, onClose);
}
private CreateWarpDialog(Draft draft) {
setTitle(Component.text("Create Warp"));
// Inputs are important for dialogs!
TextDialogField name = new TextDialogField();
// how we reference this argument in the callback
name.setKey("name");
name.setLabel(Component.text("Name"));
// any initial value we may want
name.setInitial(draft.name());
name.setMaxLength(16);
// adds the inp ut to this dialog
addInput(name);
ChoiceDialogField category = new ChoiceDialogField();
category.setKey("category");
category.setLabel(Component.text("Category"));
category.addOption("spawn", Component.text("Spawn"));
category.addOption("shop", Component.text("Shop"));
category.setInitial(draft.category());
addInput(category);
ToggleDialogField isPublic = new ToggleDialogField();
isPublic.setKey("public");
isPublic.setLabel(Component.text("Public"));
isPublic.setInitial(draft.isPublic());
addInput(isPublic);
SliderDialogField cost = new SliderDialogField();
cost.setKey("cost");
cost.setLabel(Component.text("Cost"));
cost.setRange(0, 100);
cost.setStep(5);
cost.setInitial(draft.cost());
addInput(cost);
MultiDialogShape shape = new MultiDialogShape();
shape.addAction(new Save());
shape.setExitAction(leaveElement(Component.text("Back"), null));
setShape(shape);
}
// inner private classes is a common Pattern you might find yourself doing with DialogKit
private class Save extends CustomElement {
Save() {
setText(Component.text("Save"));
}
@Override
public void accept(DialogResponseView response, Audience audience) {
// ...
// logic
Draft draft = new Draft(
// grab our values from before. Might be beneficial to make these constants
response.getText("name"),
response.getText("category"),
response.getBoolean("public"),
Math.round(response.getFloat("cost"))
);
// ...
// a good showcase of how you might want to use the ConfirmationDialog
new ConfirmationDialog(Component.text("Create Warp?"), Component.text("Create " + draft.name() + "?")) {
@Override
protected void onConfirm(Player player) {
// save the warp here
player.sendMessage(Component.text("Created " + draft.name()));
// A plain leave() here would be the confirmation's.
CreateWarpDialog.this.leave(player);
}
}.show(player, null, p -> open(p, draft, null, onClose())); // Cancel goes back to the form
}
}
}
Let’s finish this off with our last dialog the warps dialog:
// Plain DialogScreens with no server-side buttons, so they can be compiled once and opened with DialogElement.
public final class WarpDialogs {
public static Dialog help() {
DialogScreen screen = new DialogScreen();
screen.setTitle(Component.text("Warp Help"));
screen.addText(Component.text("Warps are saved spots anyone can teleport to."), 200);
MultiDialogShape shape = new MultiDialogShape();
shape.setColumns(1);
shape.addActions(
new CommandElement(Component.text("Back to menu"), "/warps"),
new SuggestCommandElement(Component.text("Ask an admin..."), "/msg "),
new UrlElement(Component.text("Open the wiki"), "https://example.com/wiki/warps")
);
shape.setExitAction(new CloseElement(Component.text("Done")));
screen.setShape(shape);
return screen.compile();
}
public static Dialog invite() {
DialogScreen screen = new DialogScreen();
screen.setTitle(Component.text("Invite a Player"));
TextDialogField target = new TextDialogField();
target.setKey("target");
target.setLabel(Component.text("Player"));
screen.addInput(target);
// onTrue/onFalse are what $(urgent) becomes in the template.
ToggleDialogField urgent = new ToggleDialogField();
urgent.setKey("urgent");
urgent.setLabel(Component.text("Urgent"));
urgent.setOnTrue("right now!");
urgent.setOnFalse("when you can.");
screen.addInput(urgent);
BinaryDialogShape shape = new BinaryDialogShape();
shape.setOptionOne(new CommandTemplateElement(Component.text("Send"),
"/msg $(target) Come check out my warps $(urgent)"));
shape.setOptionTwo(new CloseElement(Component.text("Cancel")));
screen.setShape(shape);
return screen.compile();
}
}
Now let’s admire what we built with DialogKit

Side By Side
To give you an honest look of how the organization can differ here is a respectful implementation of the same design in Paper’s API
Paper Dialog API
public final class PaperWarpDialogs {
record Draft(String name, String category, boolean isPublic, int cost) {
static final Draft EMPTY = new Draft("", "spawn", true, 0);
}
private static final ClickCallback.Options ONCE = ClickCallback.Options.builder()
.uses(1)
.lifetime(Duration.ofMinutes(5))
.build();
private static ActionButton button(Component text, Consumer<Player> onClick) {
return ActionButton.builder(text)
.action(DialogAction.customClick((DialogResponseView response, Audience audience) -> {
if (audience instanceof Player player) {
onClick.accept(player);
}
}, ONCE))
.build();
}
private static ActionButton button(Component text, BiConsumer<Player, DialogResponseView> onClick) {
return ActionButton.builder(text)
.action(DialogAction.customClick((DialogResponseView response, Audience audience) -> {
if (audience instanceof Player player) {
onClick.accept(player, response);
}
}, ONCE))
.build();
}
private static void leave(Player player, Consumer<Player> onClose) {
if (onClose == null) {
player.closeDialog();
} else {
onClose.accept(player);
}
}
private static DialogBase.Builder navigableBase(Component title, Component status, List<DialogBody> body) {
List<DialogBody> withStatus = new ArrayList<>();
if (status != null) {
withStatus.add(DialogBody.plainMessage(status));
}
withStatus.addAll(body);
return DialogBase.builder(title)
.pause(false)
.canCloseWithEscape(false)
.afterAction(DialogBase.DialogAfterAction.NONE)
.body(withStatus);
}
public static void openMenu(Player player) {
Dialog dialog = Dialog.create(factory -> factory.empty()
.base(navigableBase(Component.text("Warps"), null, List.of(
DialogBody.item(ItemStack.of(Material.ENDER_PEARL))
.description(DialogBody.plainMessage(Component.text("Save a spot so others can teleport to it.")))
.build()
)).build())
.type(DialogType.multiAction(List.of(
button(Component.text("Create"),
p -> openCreate(p, Draft.EMPTY, null, PaperWarpDialogs::openMenu)),
ActionButton.builder(Component.text("Invite"))
.action(DialogAction.staticAction(ClickEvent.showDialog(invite())))
.build(),
ActionButton.builder(Component.text("Help"))
.action(DialogAction.staticAction(ClickEvent.showDialog(help())))
.build()
))
.columns(2)
.exitAction(button(Component.text("Close"), p -> leave(p, null)))
.build())
);
player.showDialog(dialog);
}
public static void openCreate(Player player, Draft draft, Component status, Consumer<Player> onClose) {
Dialog dialog = Dialog.create(factory -> factory.empty()
.base(navigableBase(Component.text("Create Warp"), status, List.of())
.inputs(List.of(
DialogInput.text("name", Component.text("Name"))
.initial(draft.name())
.maxLength(16)
.build(),
DialogInput.singleOption("category", Component.text("Category"), List.of(
SingleOptionDialogInput.OptionEntry.create("spawn", Component.text("Spawn"), draft.category().equals("spawn")),
SingleOptionDialogInput.OptionEntry.create("shop", Component.text("Shop"), draft.category().equals("shop"))
)).build(),
DialogInput.bool("public", Component.text("Public"))
.initial(draft.isPublic())
.build(),
DialogInput.numberRange("cost", Component.text("Cost"), 0, 100)
.step(5f)
.initial((float) draft.cost())
.build()
))
.build())
.type(DialogType.multiAction(List.of(
button(Component.text("Save"), (p, response) -> save(p, response, onClose))
))
.exitAction(button(Component.text("Back"), p -> leave(p, onClose)))
.build())
);
player.showDialog(dialog);
}
private static void save(Player player, DialogResponseView response, Consumer<Player> onClose) {
Draft draft = new Draft(
response.getText("name"),
response.getText("category"),
response.getBoolean("public"),
Math.round(response.getFloat("cost"))
);
if (draft.name().isBlank()) {
openCreate(player, draft, Component.text("Give your warp a name", NamedTextColor.RED), onClose);
return;
}
Consumer<Player> backToForm = p -> openCreate(p, draft, null, onClose);
Dialog confirm = Dialog.create(factory -> factory.empty()
.base(navigableBase(Component.text("Create Warp?"), null, List.of(
DialogBody.plainMessage(Component.text("Create " + draft.name() + "?"))
)).build())
.type(DialogType.multiAction(List.of(
button(Component.text("Confirm"), p -> {
p.sendMessage(Component.text("Created " + draft.name()));
leave(p, onClose);
}),
button(Component.text("Cancel"), p -> leave(p, backToForm))
))
.columns(2)
.build())
);
player.showDialog(confirm);
}
public static Dialog help() {
return Dialog.create(factory -> factory.empty()
.base(DialogBase.builder(Component.text("Warp Help"))
.pause(false)
.body(List.of(DialogBody.plainMessage(Component.text("Warps are saved spots anyone can teleport to."), 200)))
.build())
.type(DialogType.multiAction(List.of(
ActionButton.builder(Component.text("Back to menu"))
.action(DialogAction.staticAction(ClickEvent.runCommand("/warps")))
.build(),
ActionButton.builder(Component.text("Ask an admin..."))
.action(DialogAction.staticAction(ClickEvent.suggestCommand("/msg ")))
.build(),
ActionButton.builder(Component.text("Open the wiki"))
.action(DialogAction.staticAction(ClickEvent.openUrl("https://example.com/wiki/warps")))
.build()
))
.columns(1)
.exitAction(ActionButton.builder(Component.text("Done")).build())
.build())
);
}
public static Dialog invite() {
return Dialog.create(factory -> factory.empty()
.base(DialogBase.builder(Component.text("Invite a Player"))
.pause(false)
.inputs(List.of(
DialogInput.text("target", Component.text("Player")).build(),
DialogInput.bool("urgent", Component.text("Urgent"))
.onTrue("right now!")
.onFalse("when you can.")
.build()
))
.build())
.type(DialogType.confirmation(
ActionButton.builder(Component.text("Send"))
.action(DialogAction.commandTemplate("/msg $(target) Come check out my warps $(urgent)"))
.build(),
ActionButton.builder(Component.text("Cancel")).build()
))
);
}
}
DialogKit
public final class RunElement extends CustomElement {
private final Consumer<Player> action;
public RunElement(Component text, Component tooltip, Consumer<Player> action) {
this.action = action;
setText(text);
setTooltip(tooltip);
}
@Override
public void accept(DialogResponseView response, Audience audience) {
action.accept(assertPlayer(audience));
}
}
public final class CloseElement extends ButtonElement {
public CloseElement(Component text) {
setText(text);
}
@Override
protected DialogAction action() {
return null;
}
}
public final class WarpMenuDialog extends NavigableDialogScreen {
public static void open(Player player) {
new WarpMenuDialog().show(player, null, null);
}
private WarpMenuDialog() {
setTitle(Component.text("Warps"));
addText(ItemStack.of(Material.ENDER_PEARL), Component.text("Save a spot so others can teleport to it."));
MultiDialogShape shape = new MultiDialogShape();
shape.setColumns(2);
shape.addActions(
new RunElement(Component.text("Create"), null,
player -> CreateWarpDialog.open(player, CreateWarpDialog.Draft.EMPTY, null, WarpMenuDialog::open)),
new DialogElement(Component.text("Invite"), WarpDialogs.invite()),
new DialogElement(Component.text("Help"), WarpDialogs.help())
);
shape.setExitAction(leaveElement(Component.text("Close"), null));
setShape(shape);
}
}
public final class CreateWarpDialog extends NavigableDialogScreen {
record Draft(String name, String category, boolean isPublic, int cost) {
static final Draft EMPTY = new Draft("", "spawn", true, 0);
}
public static void open(Player player, Draft draft, Component status, Consumer<Player> onClose) {
new CreateWarpDialog(draft).show(player, status, onClose);
}
private CreateWarpDialog(Draft draft) {
setTitle(Component.text("Create Warp"));
TextDialogField name = new TextDialogField();
name.setKey("name");
name.setLabel(Component.text("Name"));
name.setInitial(draft.name());
name.setMaxLength(16);
addInput(name);
ChoiceDialogField category = new ChoiceDialogField();
category.setKey("category");
category.setLabel(Component.text("Category"));
category.addOption("spawn", Component.text("Spawn"));
category.addOption("shop", Component.text("Shop"));
category.setInitial(draft.category());
addInput(category);
ToggleDialogField isPublic = new ToggleDialogField();
isPublic.setKey("public");
isPublic.setLabel(Component.text("Public"));
isPublic.setInitial(draft.isPublic());
addInput(isPublic);
SliderDialogField cost = new SliderDialogField();
cost.setKey("cost");
cost.setLabel(Component.text("Cost"));
cost.setRange(0, 100);
cost.setStep(5);
cost.setInitial(draft.cost());
addInput(cost);
MultiDialogShape shape = new MultiDialogShape();
shape.addAction(new Save());
shape.setExitAction(leaveElement(Component.text("Back"), null));
setShape(shape);
}
private class Save extends CustomElement {
Save() {
setText(Component.text("Save"));
}
@Override
public void accept(DialogResponseView response, Audience audience) {
Player player = assertPlayer(audience);
Draft draft = new Draft(
response.getText("name"),
response.getText("category"),
response.getBoolean("public"),
Math.round(response.getFloat("cost"))
);
if (draft.name().isBlank()) {
open(player, draft, Component.text("Give your warp a name", NamedTextColor.RED), onClose());
return;
}
new ConfirmationDialog(Component.text("Create Warp?"), Component.text("Create " + draft.name() + "?")) {
@Override
protected void onConfirm(Player player) {
player.sendMessage(Component.text("Created " + draft.name()));
CreateWarpDialog.this.leave(player);
}
}.show(player, null, p -> open(p, draft, null, onClose())); // Cancel goes back to the form
}
}
}
public final class WarpDialogs {
public static Dialog help() {
DialogScreen screen = new DialogScreen();
screen.setTitle(Component.text("Warp Help"));
screen.addText(Component.text("Warps are saved spots anyone can teleport to."), 200);
MultiDialogShape shape = new MultiDialogShape();
shape.setColumns(1);
shape.addActions(
new CommandElement(Component.text("Back to menu"), "/warps"),
new SuggestCommandElement(Component.text("Ask an admin..."), "/msg "),
new UrlElement(Component.text("Open the wiki"), "https://example.com/wiki/warps")
);
shape.setExitAction(new CloseElement(Component.text("Done")));
screen.setShape(shape);
return screen.compile();
}
public static Dialog invite() {
DialogScreen screen = new DialogScreen();
screen.setTitle(Component.text("Invite a Player"));
TextDialogField target = new TextDialogField();
target.setKey("target");
target.setLabel(Component.text("Player"));
screen.addInput(target);
ToggleDialogField urgent = new ToggleDialogField();
urgent.setKey("urgent");
urgent.setLabel(Component.text("Urgent"));
urgent.setOnTrue("right now!");
urgent.setOnFalse("when you can.");
screen.addInput(urgent);
BinaryDialogShape shape = new BinaryDialogShape();
shape.setOptionOne(new CommandTemplateElement(Component.text("Send"),
"/msg $(target) Come check out my warps $(urgent)"));
shape.setOptionTwo(new CloseElement(Component.text("Cancel")));
screen.setShape(shape);
return screen.compile();
}
}