Skip to content

Commit a551062

Browse files
Merge pull request #4 from ContentForge/pnx2
Updated for PowerNukkitX 2.0
2 parents ad2e295 + d71246a commit a551062

43 files changed

Lines changed: 484 additions & 441 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea
2+
.gradle
23
*.iml
3-
/lib/
4+
/build/
45
/out/
56
/target/

README.md

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
![logo by @tolimag](.github/logo.png)
22

33
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
4-
[![Version](https://img.shields.io/badge/version-1.1.3-brightgreen)](https://github.com/ContentForge/FormConstructor/releases/tag/1.1.3)
5-
[![CloudBurst](https://img.shields.io/badge/CloudBurst-1.1.2-brightgreen)](https://cloudburstmc.org/resources/formconstructor.738/)
4+
[![Version](https://img.shields.io/badge/version-2.0.0-brightgreen)](https://github.com/ContentForge/FormConstructor/releases/tag/2.0.0)
65

76
Introduction
87
-------------
@@ -19,7 +18,7 @@ It has a few key advantages over other form libraries:
1918
Examples
2019
-------------
2120

22-
For SimpleForm:
21+
### SimpleForm
2322
```java
2423
SimpleForm form = new SimpleForm("Sample title");
2524

@@ -30,21 +29,18 @@ SimpleFormHandler handler = (p, button) -> {
3029

3130
form.setContent("This is a text")
3231
.addContent("\nThis is addition :3")
33-
.addButton("Test button", handler)
34-
.addButton("Same button but with image", ImageType.PATH, "textures/items/diamond", handler)
35-
.addButton("Button without handler");
32+
.add(new Button("Test button", handler))
33+
.add(new Button("Same button but with image", Button.Icon.texture("textures/items/diamond"), handler));
3634

3735
//We can set handler for null result
38-
form.setNoneHandler(p -> {
36+
form.setOnCloseHandler(p -> {
3937
p.sendMessage("Why you closed this form? :c");
4038
});
4139

4240
form.send(player);
43-
//Also we can use `player.showFormWindow(form);` but it isn't comfortable
4441
```
4542

46-
For ModalForm:
47-
43+
### ModalForm
4844
```java
4945
ModalForm form = new ModalForm("Test modal form");
5046

@@ -59,8 +55,7 @@ form.setResponse((p, result) -> {
5955
form.send(player);
6056
```
6157

62-
For CustomForm:
63-
58+
### CustomForm
6459
```java
6560
CustomForm form = new CustomForm("Sample custom form");
6661

@@ -70,18 +65,18 @@ List<SelectableElement> elements = Arrays.asList(
7065
new SelectableElement("Option 3")
7166
);
7267

73-
form.addElement(new Label("This is a test"))
74-
.addElement("Easy way to add a label")
75-
.addElement("my-text", Input.builder().setName("A sample input").build())
76-
.addElement("my-toggle", new Toggle("Toggle?", true))
77-
.addElement("my-dd", new Dropdown("Dropdown", elements))
78-
.addElement(new Dropdown("Dropdown with default value", elements, 1))
79-
.addElement("my-ss", new StepSlider("Step slider", elements, 2));
68+
form.add(new Label("This is a test"))
69+
.add("Easy way to add a label")
70+
.add("my-text", new Input("A sample input"))
71+
.add("my-toggle", new Toggle("Toggle?", true))
72+
.add("my-dd", new Dropdown("Dropdown", elements))
73+
.add(new Dropdown("Dropdown with default value", elements, 1))
74+
.add("my-ss", new StepSlider("Step slider", elements, 2));
8075

8176
form.setHandler((p, response) -> {
8277
//We can get by id and index
8378
p.sendMessage(response.getInput("my-text").getValue());
84-
p.sendMessage(response.getInput(1).getValue()); //It's bad method
79+
p.sendMessage(response.getInput(1).getValue()); //It's bad practice. Do not use indexes
8580
p.sendMessage(response.getToggle("my-toggle").getValue());
8681

8782
SelectableElement el = response.getDropdown("my-dd").getValue();
@@ -91,13 +86,9 @@ form.setHandler((p, response) -> {
9186
el = response.getStepSlider("my-ss").getValue();
9287
p.sendMessage(el.getText());
9388
});
89+
90+
form.send(player);
9491
```
9592

9693
### Async handling
97-
Also you can use method `sendAsync(Player)` for using async form handling.
98-
But this may cause some restrictions. What exactly - I don't know.
99-
100-
Donate
101-
-------------
102-
103-
- [DonationAlerts](https://www.donationalerts.com/r/qpexlegendary)
94+
Also you can use method `form.sendAsync(player)` for using async form handling.

build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group = 'ru.scarletredman'
6+
version = '2.0.0'
7+
8+
sourceCompatibility = JavaVersion.VERSION_17
9+
targetCompatibility = JavaVersion.VERSION_17
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
compileOnly files("lib/powernukkitx.jar")
17+
implementation 'com.google.code.gson:gson:2.10.1'
18+
19+
compileOnly "org.projectlombok:lombok:1.18.32"
20+
annotationProcessor "org.projectlombok:lombok:1.18.32"
21+
}
22+
23+
tasks {
24+
compileJava {
25+
options.encoding = "UTF-8"
26+
}
27+
28+
compileTestJava {
29+
options.encoding = "UTF-8"
30+
}
31+
}

gradle/wrapper/gradle-wrapper.jar

59.3 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Fri Apr 05 21:26:26 KRAT 2024
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
5+
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

gradlew

Lines changed: 234 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)