Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing Toolbar (Pagination) buttons #23

Closed
HeadMonitor opened this issue Apr 13, 2023 · 2 comments
Closed

Customizing Toolbar (Pagination) buttons #23

HeadMonitor opened this issue Apr 13, 2023 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@HeadMonitor
Copy link

Currently as far as I am aware, the Buttons for automatic pages cannot be localised or changed since their lore and names are hardcoded.

Hence a feature I would love to have is the ability to change the lore and names of the buttons.

@SamJakob
Copy link
Owner

SamJakob commented Apr 13, 2023

You should be able to use the Toolbar Customization API to generate and totally customize the toolbar buttons with your own lores, names, items and in slots of your choosing, etc.,

It is expected that most developers would use this API to customize the toolbar, however I haven't found the time to fully document it as it's a new API released a few weeks ago.

There is an example of how this is done here:

myAwesomeMenu.setToolbarBuilder((slot, page, defaultType, menu) -> {
if (slot == 8) {
return new SGButton(
new ItemBuilder(Material.EMERALD)
.name(String.format("&a&l%d gems", gems.getOrDefault(player, 5)))
.lore(
"&aUse gems to buy cosmetics",
"&aand other items in the store!",
"",
"&7&o(Click to add more)"
)
.build()
).withListener((event) -> {
gems.put(player, gems.getOrDefault(player, 5) + 5);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&a&l&oSUCCESS! &aYou have been given &25 &agems!"));
menu.refreshInventory(event.getWhoClicked());
});
}
// Fallback to rendering the default button for a slot.
return spiGUI.getDefaultToolbarBuilder().buildToolbarButton(slot, page, defaultType, menu);
// Or, alternatively, to render a button when NEITHER a custom per-inventory button OR a fallback
// button has been defined:
// (Comment above line and uncomment below to enable this)
/*
// Ensure fallbackButton is not null before rendering. If it is, render an alternative button
// instead.
SGButton fallbackButton = spiGUI.getDefaultToolbarBuilder().buildToolbarButton(slot, page, defaultType, menu);
if (fallbackButton != null) return fallbackButton;
return new SGButton(new ItemBuilder(Material.BARRIER).name(" ").build());
// You could check if defaultType is UNASSIGNED, however this won't deal with the cases when the
// previous or next button is not shown (there will be an empty space).
*/
});

(Please let me know if this solves your issue, if so I'll look to improve documentation on customizing toolbar items by including a more detailed example in the README or wiki).

@SamJakob SamJakob changed the title Add Localization Support Customizing Toolbar (Pagination) buttons Apr 13, 2023
@SamJakob SamJakob self-assigned this Apr 13, 2023
@SamJakob SamJakob added documentation Improvements or additions to documentation question Further information is requested labels Apr 13, 2023
@SamJakob SamJakob pinned this issue Apr 13, 2023
@HeadMonitor
Copy link
Author

This is what I needed, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants