Bierwall

Can you create wand that shoots fireballs?

Kodari AI
KodariOct 8 at 4:35 am 1
FireballWand
FireballWand is a Minecraft plugin that adds a craftable wand item capable of launching explosive fireballs. Players can obtain the wand through a custom recipe, then right-click to shoot a fireball in the direction they're facing. The plugin features configurable cooldown periods to prevent spam, configurable explosion power, and optional permission-based access. Fireballs ignite targets and cause area damage, making it ideal for PvP arenas or creative gameplay. The wand uses durability to limit usage, with configurable max uses before breaking. Includes full configuration file for adjusting cooldown, power, and recipe materials, plus localization messages for player feedback.
  1. Create the Paper plugin setup.

  2. Add /firewand to give a marked blaze-rod wand.

  3. Make right-click shoot a fireball.

Created the FireWand plugin. Use /firewand to get a blaze-rod wand, then right-click to shoot a fireball.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 114
src/main/java/com/kodari/firewand/FireWandPlugin.java
package com.kodari.firewand;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

public class FireWandPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private NamespacedKey wandKey;

    @Override
    public void onEnable() {
        wandKey = new NamespacedKey(this, "fire_wand");
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("firewand").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage("Only players can use this command.");
            return true;
        }

        ItemStack wand = XMaterial.matchXMaterial("BLAZE_ROD")
                .map(XMaterial::parseItem)
                .orElse(null);
        if (wand == null) {
            player.sendMessage(ChatColor.RED + "Could not create the fire wand.");
            return true;
        }

        ItemMeta meta = wand.getItemMeta();
        meta.setDisplayName(ChatColor.GOLD + "Fire Wand");
        meta.getPersistentDataContainer().set(wandKey, PersistentDataType.BYTE, (byte) 1);
        wand.setItemMeta(meta);
        player.getInventory().addItem(wand);
        player.sendMessage(ChatColor.GREEN + "You received a Fire Wand! Right-click to shoot.");
        return true;
    }

    @EventHandler
    public void onWandUse(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND) {
            return;
        }
        Action action = event.getAction();
        if (action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) {
            return;
        }

        ItemStack item = event.getItem();
        if (item == null || !item.hasItemMeta()) {
            return;
        }
        Byte marker = item.getItemMeta().getPersistentDataContainer().get(wandKey, PersistentDataType.BYTE);
        if (marker == null || marker != (byte) 1) {
            return;
        }

        event.setCancelled(true);
        Player player = event.getPlayer();
        Vector direction = player.getEyeLocation().getDirection().normalize();
        Fireball fireball = player.getWorld().spawn(
                player.getEyeLocation().add(direction.clone().multiply(1.2)), Fireball.class);
        fireball.setDirection(direction);
        fireball.setShooter(player);
        fireball.setIsIncendiary(true);
        fireball.setYield(1.0F);
    }
}