Git Product home page Git Product logo

Comments (2)

SamJakob avatar SamJakob commented on September 17, 2024

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).

from spigui.

HeadMonitor avatar HeadMonitor commented on September 17, 2024

This is what I needed, thank you!

from spigui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.