-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathDialogInput.java
More file actions
99 lines (87 loc) · 4.76 KB
/
DialogInput.java
File metadata and controls
99 lines (87 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package fr.openmc.api.input.dialog;
import io.papermc.paper.dialog.Dialog;
import io.papermc.paper.registry.data.dialog.ActionButton;
import io.papermc.paper.registry.data.dialog.DialogBase;
import io.papermc.paper.registry.data.dialog.action.DialogAction;
import io.papermc.paper.registry.data.dialog.body.DialogBody;
import io.papermc.paper.registry.data.dialog.type.DialogType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickCallback;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
@SuppressWarnings("UnstableApiUsage")
public class DialogInput {
public static void send(Player player, Component lore, int maxLength, Consumer<String> callback) {
List<DialogBody> body = new ArrayList<>();
body.add(DialogBody.plainMessage(lore));
Dialog inputDialog = Dialog.create(builder -> builder.empty()
.base(DialogBase.builder(Component.text("Rentrer du Texte"))
.body(body)
.inputs(List.of(
io.papermc.paper.registry.data.dialog.input.DialogInput
.text("inputtextomc",
Component.text("Rentrer du texte ici")
)
.maxLength(maxLength)
.build()
)
)
.canCloseWithEscape(true)
.build()
)
.type(DialogType.confirmation(
ActionButton.builder(Component.text(ButtonType.CONFIRM.getLabel()))
.action(DialogAction.customClick((response, audience) -> {
callback.accept(response.getText("inputtextomc"));
}, ClickCallback.Options.builder().build()))
.build(),
ActionButton.builder(Component.text(ButtonType.CANCEL.getLabel()))
.action(DialogAction.customClick((response, audience) -> {
callback.accept(null);
}, ClickCallback.Options.builder().build()))
.build()
)
)
);
player.showDialog(inputDialog);
}
public static void sendFloat(Player player, Component lore, float minSize, float maxSize, float initial, Consumer<Float> callback) {
List<DialogBody> body = new ArrayList<>();
body.add(DialogBody.plainMessage(lore));
Dialog inputDialog = Dialog.create(builder -> builder.empty()
.base(DialogBase.builder(Component.text("Rentrer un nombre"))
.body(body)
.inputs(List.of(
io.papermc.paper.registry.data.dialog.input.DialogInput
.numberRange("inputfloatomc",
Component.text("Rentrer un nombre ici"),
minSize,
maxSize
)
.initial(initial)
.step(1F)
.build()
)
)
.canCloseWithEscape(true)
.build()
)
.type(DialogType.confirmation(
ActionButton.builder(Component.text(ButtonType.CONFIRM.getLabel()))
.action(DialogAction.customClick((response, audience) -> {
callback.accept(response.getFloat("inputfloatomc"));
}, ClickCallback.Options.builder().build()))
.build(),
ActionButton.builder(Component.text(ButtonType.CANCEL.getLabel()))
.action(DialogAction.customClick((response, audience) -> {
callback.accept(null);
}, ClickCallback.Options.builder().build()))
.build()
)
)
);
player.showDialog(inputDialog);
}
}