- Compatible API Versions
- 1.0.8,1.0.9,1.0.10,1.0.11
- Sourcecode
- https://github.com/DenzelCode/FormAPI
- Contributors
- Denzel Code
FormAPI
The best form API provider for Nukkit Cloudburst.
What's FormAPI?
FormAPI is an API that provides you everything that you need to enhance your plugins with the forms system implemented on Nukkit.
Download
Download the latest JAR: https://github.com/DenzelCode/FormAPI/releases/latest
Dependency for maven:
Installation:
Example:
Create formulary and send it to the client:
Event listener:
Modal Example
Simple Example
Custom Example
Licensing information
This project is licensed under LGPL-3.0. Please see the LICENSE file for details.
Donations
The best form API provider for Nukkit Cloudburst.
What's FormAPI?
FormAPI is an API that provides you everything that you need to enhance your plugins with the forms system implemented on Nukkit.
Download
Download the latest JAR: https://github.com/DenzelCode/FormAPI/releases/latest
Dependency for maven:
Java:
<dependency>
<groupId>com.denzelcode.form</groupId>
<artifactId>FormAPI</artifactId>
<version>1.0.0</version>
<systemPath>${project.basedir}/lib/FormAPI.jar</systemPath>
</dependency>
- Put the FormAPI.jar inside of /plugins.
Java:
import com.denzelcode.form.FormAPI;
FormAPI.init(this);
Create formulary and send it to the client:
Java:
package com.denzelcode.test;
import cn.nukkit.Player;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import com.denzelcode.form.FormAPI;
public class TestCommand extends Command {
public TestCommand() {
super("test");
}
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
FormAPI.customWindowForm("login", "Custom Form")
.addInput("username", "Username", "Enter your username")
.addInput("password", "Password", "Enter your password")
.addHandler((e) -> System.out.println('Variable e is an instance of CustomFormSubmitEvent'))
.sendTo((Player) sender);
return true;
}
}
Java:
package com.denzelcode.test;
import cn.nukkit.Player;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import com.denzelcode.form.FormAPI;
import com.denzelcode.form.element.Button;
import com.denzelcode.form.element.Input;
import com.denzelcode.form.event.PlayerCustomFormSubmit;
import com.denzelcode.form.event.PlayerModalFormSubmit;
import com.denzelcode.form.event.PlayerSimpleFormButtonClick;
import com.denzelcode.form.window.CustomWindowForm;
import com.denzelcode.form.window.ModalWindowForm;
import com.denzelcode.form.window.SimpleWindowForm;
public class EventListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onLoginFormSubmit(PlayerCustomFormSubmit event) {
CustomWindowForm form = event.getForm();
Player player = event.getPlayer();
if (!event.isFormValid("login")) return;
Input username = form.getElement("username");
Input password = form.getElement("password");
player.sendMessage("Player: " + player.getName());
player.sendMessage("Form: " + form.getName());
player.sendMessage("Username: " + username.getValue());
player.sendMessage("Password: " + password.getValue());
FormAPI.modalWindowForm(
"login_remember",
"Remember",
"Do you want to remember your account in this device?",
"Yes",
"No"
).sendTo(player);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onRememberFormSubmit(PlayerModalFormSubmit event) {
ModalWindowForm form = event.getForm();
Player player = event.getPlayer();
if (!event.isFormValid("login_remember")) return;
boolean accepted = event.isAccepted();
player.sendMessage("Player: " + player.getName());
player.sendMessage("Form: " + form.getName());
player.sendMessage("Accepted: " + (accepted ? "Yes" : "No"));
FormAPI.simpleWindowForm("minigames", "Minigames", "Select a minigame which you want to play!")
.addButton("skywars", "SkyWars")
.addButton("luckyislands", "LuckyIslands")
.sendTo(player);
}
@EventHandler(priority = EventPriority.NORMAL)
public void onMinigameFormSubmit(PlayerSimpleFormButtonClick event) {
SimpleWindowForm form = event.getForm();
Player player = event.getPlayer();
Button button = event.getButton();
if (!event.isFormValid("minigames")) return;
player.sendMessage("Player: " + player.getName());
player.sendMessage("Form: " + form.getName());
player.sendMessage("Clicked button: " + button.getName());
player.sendMessage("Successfully joined Minigame: " + button.getText() + "!");
}
}
- Run command /test and you will have this showed in-game: Screenshot
Modal Example
Java:
import com.denzelcode.form.FormAPI;
FormAPI.modalWindowForm("modal", "Custom Form", "This is a content", "Accept", "Decline")
.addHandler((e) -> System.out.println('Variable e is an instance of ModalFormSubmitEvent'))
.sendTo(player);
Java:
FormAPI.simpleWindowForm("simple", "Simple Form", "This is a content")
.addButton("name", "This is a button")
.addButton("name1", "Hi, im a button", "https://i.imgur.com/PPvUcoW.png")//ImageType is default URL in this case
.addButton("name2", "This is other button", ImageType.PATH, "textures/ui/feedIcon.png")
.addHandler((e) -> System.out.println('Variable e is an instance of SimpleFormButtonClickEvent'))
.sendTo(player);
Java:
import com.denzelcode.form.FormAPI;
List<String> optionsDropdown = new ArrayList<String>(){{
add("Option 1");
add("Option 2");
}};
FormAPI.customWindowForm("custom", "Custom Form")
.addInput("name", "Fill the input", "Hello, im the input")
.addDropdown("name1", "text", optionsDropdown)
.addLabel("name2", "This a label")
.addSlider("name3", "This is a slider", 1f, 10f)
.addToggle("name4", "This is a toggle", false)
.addHandler((e) -> System.out.println('Variable e is an instance of CustomFormSubmitEvent'))
.sendTo(player);
This project is licensed under LGPL-3.0. Please see the LICENSE file for details.
Donations