I stopped writing plugins for Nukkit and I don't see any point in supporting this project. Use a good fork that my friend made: https://github.com/MEFRREEX/FormConstructor
Library is designed to simplify the creation and handling of forms. It has a few key advantages over other form libraries:
- Forms are processed using a lambda, which is passed when the form itself is created, and not by catching events.
- For each button we can set a lambda function in SimpleForm.
- In SimpleForm we get a button object as a response, where we can get its text and index.
- In CustomForm we can mark elements with an identifier to conveniently get this element in its handler. We can get element by id and its index.
- Easy async handling.
SimpleFormform = newSimpleForm("Sample title");
SimpleFormHandlerhandler = (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")
.add(newButton("Test button", handler))
.add(newButton("Same button but with image", Button.Icon.texture("textures/items/diamond"), handler));
//We can set handler for null resultform.setOnCloseHandler(p -> {
p.sendMessage("Why you closed this form? :c");
});
form.send(player);ModalFormform = newModalForm("Test modal form");
form.setContent("Is OneKN gay?") //local meme in RuNukkitDev
.setPositiveButton("Yes")
.setNegativeButton("Sure");
form.setResponse((p, result) -> {
p.sendMessage(result? "I knew it!" : "Quite right :D");
});
form.send(player);CustomFormform = newCustomForm("Sample custom form");
List<SelectableElement> elements = Arrays.asList(
newSelectableElement("Option 1"),
newSelectableElement("Option 2 but with value", 42),
newSelectableElement("Option 3")
);
form.add(newLabel("This is a test"))
.add("Easy way to add a label")
.add("my-text", newInput("A sample input"))
.add("my-toggle", newToggle("Toggle?", true))
.add("my-dd", newDropdown("Dropdown", elements))
.add(newDropdown("Dropdown with default value", elements, 1))
.add("my-ss", newStepSlider("Step slider", elements, 2));
form.setHandler((p, response) -> {
//We can get by id and indexp.sendMessage(response.getInput("my-text").getValue());
p.sendMessage(response.getInput(1).getValue()); //It's bad practice. Do not use indexesp.sendMessage(response.getToggle("my-toggle").getValue());
SelectableElementel = response.getDropdown("my-dd").getValue();
p.sendMessage(el.getText());
if(el.getValue() != null) p.sendMessage(el.getValue(Integer.class));
el = response.getStepSlider("my-ss").getValue();
p.sendMessage(el.getText());
});
form.send(player);Also you can use method form.sendAsync(player) for using async form handling.
