Search code examples
javabukkit

How do you create a custom item in Spigot 1.16.5?


I'm making a plugin that adds some useful items like House Building Wand, Exploding Sword, etc. But how can I add those items using the plugin?


Solution

  • Normally, you would want to make a class for your item. For example, you can make a class HouseBuildingWand.java and add some Java logic in it.

    public class HouseBuildingWand {
      public static ItemStack getHouseBuildingWand() {
        ItemStack houseBuildingWand = new ItemStack(Material.YOUR_ITEM);
        return houseBuildingWand;
      }
    }
    

    To make the ability, you have to use Java knowledge. To add enchantments, flags, lore, names, check out https://bukkit.gamepedia.com/Plugin_Tutorial#Item_Manipulation. To get the item, you would need a command or an event that would give you the item.

    To check how the item was clicked, you can use an event listener with the event PlayerInteractEvent. Example:

        @EventHandler
        public void onRightClick (PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if (event.getAction() == Action.RIGHT_CLICK_AIR) {
                if (event.getItem().getType() == Material.YOUR_ITEM) {
                    // insert logic
                }
            }
        }