Create your own Widget - worldOneo/GUI-API GitHub Wiki
What is a widget?
A widget is just a class which implements the interface "IWidget".
The most import function is the ItemStack render(); function it defines the look of the widget.
Create your own
It is recommended to extend from AbstractWidget and not to implement directly from IWidget as the AbstractWidget comes with some nice to have methods like the addToGUI(IGUI igui) and open(Player player) which allow the widget to reopen the GUI from within the widget!
lets create a simple "give me a cookie widget"!
public class CookieWidget extends AbstractWidget {
public ItemStack render(){
ItemStack itemStack = new ItemStack(Material.COOKIE); //Create a cookie
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.setDisplayName("Click4Cookie"); //Rename the cookie
itemStack.setItemMeta(itemMeta);
return itemStack; //return the cookie
}
public void clickEvent(InventoryClickEvent e){
e.getWhoClicked().getInventory().addItem(new ItemStack(Material.COOKIE));
e.setCancelled(true);
}
}
Done
Now you can add your widget like the button wiget from the tutorial Your first GUI. (Except you dont have to set the material!)