Making more advanced item

To create a right-click event for a custom item, implement the rightClick method from the CustomItem interface. This method uses the PlayerInteractEvent parameter to manage the player's interaction and offers control over the event through options like cancellation.

Here's a breakdown of how it works:

  • PlayerInteractEvent: The event argument provides vital control, allowing you to customize interactions. You can use this to check which action triggered the event and modify or cancel it based on your needs.

  • UUID Handling: The uuid argument is crucial if the CustomItemData has the withUUID option enabled. It ensures unique identification for each item, allowing for specific behaviors for individual items. If withUUID is not enabled, uuid will be null.

In the example above, when a player right-clicks with the custom item, they will receive a "Right click!" message. To ensure your item's behavior is executed, make sure prior events haven't cancelled it unless intentionally desired. Register your item properly in main class.

public class MyItem implements CustomItem {
    @Override
    public void getItemData() {
        // Adding simple description to our item
        SimpleDescBuilder description = new SimpleDescBuilder()
            .addDesc("My awesome description!");
        
        /*
        You can also use List for description.
        Like: ArrayList<String> list = Arrays.asList("First", "second");
        or null if u want nothing.
        */
        CustomItemData data = new CustomItemData("item_id", 
            "Item name", description, Material.IRON_INGOT)
                .withUUID() // Enabled UUID for item
                .asUniqueMaterial(); 
                // Disable using this item in default crafts.
                // By that i mean our item is basicly is iron ingot
                // and can be used in minecraft recipes.
                // This option disables that function.
        
        return data;
    }

    // Right click event.
    // You can also rewrite left click just ask your IDE
    @Override
    public void rightClick(PlayerInteractEvent event, UUID uuid) {
        Player player = event.getPlayer();
        player.sendMessage("Right click!");
    }
}

Last updated