Skip to content

Commit 83fad3d

Browse files
chore: update README.md
1 parent c11154f commit 83fad3d

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

README.md

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![Cover](images/cover.png)
2+
13
# SomeGuiApi
24

35
SomeGuiApi is a versatile Java library designed for effortless creation and management
@@ -15,7 +17,12 @@ player experience within their Minecraft worlds.
1517

1618
### Plugin
1719

18-
Download the SomeGuiApi plugin from the releases page and place it in your server's `plugins` folder.
20+
1. **Download the Plugin**: Download the SomeGuiApi plugin from the [releases page](https://github.com/SomeSourceCode/SomeGuiApi/releases).
21+
2. **Install the Plugin**: Place the downloaded JAR file in your server's `plugins` folder.
22+
3. **Configure Your Plugin**: Ensure that any plugins using SomeGuiApi include it in the `depend` section of their `plugin.yml` file:
23+
```yaml
24+
depend: [SomeGuiApi]
25+
```
1926
2027
### Maven
2128
@@ -25,7 +32,7 @@ Add the following dependency to your `pom.xml` file:
2532
<dependency>
2633
<groupId>io.github.somesourcecode</groupId>
2734
<artifactId>someguiapi</artifactId>
28-
<version>1.0.0</version>
35+
<version>2.0.0</version>
2936
<scope>provided</scope>
3037
</dependency>
3138
```
@@ -41,7 +48,7 @@ repositories {
4148
}
4249
4350
dependencies {
44-
compileOnly 'io.github.somesourcecode:someguiapi:1.0.0'
51+
compileOnly 'io.github.somesourcecode:someguiapi:2.0.0'
4552
}
4653
```
4754

@@ -61,7 +68,7 @@ Creating a new GUI with SomeGuiApi is straightforward. Below is an example of cr
6168
ChestGui gui = new ChestGui(Component.text("My GUI"), 3);
6269
gui.show(player);
6370
```
64-
This code snippet creates a new ChestGui with the `title My GUI` and `3 rows`, and then displays
71+
This code snippet creates a new `ChestGui` with the title "My GUI" and 3 rows, and then displays
6572
it to the specified player.
6673

6774
### GuiItem
@@ -70,14 +77,17 @@ A `GuiItem` represents a clickable item within the GUI. You can customize its ap
7077
using various properties such as `material`, `title`, `lore`, and `click events`.
7178

7279
```java
80+
// Create a new GuiItem
7381
GuiItem item = new GuiItem();
82+
83+
// Set properties of the GuiItem
7484
item.setMaterial(Material.DIAMOND_SWORD);
7585
item.setTitle("Sword");
76-
item.setLore(new Lore()
77-
.appendLine("A powerful weapon"));
86+
item.setLore(new Lore().appendLine("A powerful weapon"));
87+
88+
// Set click event handler
7889
item.setOnClick(context -> {
79-
Player player = context.getPlayer();
80-
player.sendMessage("You clicked the sword!");
90+
context.getWhoClicked().sendMessage("You clicked the sword!");
8191
});
8292
```
8393

@@ -87,6 +97,7 @@ To add content to the GUI, you need to define a `Scene` containing a `root` Pare
8797
Here's how you can do it:
8898

8999
```java
100+
// Create a new ChestGui
90101
ChestGui gui = new ChestGui(Component.text("My GUI"), 3);
91102
92103
// Create a layout pane to hold the content
@@ -100,16 +111,16 @@ GuiItem item2 = createGuiItem(/* Item details */);
100111
// Add the items to the layout
101112
root.getChildren().addAll(item1, item2);
102113
103-
// create and set a Scene with the root node for the GUI
114+
// Create and set a Scene with the root node for the GUI
104115
Scene scene = new Scene(root);
105116
gui.setScene(scene);
106117
107118
// Show the GUI to the player
108119
gui.show(player);
109120
```
110121

111-
In this example, we create a Pane layout pane to hold the content of the GUI.
112-
We add GuiItems or other nodes to the layout, and then we set the `root` node for the GUI using a `Scene`.
122+
In this example, we create a `Pane` layout pane to hold the content of the GUI.
123+
We add `GuiItems` or other nodes to the layout, and then we set the `root` node for the GUI using a `Scene`.
113124
Finally, we show the GUI to the player.
114125

115126
### Layout Panes
@@ -123,6 +134,7 @@ SomeGuiApi provides several layout panes to assist with organizing and positioni
123134
### Nesting
124135

125136
You can nest layout panes within each other to achieve more complex GUI designs. For example:
137+
126138
```java
127139
ChestGui gui = new ChestGui(Component.text("Nested GUI"), 3);
128140
@@ -173,6 +185,7 @@ Nodes that extend `Region` (e.g. the [layout panes](#layout-panes)) also have th
173185
SomeGuiApi provides support for handling various types of click events. When a player clicks an item
174186
a click event will be fired. The top-most clicked node will receive the click first, followed by all of its
175187
parent nodes, if the click occurs within their bounds.
188+
176189
```java
177190
item.setOnClick(context -> {
178191
// Handle click
@@ -201,6 +214,36 @@ and the `click type` (e.g., left-click, right-click).
201214
It also can be consumed using `context.consume()` to prevent further processing of the click event. Other listeners can
202215
check if the context is consumed before handling the event using `context.isConsumed()`.
203216

217+
### Updating a Gui
218+
219+
When the gui is updated, e.g. a content, title, or size change, those changes are not automatically reflected in the
220+
displayed gui. To update the gui, you can use the `update` method:
221+
222+
```java
223+
gui.setTitle(Component.text("New Title"));
224+
gui.update();
225+
```
226+
227+
To reduce the amount of calculations, layout is only computed for `Parents` marked as needing layout.
228+
For most changes, an update is automatically requested; if that's not the case you can manually request it using
229+
the `Parent#requestLayout` method.
230+
<br>
231+
Some non-layout related changes cannot be picked up by the system (e.g. lore changes). Just calling `update` won't
232+
update the lore, because a render has to be manually requested. This can be done using the `ChestGui#requestRender` method:
233+
234+
```java
235+
// Update the lore of an item
236+
item.setLore(new Lore().appendLine("Updated Lore"));
237+
238+
// Request a render to reflect the lore change
239+
// Rendering happens when the gui is updated
240+
gui.requestRender();
241+
gui.update();
242+
243+
// Alternatively, you can combine the two calls into one
244+
gui.requestRender(true);
245+
```
246+
204247
## License
205248

206249
SomeGuiApi is licensed under the [MIT License](LICENSE).

images/cover.png

2.95 MB
Loading

0 commit comments

Comments
 (0)