DISCLAIMER |
---|
The following is a feature only available in Mythic Dungeons 1.3.0+! |
In order to make dungeon elements easy to customize and edit in-game, Mythic Dungeons uses both a chest-based GUI for selecting elements, and a hotbar-based menu for modifying options on those elements.
Browser Menu Buttons
In order for your custom elements to even be accessible by server owners, you must first create a menu button for it. This is done through the provided buildMenuButton()
method.
@Override
public MenuButton buildMenuButton() {
// Create a new menu button that uses the paper item as its base.
MenuButton functionButton = new MenuButton(Material.PAPER);
// Set the display name of the item.
functionButton.setDisplayName("&aMessage Sender");
// Add some lore to describe the function.
functionButton.addLore("&eSends a chat or action bar");
functionButton.addLore("&emessage to the target player(s).");
// Finally, return the button you've created so the menu can use it.
return functionButton;
}
This code produces this menu button.
The Hotbar Menu
Hotbar menus take up a lot of space in the class, however they are relatively straightforward! Simply populate the buildHotbarMenu()
method with options and Mythic Dungeons will do the rest. Let's break it down...
For every option you want to have in the hotbar menu, you need to call menu.addMenuItem
, and then provide details about how your button will behave. There are a couple pre-made menu item types to help simplify the process, or you can make your own.
MenuItem
The default menu entry. All it requires is that you provide a button and some code to run when the button is selected!
menu.addMenuItem(new MenuItem() {
// Build the hotbar menu button. Works similarly to the function's menu button.
// You can also customize the quantity of the item, and whether it's enchanted!
@Override
public void buildButton() {
button = new MenuButton(Material.KNOWLEDGE_BOOK);
button.setDisplayName("&d&lExample Option");
}
// What to do when the button is selected with right-click.
@Override
public void onSelect(PlayerEvent event) {
Player player = event.getPlayer();
player.sendMessage("Player has selected this button!"));
}
});
ChatMenuItem
Chat menu items add an extra option for accepting chat input. Otherwise, they work the same as a normal menu button.
menu.addMenuItem(new ChatMenuItem() {
@Override
public void buildButton() {
button = new MenuButton(Material.MAP);
button.setDisplayName("&d&lEdit Message");
}
@Override
public void onSelect(Player player) {
player.sendMessage(Util.colorize(debugPrefix + "&eWhat should the message say?"));
player.sendMessage(Util.colorize(debugPrefix + "&eCurrent message: &6" + message));
}
// What to do when the player sends a chat message after selecting this button.
@Override
public void onInput(Player player, String message) {
FunctionMessage.this.message = message;
player.sendMessage(Util.colorize(debugPrefix + "&aSet message to '&6" + message + "&a'"));
}
});
Click to see a full example
```java
@Override
public void buildHotbarMenu() {
// First, we add our example menu item.
menu.addMenuItem(new MenuItem() {
@Override
public void buildButton() {
button = new MenuButton(Material.KNOWLEDGE_BOOK);
button.setDisplayName("&d&lExample Option");
}
@Override
public void onSelect(PlayerEvent event) {
Player player = event.getPlayer();
player.sendMessage("Player has selected this button!"));
}
});
// Then, we add our chat menu item. These will appear in the hotbar in the order we add them.
menu.addMenuItem(new ChatMenuItem() {
@Override
public void buildButton() {
button = new MenuButton(Material.MAP);
button.setDisplayName("&d&lEdit Message");
}
@Override
public void onSelect(Player player) {
player.sendMessage(Util.colorize(debugPrefix + "&eWhat should the message say?"));
player.sendMessage(Util.colorize(debugPrefix + "&eCurrent message: &6" + message));
}
@Override
public void onInput(Player player, String message) {
FunctionMessage.this.message = message;
player.sendMessage(Util.colorize(debugPrefix + "&aSet message to '&6" + message + "&a'"));
}
});
}
```
While it may look complicated, this system allows for an enormous amount of flexibility and power when creating menus and customizable options. If you're really clever, you can even create nested hotbar menus and hide-able menu items, such as what's seen in the rewards functions! Play around and get creative!