INTRODUCTION
This library will allow you to build menus in a clear and easy way.
This library includes:
- Pagination
- Menu synchronization
- Built in: confirmation & number selector type menus
- Timers, async tasks
- Communication via messaging between menus
To see examples of all of these:
https://github.com/JaimeTruman/Bukkit-better-menus
SETUP
Code (XML):
<repositories>
<repository>
<id>jitpack.io
</id>
<url>https://jitpack.io
</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.JaimeTruman
</groupId>
<artifactId>Bukkit-better-menus
</artifactId>
<version>1.4.0
</version>
</dependency>
</dependencies>
Code (Java):
public
class MyPlugin
extends JavaPlugin
{
@Override
public
void onEnable
(
)
{
BukkitBetterMenus.
setPlugin
(
this
)
;
BukkitBetterMenus.
registerEventListeners
(
this, Bukkit.
getPluginManager
(
)
)
;
BukkitBetterMenus.
setInstanceProvider
(
/*Optional if you have dependency injection library*/
)
;
}
}
Simple example
Every menu will have to extend Menu. The menu generic parameter is the state that the Menu can have, this is optional. A menu will have to implement:
- public int[][] items() Represents the outlay of the menu. It will contain a number which will map to an item.
- public MenuConfiguration configuration() Returns the menu configuration. It will also include the mapping of the numbers to items
Code (Java):
public
class SimpleMenu
extends Menu
<Transaction
>
{
@Override
public
int
[
]
[
] items
(
)
{
return
new
int
[
]
[
]
{
{
1,
1,
1,
1,
1,
1,
1,
1,
1
},
{
1,
0,
2,
0,
0,
0,
0,
9,
1
},
{
1,
1,
1,
1,
1,
1,
1,
1,
1
}
}
;
}
@Override
public MenuConfiguration configuration
(
)
{
return MenuConfiguration.
builder
(
)
.
title
(DARK_RED
+
""
+ BOLD
+
"Simple menu"
)
.
fixedItems
(
)
//Players cannot take items
.
staticMenu
(
)
//Only one instance of inventory will be created
.
item
(
1, Material.
BLACK_STAINED_GLASS_PANE
)
.
item
(
2, buildItemTransaction
(
)
)
.
item
(
9, buildItemClose
(
),
(player, event
)
-> player.
closeInventory
(
)
)
.
onClose
(event
-> event.
getPlayer
(
).
sendMessage
(
"You have closed the inventory"
)
)
.
build
(
)
;
}
private ItemStack buildItemTransaction
(
)
{
return ItemBuilder.
of
(Material.
PAPER
)
.
title
(GOLD
+
""
+ BOLD
+
"Transaction"
)
.
lore
(
Arrays.
asList
(
GOLD
+
"Payer: "
+ getState
(
).
payerName,
GOLD
+
"Payee: "
+ getState
(
).
payeeName,
GOLD
+
"money: "
+ GREEN
+ getState
(
).
money
+
"$"
)
)
.
build
(
)
;
}
private ItemStack buildItemClose
(
)
{
return ItemBuilder.
of
(Material.
BARRIER
)
.
title
(ChatColor.
BOLD
+
""
+ ChatColor.
GOLD
+
"CLOSE"
)
.
build
(
)
;
}
}
public
class Transaction
{
public
String payerName
;
public
String payeeName
;
public
double money
;
}
To open the menu:
Code (Java):
public
void open
(Player player
)
{
MenuService menuService
= BukkitBetterMenus.
MENU_SERVICE
;
Transaction transactionState
=
/**/
;
//A menu can have a state represented by Menu<class of state>
menuService.
open
(player,
new SimpleMenu
(
), transactionState
)
;
//If you have dependency injection library. It will inject the dependencies of the constructor
menuService.
open
(player, SimpleMenu.
class, transactionState
)
;
}
To see pagination, synchronization etc you can find them at:
https://github.com/JaimeTruman/Bukkit-better-menus