-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigationExample.java
More file actions
346 lines (324 loc) · 12.5 KB
/
NavigationExample.java
File metadata and controls
346 lines (324 loc) · 12.5 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package eu.okaeri.menu.test.example;
import eu.okaeri.menu.Menu;
import eu.okaeri.menu.navigation.NavigationUtils;
import org.bukkit.Material;
import org.bukkit.plugin.Plugin;
import static eu.okaeri.menu.item.MenuItem.item;
import static eu.okaeri.menu.pane.StaticPane.staticPane;
/**
* Examples demonstrating the navigation system (Phase 2).
* Shows how to create menus that can navigate between each other with back buttons.
*/
public class NavigationExample {
/**
* Creates a main menu with navigation to sub-menus.
*/
public static Menu createMainMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("Main Menu")
.rows(3)
.pane(staticPane()
.name("main")
.bounds(0, 0, 3, 9)
// Navigate to Shop
.item(1, 1, item()
.material(Material.EMERALD)
.name("&a&lShop")
.lore("""
&7Browse items for sale
&eClick to open!""")
.onClick(event -> {
event.open(createShopMenu(event.getMenu().getPlugin()));
})
.build())
// Navigate to Settings
.item(1, 4, item()
.material(Material.COMPARATOR)
.name("&b&lSettings")
.lore("""
&7Configure your preferences
&eClick to open!""")
.onClick(event -> {
event.open(createSettingsMenu(event.getMenu().getPlugin()));
})
.build())
// Navigate to Profile
.item(1, 7, item()
.material(Material.PLAYER_HEAD)
.name("&d&lProfile")
.lore("""
&7View your statistics
&eClick to open!""")
.onClick(event -> {
event.open(createProfileMenu(event.getMenu().getPlugin()));
})
.build())
// Close button (no back button since this is main menu)
.item(2, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Creates a shop menu with categories.
*/
public static Menu createShopMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("&a&lShop")
.rows(4)
.pane(staticPane()
.name("main")
.bounds(0, 0, 4, 9)
// Shop categories
.item(1, 1, item()
.material(Material.DIAMOND_SWORD)
.name("&b&lWeapons")
.lore("""
&7Browse weapons
&eClick to open!""")
.onClick(event -> {
event.open(createWeaponsMenu(event.getMenu().getPlugin()));
})
.build())
.item(1, 4, item()
.material(Material.DIAMOND_CHESTPLATE)
.name("&9&lArmor")
.lore("""
&7Browse armor
&eClick to open!""")
.onClick(event -> {
event.open(createArmorMenu(event.getMenu().getPlugin()));
})
.build())
.item(1, 7, item()
.material(Material.GOLDEN_APPLE)
.name("&6&lConsumables")
.lore("""
&7Browse consumables
&eClick to open!""")
.onClick(event -> {
event.open(createConsumablesMenu(event.getMenu().getPlugin()));
})
.build())
// Navigation: Back button (visible because we came from main menu)
.item(3, 0, NavigationUtils.backButton().build())
// Close button
.item(3, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Creates a weapons shop menu (3rd level).
*/
public static Menu createWeaponsMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("&b&lWeapons Shop")
.rows(4)
.pane(staticPane()
.name("main")
.bounds(0, 0, 4, 9)
// Weapons
.item(1, 1, item()
.material(Material.DIAMOND_SWORD)
.name("&b&lDiamond Sword")
.lore("""
&7Damage: &c+7
&7Price: &6100 coins
&eClick to purchase!""")
.onClick(event -> {
event.sendMessage("&aPurchased Diamond Sword!");
})
.build())
.item(1, 2, item()
.material(Material.IRON_SWORD)
.name("&f&lIron Sword")
.lore("""
&7Damage: &c+6
&7Price: &650 coins
&eClick to purchase!""")
.onClick(event -> {
event.sendMessage("&aPurchased Iron Sword!");
})
.build())
.item(1, 3, item()
.material(Material.BOW)
.name("&e&lBow")
.lore("""
&7Range Weapon
&7Price: &675 coins
&eClick to purchase!""")
.onClick(event -> {
event.sendMessage("&aPurchased Bow!");
})
.build())
// Navigation: Back button (visible, goes to Shop menu)
.item(3, 0, NavigationUtils.backButton().build())
// Close button
.item(3, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Creates an armor shop menu (3rd level).
*/
public static Menu createArmorMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("&9&lArmor Shop")
.rows(4)
.pane(staticPane()
.name("main")
.bounds(0, 0, 4, 9)
// Armor pieces
.item(1, 1, item()
.material(Material.DIAMOND_HELMET)
.name("&b&lDiamond Helmet")
.lore("""
&7Defense: &a+3
&7Price: &6150 coins""")
.build())
.item(1, 2, item()
.material(Material.DIAMOND_CHESTPLATE)
.name("&b&lDiamond Chestplate")
.lore("""
&7Defense: &a+8
&7Price: &6300 coins""")
.build())
.item(1, 3, item()
.material(Material.DIAMOND_LEGGINGS)
.name("&b&lDiamond Leggings")
.lore("""
&7Defense: &a+6
&7Price: &6250 coins""")
.build())
.item(1, 4, item()
.material(Material.DIAMOND_BOOTS)
.name("&b&lDiamond Boots")
.lore("""
&7Defense: &a+3
&7Price: &6150 coins""")
.build())
// Navigation
.item(3, 0, NavigationUtils.backButton().build())
.item(3, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Creates a consumables shop menu (3rd level).
*/
public static Menu createConsumablesMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("&6&lConsumables Shop")
.rows(4)
.pane(staticPane()
.name("main")
.bounds(0, 0, 4, 9)
// Consumables
.item(1, 1, item()
.material(Material.GOLDEN_APPLE)
.name("&6&lGolden Apple")
.lore("""
&7Restores &c4 hearts
&7Price: &625 coins""")
.build())
.item(1, 2, item()
.material(Material.COOKED_BEEF)
.name("&e&lSteak")
.lore("""
&7Restores &c4 hunger
&7Price: &65 coins""")
.build())
.item(1, 3, item()
.material(Material.POTION)
.name("&d&lHealing Potion")
.lore("""
&7Instant healing
&7Price: &650 coins""")
.build())
// Navigation
.item(3, 0, NavigationUtils.backButton().build())
.item(3, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Creates a settings menu.
*/
public static Menu createSettingsMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("&b&lSettings")
.rows(3)
.pane(staticPane()
.name("main")
.bounds(0, 0, 3, 9)
.item(1, 4, item()
.material(Material.COMPARATOR)
.name("&b&lSettings")
.lore("""
&7This is the settings menu
&7(Work in progress)""")
.build())
// Navigation
.item(2, 0, NavigationUtils.backButton().build())
.item(2, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Creates a profile menu.
*/
public static Menu createProfileMenu(Plugin plugin) {
return Menu.builder(plugin)
.title("&d&lYour Profile")
.rows(3)
.pane(staticPane()
.name("main")
.bounds(0, 0, 3, 9)
.item(1, 4, item()
.material(Material.PLAYER_HEAD)
.name(ctx -> "&d&l" + ctx.getEntity().getName())
.lore("""
&7Level: &a42
&7Coins: &6500
&7Playtime: &e12h 34m""")
.build())
// Navigation
.item(2, 0, NavigationUtils.backButton().build())
.item(2, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Example showing conditional back button visibility.
* The back button only appears if there's navigation history.
*/
public static Menu createConditionalBackButtonExample(Plugin plugin) {
return Menu.builder(plugin)
.title("Conditional Back Button")
.rows(3)
.pane(staticPane()
.name("main")
.bounds(0, 0, 3, 9)
.item(1, 4, item()
.material(Material.COMPASS)
.name("&e&lNavigation Info")
.lore("""
&7Has Previous Menu: &f<has_last>
&7Navigation Depth: &f<depth>
&7The back button only appears
&7when you have navigation history!""",
ctx -> java.util.Map.of(
"has_last", ctx.hasLast() ? "Yes" : "No",
"depth", ctx.navigationDepth()
))
.build())
// Conditional back button - automatically hidden if no history
.item(2, 0, NavigationUtils.backButton()
.lore("""
&7Go back to the previous menu
&eClick to go back!""")
.build())
.item(2, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
}