Crea bottone/tasto
How to create a button
The code for this example can be found here: https://github.com/Maxlego08/zMenuExample/tree/master
If you need a more concrete example you can look at the zShop source: https://github.com/Maxlego08/zShop/tree/master
Button
This documentation guides you through creating a SpecialButton for use in your plugin, utilizing the SpecialButton.java class to implement custom click actions. This example is the typical case of a very simple button.
Overview
SpecialButton extends ZButton from the fr.maxlego08.menu API to customize the button's behavior on click events. It's designed to close the player's inventory interface, send a custom message, and apply a "jump" or "boost" effect to the player's velocity.
Prerequisites
Ensure you have the fr.maxlego08.menu API included in your project to use ZButton and other required classes.
Implementation Steps
Step 1: Define the SpecialButton Class
Create a class named SpecialButton that extends ZButton. This class will override the onClick method to define the button's behavior.
public class SpecialButton extends ZButton {
// Method implementation
}Step 2: Override the onClick Method
In the SpecialButton class, override the onClick method to specify the actions that occur when the button is clicked. This includes closing the player's inventory, sending a custom message, and applying a velocity change to simulate a jump.
Step 3: Implement Custom Actions
Within the onClick method, add the logic for the custom actions:
Close the Inventory Interface: Use
player.closeInventory()to close the inventory interface.Send a Custom Message to the Player: Use
player.sendMessage("§fWhoosshh")to send a custom message.Modify the Player's Velocity:
Retrieve the current velocity:
Vector vector = player.getVelocity().Modify the velocity to add an upward motion:
vector.add(new Vector(0, 2, 0)).Apply the new velocity:
player.setVelocity(vector).
Step 4: Regitser the SpecialButton
To register the SpecialButton in your plugin, instantiate it and add it to your inventory layout where needed. Ensure that the inventory system you're using supports custom button actions.
This method allows to save a button very quickly without having to create a new loader. You must specify the plugin from where the plugin comes from, the button class and the name. For the name of the button it is advisable to prefix the name of your plugin.
Result
Paginate Button
This documentation outlines how to implement a ExamplePaginateButton for creating a paginated inventory interface in your plugin, using the provided ExamplePaginateButton.java class as a basis.
Overview
ExamplePaginateButton leverages the PaginateButton interface from the fr.maxlego08.menu.api to offer pagination functionality, allowing items to be displayed across multiple inventory pages.
Prerequisites
Include the
fr.maxlego08.menuAPI in your project.Understand basic concepts of inventory manipulation in Bukkit/Spigot plugins.
Implementation Steps
Step 1: Extend ZButton and Implement PaginateButton
Your ExamplePaginateButton should extend ZButton and implement PaginateButton, enabling special render behavior and pagination:
We use Plugin instead of ExamplePlugin because the NoneLoader class, which is responsible for button registration, requires a constructor parameter of the plugin. Since NoneLoader is designed to work with the general Plugin interface from Spigot, it ensures compatibility with any Spigot plugin. Casting to the specific ExamplePlugin class is then performed to access its unique functionalities. This approach maintains flexibility and adherence to Spigot's plugin architecture.
Step 2: Override hasSpecialRender
Indicate that your button uses custom rendering logic for pagination:
Step 3: Implement Custom Rendering Logic
Override the onRender method to define how items are displayed based on the current page:
Step 4: Define Pagination Size
Implement getPaginationSize to specify the total number of items for pagination. This directly influences the number of pages within the inventory, allowing for dynamic list management. Changes in the list size will automatically adjust the pagination, making this method a key component in handling variable amounts of data efficiently in the inventory UI.
Step 5: Regitser the SpecialButton
To register the ExamplePaginateButton in your plugin, instantiate it and add it to your inventory layout where needed. Ensure that the inventory system you're using supports custom button actions.
This method allows to save a button very quickly without having to create a new loader. You must specify the plugin from where the plugin comes from, the button class and the name. For the name of the button it is advisable to prefix the name of your plugin.
Result
Custom Button Loader
You can create your own button loader if your button needs more settings. Just create a class that will implement ButtonLoader. All you have to do is implement the methods, here is an example from zShop.
Last updated