Inventories - noobmobile/GroovyBukkitAPI GitHub Wiki
Tired of creating inventories using Bukkit.createInventory() and creating listeners to InventoryClickEvent? GroovyBukkitAPI provides you a great solution.
// or new InventoryHandler(name, size)
def player = ...
menu(name, size)
.item(10, new ItemBuilder(Material.STONE), {player -> player.sendMessage("clicked on item STONE on slot 10")})
.item(new ItemBuilder(Material.DIAMOND), {player -> player.sendMessage("click on item DIAMOND on slot coming from config")})
.items([item1, item2, item3])
.handler({InventoyClickEvent event ->
event.getWhoClicked().sendMessage("custom event handling")
})
.open(player)Another powerful tool from GroovyBukkitAPI.
arenas:
Name: "&5Arenas"
Size: 27
goToArena:
Slot: 10
Material: DIAMOND_SWORD
Name: "&6Go to Arena"
profile:
Slot: 11
Texture: "{playerName}"
Name: "&6You"
Lore:
- "&7You have killed {playerKills} players."
itemTemplate: # if there's no slot, item will be avaliable on inventory.itemTemplate
Material: STONE
Name: "&6I dont know what i am"
Lore:
- "&7how are you {playerName}?" FileConfiguration inventories
def test = { Context context ->
def player = context.player()
def inventory = inventories.arenas.asInventory(
goToArena: { clicker -> clicker.sendMessage("going to the arena") },
profile: { clicker -> clicker.sendMessage("yeah this is you") },
"{playerName}": player.name, "{playerKills}": player.getStatistic(Statistic.MOB_KILLS))
inventory.item(16, inventory.itemTemplate.editPlaceholders("{playerName}": player.name), { clicker -> clicker.sendMessage("this is a template") })
inventory.open(player)
}We use ConfigurationSection.asInventory() passing as a Map<String, Object>. The map contains all the placeholders we use, like {playerName} and {playerKills} and the Closures that are called when a player clicks in a item.
Sets an item on the inventory and execute a closure when a player clicks it
Same as above, without the closure
Sets an item on the ItemStack.slot (this slot comes from the config) and execute a closure when a player clicks it. Throws an exception if there's no field slot in the ItemStack
Same as above, without the closure
Sets a list/array of itemstacks in the center of the inventory (center slots: 10..16, 19..25, 28..34)
Same as above buth with the passed slots
Same as items(itemstacks) and execute a closure with two parameters (player and itemstack)
items(itemList, {player, item -> player.sendMessage("you clicked on $item.type")})If the itemstacks is empty, the ItemStack orElse is added to the list
Sets the slots used by items() and scroller()
Handles when a player click on ItemStack itemConsumer({item, player -> player.sendMessage("clicked on $item.type")})
Handles the InventoryClickEvent with a closure.
Opens the inventory
You can easily create an Scroller Inventory (multiple) pages.
menu("Test Scroller", 36)
.scroller()
.items(itemList, {item, player-> player.sendMessage("this is a $item.type")})
.item(4, new ItemBuilder(Material.DIAMOND).setName("Test Scroller"))
.open(player)scrollerTest:
Name: "&2Scroller Test"
Size: 36
it1:
Slot: 31
Material: BARRIER
Name: "&cClose"
itScroller: # template item
Material: STONE # gonna be changed later
Name: "&6I'm {materialName}"
Scroller: # this whole section is optional, if not provided it'll be used the default settings
Slots: 11,12,13,14,15
PreviousPage:
Slot: 9
Material: STAINED_CLAY
Data: 14
Name: "&aPage <page>"
NextPage:
Slot: 17
Material: STAINED_CLAY
Data: 5
Name: "&aPage <page>" FileConfiguration inventories
def test = { Context context ->
def player = context.player()
InventoryHandler inventory = inventories.scrollerTest.asInventory(it1: { clicker -> clicker.closeInventory() })
inventory.items(Material.values()
.findAll { it.isSolid() }
.collect {
new ItemBuilder(inventory.itScroller.clone())
.setType(it)
.editPlaceholders("{materialName}": it.name().toLowerCase())
.build()
}
)
inventory.itemConsumer({ item, clicker -> clicker.sendMessage("clicked on $item.type") })
inventory.open(player)
}Scroller methods
Enable the scroller mode
Sets the slots of the previous page and next page item
Same as above but for the previous/next page item
slots() itemConsumer() also applies. Call all these before items()