@@ -11,10 +11,6 @@ sidebar:
11
11
12
12
import Video from " /src/components/Video.astro" ;
13
13
14
- import InputBooleanMp4 from " ./assets/dialogs/input-boolean.mp4?url" ;
15
- import InputMultiOptionMp4 from " ./assets/dialogs/input-multi-options.mp4?url" ;
16
- import InputTextMp4 from " ./assets/dialogs/input-text.mp4?url" ;
17
- import InputNumberRange from " ./assets/dialogs/input-number-range.mp4?url" ;
18
14
import DialogShowcaseMp4 from " ./assets/dialogs/dialog-showcase.mp4?url" ;
19
15
import InputDialogShowcaseMp4 from " ./assets/dialogs/input-dialog-showcase.mp4?url" ;
20
16
@@ -66,6 +62,12 @@ can be declared in the builder. You can either create a new dialog or alternativ
66
62
[ registry-registered] ( #registering-dialogs-in-the-registry ) dialog as a base instead.
67
63
68
64
For reference, a very simple (notice-type) dialog can be constructed and shown to a player with the following code:
65
+
66
+ <details >
67
+ <summary >In-game preview</summary >
68
+ ![ A dialog with only a title and an ok button] ( ./assets/dialogs/notice-dialog.png )
69
+ </details >
70
+
69
71
``` java
70
72
Dialog dialog = Dialog . create(builder - > builder. empty()
71
73
.base(DialogBase . builder(Component . text(" Title" )). build())
@@ -74,11 +76,6 @@ Dialog dialog = Dialog.create(builder -> builder.empty()
74
76
player. showDialog(dialog);
75
77
```
76
78
77
- <details >
78
- <summary >In-game preview</summary >
79
- ![ A dialog with only a title and an ok button] ( ./assets/dialogs/notice-dialog.png )
80
- </details >
81
-
82
79
### Dialog base
83
80
You can create a dialog base using its [ builder] ( jd:paper:io.papermc.paper.registry.data.dialog.DialogBase$Builder ) , which can be created
84
81
using [ ` DialogBase.builder(Component title) ` ] ( jd:paper:io.papermc.paper.registry.data.dialog.DialogBase#builder(net.kyori.adventure.text.Component) ) .
@@ -104,25 +101,25 @@ There are four ways to gather input:
104
101
105
102
A simple tick box representing a true or false state
106
103
107
- < Video src = { InputBooleanMp4 } />
104
+ ![ ] ( ./assets/dialogs/input-boolean.gif )
108
105
109
106
- [ ` DialogInput.singleOption ` ] ( jd:paper:io.papermc.paper.registry.data.dialog.input.DialogInput#singleOption(java.lang.String,net.kyori.adventure.text.Component,java.util.List) )
110
107
111
108
A multiple-choice button
112
109
113
- < Video src = { InputMultiOptionMp4 } />
110
+ ![ ] ( ./assets/dialogs/input-multi-options.gif )
114
111
115
112
- [ ` DialogInput.text ` ] ( jd:paper:io.papermc.paper.registry.data.dialog.input.DialogInput#text(java.lang.String,net.kyori.adventure.text.Component) )
116
113
117
114
A simple string input field
118
115
119
- < Video src = { InputTextMp4 } />
116
+ ![ ] ( ./assets/dialogs/input-text.gif )
120
117
121
118
- [ ` DialogInput.numberRange ` ] ( jd:paper:io.papermc.paper.registry.data.dialog.input.DialogInput#numberRange(java.lang.String,net.kyori.adventure.text.Component,float,float) )
122
119
123
120
A slider for number input
124
121
125
- < Video src = { InputNumberRange } />
122
+ ![ ] ( ./assets/dialogs/input-number-range.gif )
126
123
127
124
128
125
### Dialog type
@@ -166,6 +163,17 @@ public void bootstrap(BootstrapContext context) {
166
163
}
167
164
```
168
165
166
+ ## Closing dialogs
167
+ Dialogs can be closed from the API. There are two ways to achieve that:
168
+
169
+ - The intended way of using [ ` Adventure#closeDialog() ` ] ( https://jd.advntr.dev/api/latest/net/kyori/adventure/audience/Audience.html#closeDialog() ) .
170
+ - The slightly hacky way of using [ `Player#closeInventory()] ( jd:paper:org.bukkit.entity.HumanEntity#closeInventory() ) .
171
+
172
+ Using ` closeDialog() ` will result in the dialog being closed and the player returning to the previous non-dialog or game menu screen they were on.
173
+ This means any previously open inventories will be kept open.
174
+
175
+ In contrast, ` closeInventory() ` will close not only the currently open dialog, but also any other screens, like an open inventory.
176
+
169
177
## Example: A blocking confirmation dialog
170
178
If you want your players to read some information, agree to something, or give general input before they join your server,
171
179
you can send them a dialog during the configuration phase. For this example, we will be creating the dialog shown at
@@ -214,6 +222,12 @@ this by constructing a `CompletableFuture`, putting it into a map, and waiting u
214
222
completed, will only happen as soon the player pressed one of the two confirmation buttons of the dialog.
215
223
216
224
The code for that would look something like this:
225
+
226
+ <details >
227
+ <summary >In-game preview</summary >
228
+ <Video src = { DialogShowcaseMp4 } />
229
+ </details >
230
+
217
231
``` java title="ServerJoinListener.java" showLineNumbers
218
232
@NullMarked
219
233
public class ServerJoinListener implements Listener {
@@ -284,11 +298,6 @@ public class ServerJoinListener implements Listener {
284
298
And that's all there is to it. You can use this code to block players from joining your server before they should
285
299
be allowed to.
286
300
287
- <details >
288
- <summary >In-game preview</summary >
289
- <Video src = { DialogShowcaseMp4 } />
290
- </details >
291
-
292
301
## Example: Retrieving and parsing user input
293
302
The dialog for this example will be fairly simple: We once again create a confirmation-type dialog which contains two number range inputs.
294
303
The top input will be for setting the level, the bottom input for setting the experience percentage towards the next level.
@@ -343,6 +352,12 @@ to cast the connection retrievable from [`PlayerCustomClickEvent#getCommonConnec
343
352
to a [ ` PlayerGameConnection ` ] ( jd:paper:io.papermc.paper.connection.PlayerGameConnection ) , from which we can get the player.
344
353
345
354
The full event handler code looks like this:
355
+
356
+ <details >
357
+ <summary >In-game preview</summary >
358
+ <Video src = { InputDialogShowcaseMp4 } />
359
+ </details >
360
+
346
361
``` java
347
362
@EventHandler
348
363
void handleLevelsDialog(PlayerCustomClickEvent event) {
@@ -400,8 +415,3 @@ DialogAction.customClick(
400
415
.build()
401
416
)
402
417
```
403
-
404
- <details >
405
- <summary >In-game preview</summary >
406
- <Video src = { InputDialogShowcaseMp4 } />
407
- </details >
0 commit comments