• 你好,Guest,欢迎回来!Nukkit-MOT BBS社区是专为Minecraft玩家和开发者提供的Nukkit-MOT平台技术论坛。Nukkit-MOT是一个多版本、内置实体AI、广泛插件兼容的我的世界服务器软件,采用Java编写,专为性能和可扩展性设计,支持插件开发和自定义功能。在Nukkit-MOT BBS,您可以轻松找到开服教程、插件开发资源和插件分享,帮助您快速搭建和管理Nukkit-MOT服务器,提升开发技能,推广您的插件。

    You can join [Discord] to get the latest notifications.
    为了避免一些意外情况,你可以【加入QQ群】来获取最新通知
FormConstructor V2

Open Source Free FormConstructor V2 2.0.5

No permission to download
Resource Type
Originality
API Version
1.0.0
Copyright Link
https://github.com/MEFRREEX/FormConstructor
Open Source URL
https://github.com/MEFRREEX/FormConstructor
View attachment 4441

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.setCloseHandler(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.setCloseHandler(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);

🔌 Installation

Place the plugin of the appropriate version in the `plugins` folder.

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.5</version>
</dependency>

Gradle (Kotlin DSL)​


Repository:
Code:
repositories {
    mavenCentral()
    maven("https://jitpack.io")
}

Dependency:
Code:
dependencies {
    compileOnly("com.github.MEFRREEX:FormConstructor:2.0.5")
}
  • Like
Reactions: 眠悠子Miyoz
Author
MEFRREEX
Downloads
1
Views
14
First release
Last update
Rating
0.00 star(s) 0 ratings