-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleMenuExample.java
More file actions
174 lines (165 loc) · 6.61 KB
/
SimpleMenuExample.java
File metadata and controls
174 lines (165 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package eu.okaeri.menu.test.example;
import eu.okaeri.menu.Menu;
import eu.okaeri.menu.MenuContext;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import static eu.okaeri.menu.item.MenuItem.item;
import static eu.okaeri.menu.pane.StaticPane.staticPane;
/**
* Simple example demonstrating the new menu system.
* This shows Phase 1 functionality: Pane-based architecture with reactive properties.
*/
public class SimpleMenuExample {
public static Menu createSimpleMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("Simple Menu")
.rows(3)
.pane(staticPane()
.name("main")
.bounds(0, 0, 3, 9) // Full 3-row inventory
.item(0, 0, item()
.material(Material.DIAMOND)
.name("Static Diamond")
.onClick(event -> event.sendMessage("You clicked a diamond!"))
.build())
.item(0, 1, item()
.material(Material.GOLD_INGOT)
.name(() -> "Dynamic: " + System.currentTimeMillis()) // Reactive!
.onClick(event -> {
event.sendMessage("Refreshing menu...");
event.refresh();
})
.build())
.item(2, 8, item()
.material(Material.BARRIER)
.name("Close")
.onClick(MenuContext::closeInventory)
.build())
.build())
.build();
}
public static Menu createPaneExample(Plugin plugin) {
return Menu.builder(plugin)
.title("Multi-Pane Example")
.rows(6)
// Top navigation pane
.pane(staticPane()
.name("nav")
.bounds(0, 0, 1, 9)
.item(0, 4, item()
.material(Material.COMPASS)
.name("Navigation")
.build())
.item(0, 8, item()
.material(Material.BARRIER)
.name("Close")
.onClick(MenuContext::closeInventory)
.build())
.build())
// Content pane
.pane(staticPane()
.name("content")
.bounds(1, 0, 5, 9)
.item(2, 4, item()
.material(Material.EMERALD)
.name("Content Item")
.onClick(event -> {
event.sendMessage("Content clicked!");
event.refreshPane("content"); // Refresh only this pane
})
.build())
.build())
.build();
}
/**
* Example with reactive properties.
*/
public static Menu createReactiveExample(Plugin plugin, Player player) {
return Menu.builder(plugin)
.title("Reactive Example")
.rows(3)
.pane(staticPane()
.name("main")
.bounds(0, 0, 3, 9)
.item(1, 4, item()
.material(Material.DIAMOND)
.name(ctx -> "Clicks: " + ctx.getInt("clickCount")) // Reactive!
.amount(ctx -> Math.min(64, ctx.getInt("clickCount") + 1)) // Reactive amount!
.onClick(event -> {
event.set("clickCount", event.getInt("clickCount") + 1);
event.refresh(); // Re-evaluate reactive properties
})
.build())
.build())
.build();
}
/**
* Example with automatic update intervals.
* Demonstrates reactive properties that change over time without manual refresh.
*/
public static Menu createAutoUpdateExample(Plugin plugin) {
Instant startTime = Instant.now();
return Menu.builder(plugin)
.title("Auto-Update Example")
.rows(3)
.updateInterval(Duration.ofSeconds(1)) // Update every second
.pane(staticPane()
.name("main")
.bounds(0, 0, 3, 9)
// Clock display - updates automatically
.item(1, 1, item()
.material(Material.CLOCK)
.name(() -> "Current Time")
.lore("""
&7Server: &f<millis>
&7Elapsed: &f<elapsed>s""",
ctx -> Map.of(
"millis", System.currentTimeMillis(),
"elapsed", Duration.between(startTime, Instant.now()).getSeconds()
))
.build())
// Online players count - updates automatically
.item(1, 4, item()
.material(Material.PLAYER_HEAD)
.name(() -> "Online Players")
.amount(() -> Math.max(1, Bukkit.getOnlinePlayers().size())) // Min 1 for visibility
.lore("""
&7Count: &f<count>
&7Updates every second""",
ctx -> Map.of("count", Bukkit.getOnlinePlayers().size()))
.build())
// Dynamic material - cycles through colors
.item(1, 7, item()
.material(() -> {
long seconds = Duration.between(startTime, Instant.now()).getSeconds();
Material[] materials = {
Material.RED_WOOL,
Material.ORANGE_WOOL,
Material.YELLOW_WOOL,
Material.LIME_WOOL,
Material.CYAN_WOOL,
Material.BLUE_WOOL,
Material.PURPLE_WOOL
};
return materials[(int) (seconds % materials.length)];
})
.name(() -> "Color Cycle")
.lore("""
&7This item changes color
&7every second automatically!""")
.build())
// Close button
.item(2, 8, item()
.material(Material.BARRIER)
.name("Close")
.onClick(event -> event.closeInventory())
.build())
.build())
.build();
}
}