-
Notifications
You must be signed in to change notification settings - Fork 9
Creating and handling SimpleForm
SimpleForm intended for creating menu.
Simple form has 3 elements:
- Title
- Text
- Buttons (may be with image)
Buttons may be haven't add. We can add handler for each button. Example:
Button button = new Button("Sample text", (player, chosenButton) -> {
// Player player
// Button chosenButton (same button)
});
We can get all button`s data(name, index, handler, icon).
Note: We can not add over than 100 buttons.
Note: After clicking on button form will close.
Also we can use a symbol \n
for creating few lines in the button text.
We can add image for button. Image can be stored in internet and in resource pack. Image format need be .png.
Images from internet always loading after opening form. It's slow but we can use any images in any time. Example:
Button button = new Button("Sample text", ImageType.URL, "http://dragonestia.ru/static/hello.png");
Images from resource pack loading quickly. But for this we need add resource pack and all players need download it. Example:
Button button = new Button("Sample text", ImageType.PATH, "textures/items/diamond");
Where textures/items/diamond
is path in resource pack without file format.
This form can be closed by player without choosing button. For this situation, NoneHandler was added. Example:
form.setNoneHandler(player -> {
player.sendMessage("Why you closed this form? :c");
});
SimpleForm form = new SimpleForm("Sample title");
SimpleFormHandler handler = (p, button) -> {
p.sendMessage("Your selected button is " + button.getName());
p.sendMessage("Its index - " + button.index);
};
form.setContent("This is a text")
.addContent("\nThis is addition :3")
.addButton("Test button", handler)
.addButton("Same button but with image", ImageType.PATH, "textures/items/diamond", handler)
.addButton("Button without handler");
.setNoneHandler(p -> {
p.sendMessage("Why you closed this form? :c");
}).send(player);