-
Notifications
You must be signed in to change notification settings - Fork 0
Menu
More info and source code click here
Menus is the main reason why i created this api. Create GUIs in Bukkit
is easy but very repetitive task. Its definitely so if you need to make alot of GUIs. Thats why i create this.
Using a custom menu is easy the player has 4 custom extension functions called openMenu
, closeMenu
, hasMenuOpen
and getOpenMenu
they can be used to use menus. (See below)
player.openMenu(FunMenu())
There are different types of menu mainly a normal
menu and an PagedMenu
When creating a normal GUI you can create a new class and extend UndefinedMenu
this class needs 2 values. The first is title
, the second one is size
witch can be given in two ways by giving a Int
or giving an MenuSize
. When you have done that you will need to extend a method called generateInventory
witch need to return a different method createInventory
. When done you can change the inventory
by using setItem
and more method. (See below for so far)
class FunMenu: UndefinedMenu("FUN", 27) {
override fun generateInventory() = createInventory {
setItem(0, ItemStack(Material.DIAMOND))
}
}
The start of a paged GUI is similar to a normal menu (See above). So the start we are going to be doing quickly. You extend a class called UndefinedPageMenu
then you give the title
, size
and you will see that you need to give a List<ItemStack>
witch if the list of items you want to display. After that you need to extend generateInventory
you don't use createInventory
but you use createPagedInventory
. When you have done that you need to create the back and next buttons you can do this using the setBackButton
and setNextButton
witch ask for PageButton
witch need a slot
and active ItemStack
and a deactive ItemStack
. You are nearly done after that you have done the inventory you need to do the item interaction witch need to be done by extending ClickData.() -> Unit
and this will run every time someone presses a item from the list. (See below)
Note
Menu buttons still work with paged menus
class FunGui(list: List<ItemStack>): UndefinedPageMenu("Fun", MenuSize.LARGE, list) {
override fun generateInventory(): Inventory = createPageInventory {
setBackButton(PageButton(45, ItemStack(Material.RED_STAINED_GLASS_PANE), ItemStack(Material.GRAY_STAINED_GLASS_PANE)))
setNextButton(PageButton(53, ItemStack(Material.LIME_STAINED_GLASS_PANE), ItemStack(Material.GRAY_STAINED_GLASS_PANE)))
setColumn(6, ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).setName(" ").build())
}
override var clickData: ClickData.() -> Unit = {
println("DIAMONDS")
}
}
When doing custom interactions with items you can add a method called addButton
. This method will asks for 1 value called Button
.
This button is very open to do anything with. When creating a simple button it will ask for slot
and give you a Unit.ClickData
witch is a consumer that gives you ClickData
with all the data of the interaction. (See below)
class FunGUI: UndefinedMenu("Fun") {
override fun generateInventory() = createInventory {
addButton(Button(10){
Bukkit.broadcastMessage("Button yeeeeee")
})
}
}
The menu button is a button that will open a different menu when clicked. When creating a new menu button it will ask you to for a slot
and the menu to open when clicked. (See below)
class FunGUI: UndefinedMenu("Fun") {
override fun generateInventory() = createInventory {
addButton(MenuButton(10, DifferntMenu()))
}
}