FormConstructor V2

FormConstructor V2 2.0.1

Compatible API Versions
1.0.0
Sourcecode
https://github.com/MEFRREEX/FormConstructor
Contributors
terentev, MEFRREEX
logo_v2.png


The current version of the FormConstructor plugin is 2.0.0. This version includes many API changes and improvements.
You can read the full list of changes here: CHANGELOG

🤔 Introduction

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 in SimpleForm we can set a lambda function.
  • In SimpleForm we get a button object as a response, where we can get its name 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.
  • For each form we can set its closing handler.
  • Easy async handling.

🛠 Examples

Creating a SimpleForm:
Java:
SimpleForm form = new SimpleForm("Sample title");
// Adding form content
form.addContent("New content line");
 
// Easiest way to add a button
form.addButton("Button", (pl, b) -> {
        pl.sendMessage("Button clicked: " + b.getName() + " (" + b.getIndex() + ")");
    })
    // Button with image
    .addButton("Button with image", ImageType.PATH, "textures/items/diamond")
    // Another way to add a button
    .addButton(new Button("Another button")
        .setImage(ImageType.PATH, "textures/blocks/stone")
        .onClick((pl, b) -> {
            pl.sendMessage("Another button clicked: " + b.getName() + " (" + b.getIndex() + ")");
        }));

// Setting the form close handler
form.setNoneHandler(pl -> {
    pl.sendMessage("You closed the form!");
});

form.send(player);
Creating a ModalForm:
Java:
ModalForm form = new ModalForm("Test modal form");
form.addContent("New content line");

form.setPositiveButton("Positive button")
    .setNegativeButton("Negative button");

// Setting the form handler
// Result returns true if a positive button was ckicked and false if a negative button was ckicked
form.setHandler((pl, result) -> {
    pl.sendMessage("You clicked " + (result ? "correct" : "wrong") + " button!");
});

// Setting the form close handler
form.setNoneHandler(pl -> pl.sendMessage("You closed the form!"));
form.send(player);
Creating a CustomForm:
Java:
CustomForm form = new CustomForm("Test custom form");

// Options list
List<SelectableElement> elements = List.of(
    new SelectableElement("Option 1"),
    new SelectableElement("Option 2"),
    // SelectableElement may be named and may contain a value
    new SelectableElement("Option with value", 15)
);

form.addElement("Test label")
    .addElement("input", new Input("Input")
        .setPlaceholder("Text")
        .setDefaultValue("Default value"))
    .addElement("slider", new Slider("Slider", 1f, 100f, 1, 1))
    .addElement("stepslider", new StepSlider("Step slider")
        .addStep("1")
        .addStep("2")
        .addStep("3"))
    .addElement("dropdown", new Dropdown("Dropdown")
        .addElement("Element 1")
        .addElement("Element 2")
        .addElement("Element 3"))
    .addElement("dropdown1", new Dropdown("Second dropdown", elements))
    .addElement("toggle", new Toggle("Toggle"));

// Setting the form handler
form.setHandler((pl, response) -> {
    String input = response.getInput("input").getValue();

    float slider = response.getSlider("slider").getValue();
    SelectableElement stepslider = response.getStepSlider("stepslider").getValue();
    SelectableElement dropdown = response.getDropdown("dropdown").getValue();

    // Getting the value we set in SelectableElement
    Integer dropdownValue = response.getDropdown("dropdown1").getValue().getValue(Integer.class);

    boolean toggle = response.getToggle("toggle").getValue();

    pl.sendMessage("Input: " + input + ", Slider: " + slider + ", Step Slider: " + stepslider + ", Dropdown: " + dropdown + ", Toggle: " + toggle);
    pl.sendMessage("Second dropdown value: " + dropdownValue);
});

form.send(player);
🔌 Maven

Repository

XML:
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
Dependency
XML:
<dependency>
    <groupId>com.github.MEFRREEX</groupId>
    <artifactId>FormConstructor</artifactId>
    <version>2.0.0</version>
</dependency>
Author
MEFRREEX
Downloads
383
Views
771
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from MEFRREEX

Latest updates

  1. Changed FormElement#setName method

    Changed the type returned by the setName() method in FormElement
Top