-
Notifications
You must be signed in to change notification settings - Fork 1
PaginatedList Example
Hempfest edited this page Dec 5, 2021
·
7 revisions
This section will soon be updated with the brand new AbstractPaginatedCollection object
private PaginatedList<OfflinePlayer> getTestList(Player p) {
Message msg = Message.form(p);
List<OfflinePlayer> list = new LinkedList<>();
Collections.addAll(list, Bukkit.getOfflinePlayers());
return new PaginatedList<>(list)
.limit(10)
.compare((o1, o2) -> Long.compare(o2.getLastPlayed(), o1.getLastPlayed()))
.start((pagination, page, max) -> p.sendMessage("--------------------"))
.finish((pagination, page, max) -> {
p.sendMessage("--------------------");
TextLib component = TextLib.getInstance();
int next = page + 1;
int last = Math.max(page - 1, 1);
List<BaseComponent> toSend = new LinkedList<>();
if (page == 1) {
if (page == max) {
toSend.add(component.textHoverable("", "&8« ", "You are on the first page already."));
toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
toSend.add(component.textHoverable("", " &8»", "You are already on the last page."));
msg.build(toSend.toArray(new BaseComponent[0]));
return;
}
toSend.add(component.textHoverable("", "&8« ", "You are on the first page already."));
toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
toSend.add(component.execute(() -> t.get(next), component.textHoverable("", " &3»", "")));
msg.build(toSend.toArray(new BaseComponent[0]));
return;
}
if (page == max) {
toSend.add(component.execute(() -> t.get(last), component.textHoverable("", "&3« ", "")));
toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
toSend.add(component.textHoverable("", " &8»", "You are already on the last page."));
msg.build(toSend.toArray(new BaseComponent[0]));
return;
}
if (next <= max) {
toSend.add(component.execute(() -> t.get(last), component.textHoverable("", "&3« ", "")));
toSend.add(component.textHoverable("&f<&7" + page + "&f/&7" + max + "&f>", "", ""));
toSend.add(component.execute(() -> t.get(next), component.textHoverable("", " &3»", "")));
msg.build(toSend.toArray(new BaseComponent[0]));
}
}).decorate((pagination, player, page, max, placement) -> msg.send("&7#&f" + placement + " &6" + player.getName() + " &f&l: &e" + new Date(player.getLastPlayed()).toInstant().atZone(ZoneId.systemDefault()).toLocalDate().toString())).get(1);
}
The above example will provide you with this layout. You only ever need to call the first page and internal programming will take care of taking players to next possible pages.
-
- AFK Player Utility
- Command Builder
- Command Utility
- Complete GUI Builder
- Complete Head Database/Locator
- Cooldown Abstraction
- Custom Gradient Color Interface
- Custom ID Generation
- Directional Enumeration
- Economy Interface Wrapper
- Entity Creation Tools
- File Management
- Item Recipe Builder
- Item Modification Builder
- Legacy Safe NamespacedKey
- Listing Collections
- Material Matcher
- Message Formatter
- String Utility
- Tab Completion Builder
- Task Scheduling
- Template Creation
- TextComponent Builder
- Vault Permission Interface Wrapper