-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPaginationExample.java
More file actions
247 lines (229 loc) · 10.9 KB
/
PaginationExample.java
File metadata and controls
247 lines (229 loc) · 10.9 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
package eu.okaeri.menu.test.example;
import eu.okaeri.menu.Menu;
import eu.okaeri.menu.navigation.NavigationUtils;
import eu.okaeri.menu.pane.pagination.PaginationFilter;
import eu.okaeri.menu.pane.pagination.PaginationUtils;
import eu.okaeri.menu.pane.PaginatedPane;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Material;
import org.bukkit.plugin.Plugin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static eu.okaeri.menu.item.MenuItem.item;
import static eu.okaeri.menu.pane.StaticPane.staticPane;
/**
* Examples demonstrating the pagination system (Phase 3).
* Shows how to create menus with paginated content, filtering, and navigation.
*/
public class PaginationExample {
/**
* Simple example: Paginate a list of strings.
*/
public static Menu createSimplePaginatedMenu(Plugin plugin) {
// Create some sample data
List<String> items = Arrays.asList(
"Apple", "Apricot", "Avocado", "Banana", "Blackberry",
"Blueberry", "Cherry", "Coconut", "Cranberry", "Date",
"Dragonfruit", "Elderberry", "Fig", "Grapefruit", "Grape",
"Guava", "Honeydew", "Jackfruit", "Kiwi", "Kumquat",
"Lemon", "Lime", "Lychee", "Mango", "Mandarin",
"Mulberry", "Nectarine", "Orange", "Papaya", "Passionfruit",
"Peach", "Pear", "Persimmon", "Pineapple", "Plum",
"Pomegranate", "Quince", "Raspberry", "Starfruit", "Strawberry",
"Tangerine", "Watermelon", "Acai", "Boysenberry", "Cantaloupe",
"Clementine", "Currant", "Gooseberry", "Huckleberry", "Jabuticaba",
"Longan", "Loquat", "Rambutan", "Soursop", "Tamarind"
);
return Menu.builder(plugin)
.title("&6Fruit List")
.rows(6)
.pane(PaginatedPane.<String>pane()
.name("content")
.bounds(0, 0, 5, 9) // 5 rows for content
.items(items)
// itemsPerPage defaults to pane size (9x5 = 45 slots)
.renderer((ctx, fruit, index) -> item()
.material(Material.APPLE) // Could map different materials
.name("&e" + fruit)
.lore("""
&7Index: &f%d
&eClick for more info!""".formatted(index))
.onClick(event -> {
event.sendMessage("&aYou selected: " + fruit);
})
.build())
.build())
// Navigation row (bottom row)
.pane(staticPane()
.name("nav")
.bounds(5, 0, 1, 9)
.item(0, 3, PaginationUtils.previousPageButton("content").build())
.item(0, 4, PaginationUtils.pageIndicator("content").build())
.item(0, 5, PaginationUtils.nextPageButton("content").build())
.item(0, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
/**
* Example with static items in paginated pane.
* Shows how to reserve slots for buttons within the paginated area.
*/
public static Menu createPaginatedWithStaticItems(Plugin plugin) {
List<String> players = Arrays.asList(
"Player1", "Player2", "Player3", "Player4", "Player5",
"Player6", "Player7", "Player8", "Player9", "Player10",
"Player11", "Player12", "Player13", "Player14", "Player15"
);
return Menu.builder(plugin)
.title("&bPlayer List")
.rows(4)
.pane(PaginatedPane.<String>pane()
.name("players")
.bounds(0, 0, 4, 9)
.items(players)
.renderer((ctx, playerName, index) -> item()
.material(Material.PLAYER_HEAD)
.name("&a" + playerName)
.lore("""
&7Status: &aOnline
&eClick to view profile!""")
.build())
// Static buttons in the paginated area
.item(3, 7, PaginationUtils.previousPageButton("players").build())
.item(3, 8, PaginationUtils.nextPageButton("players").build())
.build())
.build();
}
/**
* Advanced example: Player profile browser with search/filter.
*/
public static Menu createPlayerBrowser(Plugin plugin) {
List<PlayerProfile> profiles = createPlayerProfiles();
return Menu.builder(plugin)
.title("&d&lPlayer Browser")
.rows(6)
// Filter controls
.pane(staticPane()
.name("filters")
.bounds(0, 0, 1, 9)
.item(0, 1, PaginationUtils.<PlayerProfile>filterButton(
"profiles",
"online",
"&aOnline Only",
profile -> profile.isOnline()
).build())
.item(0, 2, PaginationUtils.<PlayerProfile>filterButton(
"profiles",
"vip",
"&6VIP Players",
profile -> profile.isVip()
).build())
.item(0, 3, PaginationUtils.<PlayerProfile>filterButton(
"profiles",
"highlevel",
"&bLevel 50+",
PaginationFilter.min(PlayerProfile::getLevel, 50)
).build())
.item(0, 7, PaginationUtils.clearFiltersButton("profiles").build())
.item(0, 8, PaginationUtils.emptyIndicator("profiles").build())
.build())
// Player list
.pane(PaginatedPane.<PlayerProfile>pane()
.name("profiles")
.bounds(1, 0, 4, 9)
.items(profiles)
// itemsPerPage defaults to pane size (9x4 = 36 slots)
.renderer((ctx, profile, index) -> item()
.material(profile.isOnline() ? Material.LIME_WOOL : Material.GRAY_WOOL)
.name((profile.isOnline() ? "&a" : "&7") + profile.getName())
.lore("""
&7Level: &f%d
&7Status: %s
%s
&eClick for details!""".formatted(
profile.getLevel(),
profile.isOnline() ? "&aOnline" : "&7Offline",
profile.isVip() ? "&6VIP Member" : "&7Regular Member"
))
.glint(profile.isVip())
.build())
.build())
// Navigation
.pane(staticPane()
.name("nav")
.bounds(5, 0, 1, 9)
.item(0, 3, PaginationUtils.previousPageButton("profiles").build())
.item(0, 4, PaginationUtils.pageIndicator("profiles").build())
.item(0, 5, PaginationUtils.nextPageButton("profiles").build())
.item(0, 8, NavigationUtils.closeButton().build())
.build())
.build();
}
// ========================================
// HELPER CLASSES
// ========================================
@Getter
@AllArgsConstructor
public static class PlayerProfile {
private final String name;
private final int level;
private final boolean online;
private final boolean vip;
}
private static List<PlayerProfile> createPlayerProfiles() {
List<PlayerProfile> profiles = new ArrayList<>();
profiles.add(new PlayerProfile("Alice", 45, true, false));
profiles.add(new PlayerProfile("Bob", 67, true, true));
profiles.add(new PlayerProfile("Charlie", 23, false, false));
profiles.add(new PlayerProfile("Diana", 89, true, true));
profiles.add(new PlayerProfile("Eve", 12, false, false));
profiles.add(new PlayerProfile("Frank", 56, true, false));
profiles.add(new PlayerProfile("Grace", 78, false, true));
profiles.add(new PlayerProfile("Henry", 34, true, false));
profiles.add(new PlayerProfile("Iris", 90, true, true));
profiles.add(new PlayerProfile("Jack", 15, false, false));
profiles.add(new PlayerProfile("Kelly", 42, true, false));
profiles.add(new PlayerProfile("Liam", 58, true, true));
profiles.add(new PlayerProfile("Maya", 31, false, false));
profiles.add(new PlayerProfile("Nathan", 74, true, false));
profiles.add(new PlayerProfile("Olivia", 19, false, false));
profiles.add(new PlayerProfile("Peter", 63, true, true));
profiles.add(new PlayerProfile("Quinn", 27, true, false));
profiles.add(new PlayerProfile("Rachel", 85, false, true));
profiles.add(new PlayerProfile("Sam", 38, true, false));
profiles.add(new PlayerProfile("Tara", 52, true, true));
profiles.add(new PlayerProfile("Uma", 11, false, false));
profiles.add(new PlayerProfile("Victor", 69, true, false));
profiles.add(new PlayerProfile("Wendy", 44, false, false));
profiles.add(new PlayerProfile("Xavier", 91, true, true));
profiles.add(new PlayerProfile("Yuki", 25, true, false));
profiles.add(new PlayerProfile("Zara", 77, false, true));
profiles.add(new PlayerProfile("Adam", 33, true, false));
profiles.add(new PlayerProfile("Bella", 48, true, false));
profiles.add(new PlayerProfile("Carlos", 62, false, true));
profiles.add(new PlayerProfile("Daphne", 29, true, false));
profiles.add(new PlayerProfile("Ethan", 54, true, true));
profiles.add(new PlayerProfile("Fiona", 17, false, false));
profiles.add(new PlayerProfile("George", 71, true, false));
profiles.add(new PlayerProfile("Hannah", 39, true, true));
profiles.add(new PlayerProfile("Isaac", 81, false, false));
profiles.add(new PlayerProfile("Julia", 26, true, false));
profiles.add(new PlayerProfile("Kyle", 55, true, true));
profiles.add(new PlayerProfile("Luna", 13, false, false));
profiles.add(new PlayerProfile("Mason", 68, true, false));
profiles.add(new PlayerProfile("Nina", 46, false, true));
profiles.add(new PlayerProfile("Oscar", 92, true, true));
profiles.add(new PlayerProfile("Paige", 21, true, false));
profiles.add(new PlayerProfile("Quincy", 59, false, false));
profiles.add(new PlayerProfile("Riley", 35, true, false));
profiles.add(new PlayerProfile("Sophia", 73, true, true));
profiles.add(new PlayerProfile("Tyler", 28, false, false));
profiles.add(new PlayerProfile("Ursula", 64, true, false));
profiles.add(new PlayerProfile("Violet", 41, true, true));
profiles.add(new PlayerProfile("Wade", 16, false, false));
profiles.add(new PlayerProfile("Xena", 87, true, true));
return profiles;
}
}