GamerNoobXd

package com.yourname.customweapons;

import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.DragonFireball; 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.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType;

import java.util.*;

public final class Main extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {

private static Main instance; private NamespacedKey weaponKey; private boolean stealEnabled = true; private final Map<String, ItemStack> weaponRegistry = new HashMap<>();

@Override public void onEnable() { instance = this; weaponKey = new NamespacedKey(this, "custom_weapon_id");

// Register events, commands, and tab completer getServer().getPluginManager().registerEvents(this, this); getCommand("sr").setExecutor(this); getCommand("sr").setTabCompleter(this);

// Initialize Weapons and Custom Recipes initWeapons(); registerRecipes();

getLogger().info("CustomWeapons Single-File Plugin enabled successfully for MC 26.2!"); }

@Override public void onDisable() { getLogger().info("CustomWeapons Plugin disabled."); }

public static Main getInstance() { return instance; }

private void initWeapons() { // 1. SOULSTRIKE — Soul Blade ItemStack soulstrike = new ItemStack(Material.NETHERITE_SWORD); ItemMeta meta1 = soulstrike.getItemMeta(); meta1.setDisplayName(ChatColor.DARK_RED + "" + ChatColor.BOLD + "SOULSTRIKE — Soul Blade"); meta1.setLore(Arrays.asList( ChatColor.GRAY + "Legendary Netherite Sword", "", ChatColor.GREEN + "PASSIVE ABILITIES:", ChatColor.DARK_GREEN + "• Resistance: " + ChatColor.WHITE + "Activates for 30s on hit/receive damage[cite: 17]", ChatColor.DARK_GREEN + "• Strength I: " + ChatColor.WHITE + "Permanent while holding[cite: 17]", "", ChatColor.LIGHT_PURPLE + "SPECIAL ABILITIES:", ChatColor.AQUA + "• Sonic Beam: " + ChatColor.YELLOW + "Shift + Left Click (8m CD)[cite: 17]", ChatColor.AQUA + "• Dragon Breath: " + ChatColor.YELLOW + "Right Click (6m CD)[cite: 17]", ChatColor.AQUA + "• Soul Power: " + ChatColor.YELLOW + "Shift + Right Click (3m CD)[cite: 17]" )); meta1.getPersistentDataContainer().set(weaponKey, PersistentDataType.STRING, "soulstrike"); soulstrike.setItemMeta(meta1); weaponRegistry.put("soulstrike", soulstrike);

// 2. GODBREAKER — Ocean Destroyer ItemStack godbreaker = new ItemStack(Material.TRIDENT); ItemMeta meta2 = godbreaker.getItemMeta(); meta2.setDisplayName(ChatColor.AQUA + "" + ChatColor.BOLD + "GODBREAKER — Ocean Destroyer"); meta2.addEnchant(Enchantment.RIPTIDE, 4, true); //[cite: 18] meta2.addEnchant(Enchantment.IMPALING, 5, true); //[cite: 18] meta2.addEnchant(Enchantment.SHARPNESS, 4, true); //[cite: 18] meta2.setLore(Arrays.asList( ChatColor.GRAY + "Water Dominion — Second Strongest Weapon[cite: 18]", "", ChatColor.GOLD + "PASSIVES & ENCHANTS:", ChatColor.YELLOW + "• Riptide IV, Impaling V, Sharpness IV, Strength II[cite: 18]", ChatColor.YELLOW + "• Water Breathing: Unlimited while held[cite: 18]", "", ChatColor.LIGHT_PURPLE + "SPECIAL ABILITIES:", ChatColor.AQUA + "• Water Tornado: Right-click in water (10m CD)[cite: 18]" )); meta2.getPersistentDataContainer().set(weaponKey, PersistentDataType.STRING, "godbreaker"); godbreaker.setItemMeta(meta2); weaponRegistry.put("godbreaker", godbreaker); }

private void registerRecipes() { // Soulstrike Recipe[cite: 17] NamespacedKey recipeKey1 = new NamespacedKey(this, "soulstrike_recipe"); ShapedRecipe recipe1 = new ShapedRecipe(recipeKey1, weaponRegistry.get("soulstrike")); recipe1.shape("BTB", "ESE", "ITI"); //[cite: 17] recipe1.setIngredient('B', Material.BLAZE_ROD); //[cite: 17] recipe1.setIngredient('T', Material.TOTEM_OF_UNDYING); //[cite: 17] recipe1.setIngredient('E', Material.EYE_OF_ENDER); //[cite: 17] recipe1.setIngredient('S', Material.NETHERITE_SWORD); //[cite: 17] recipe1.setIngredient('I', Material.NETHERITE_INGOT); //[cite: 17] Bukkit.addRecipe(recipe1);

// Godbreaker Recipe[cite: 18] NamespacedKey recipeKey2 = new NamespacedKey(this, "godbreaker_recipe"); ShapedRecipe recipe2 = new ShapedRecipe(recipeKey2, weaponRegistry.get("godbreaker")); recipe2.shape("NIN", "WWS", "ETE"); //[cite: 18] recipe2.setIngredient('N', Material.NETHERITE_INGOT); //[cite: 18] recipe2.setIngredient('I', Material.DIAMOND_BLOCK); //[cite: 18] recipe2.setIngredient('W', Material.POTION); //[cite: 18] recipe2.setIngredient('S', Material.WITHER_SKELETON_SKULL); //[cite: 18] recipe2.setIngredient('E', Material.ECHO_SHARD); //[cite: 18] recipe2.setIngredient('T', Material.TRIDENT); //[cite: 18] Bukkit.addRecipe(recipe2); }

// --- COMMANDS & TAB COMPLETE (/sr) --- @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length == 0) { sender.sendMessage(ChatColor.YELLOW + "Usage: /sr <give|take|steal|weapons>"); //[cite: 11, 12] return true; }

String sub = args[0].toLowerCase(); if (sub.equals("give")) { if (args.length < 3) { sender.sendMessage(ChatColor.RED + "Usage: /sr give <player> <weapon>"); //[cite: 11] return true; } Player target = Bukkit.getPlayer(args[1]); if (target == null) { sender.sendMessage(ChatColor.RED + "Player not found!"); return true; } ItemStack item = weaponRegistry.get(args[2].toLowerCase()); if (item == null) { sender.sendMessage(ChatColor.RED + "Invalid weapon ID! Available: soulstrike, godbreaker"); //[cite: 11] return true; } target.getInventory().addItem(item.clone()); sender.sendMessage(ChatColor.GREEN + "Gave " + args[2] + " to " + target.getName()); return true; }

if (sub.equals("take")) { if (args.length < 3) { sender.sendMessage(ChatColor.RED + "Usage: /sr take <player> <weapon>"); //[cite: 11] return true; } Player target = Bukkit.getPlayer(args[1]); if (target != null) { for (ItemStack item : target.getInventory().getContents()) { if (item != null && item.hasItemMeta()) { String id = item.getItemMeta().getPersistentDataContainer().get(weaponKey, PersistentDataType.STRING); if (args[2].equalsIgnoreCase(id)) { target.getInventory().remove(item); } } } sender.sendMessage(ChatColor.GREEN + "Removed weapon from " + target.getName()); //[cite: 11] } return true; }

if (sub.equals("steal")) { if (args.length > 1) { if (args[1].equalsIgnoreCase("on")) { stealEnabled = true; sender.sendMessage(ChatColor.GREEN + "Weapon Stealing enabled."); //[cite: 12] } else if (args[1].equalsIgnoreCase("off")) { stealEnabled = false; sender.sendMessage(ChatColor.RED + "Weapon Stealing disabled."); //[cite: 12] } } return true; }

if (sub.equals("weapons")) { sender.sendMessage(ChatColor.GOLD + "Registered Weapons: soulstrike, godbreaker"); //[cite: 11] return true; }

return true; }

@Override public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { if (args.length == 1) { return Arrays.asList("give", "take", "steal", "weapons"); //[cite: 11, 12] } if (args.length == 3 && (args[0].equalsIgnoreCase("give") || args[0].equalsIgnoreCase("take"))) { return new ArrayList<>(weaponRegistry.keySet()); } return null; }

// --- EVENT LISTENERS (Passives, Abilities, Steal) --- @EventHandler public void onCombat(EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Player attacker) { ItemStack item = attacker.getInventory().getItemInMainHand(); if (item.hasItemMeta() && "soulstrike".equals(item.getItemMeta().getPersistentDataContainer().get(weaponKey, PersistentDataType.STRING))) { attacker.addPotionEffect(new PotionEffect(PotionEffectType.RESISTANCE, 600, 0)); // 30s Resistance[cite: 17] } } if (event.getEntity() instanceof Player victim) { ItemStack item = victim.getInventory().getItemInMainHand(); if (item.hasItemMeta() && "soulstrike".equals(item.getItemMeta().getPersistentDataContainer().get(weaponKey, PersistentDataType.STRING))) { victim.addPotionEffect(new PotionEffect(PotionEffectType.RESISTANCE, 600, 0)); // 30s Resistance[cite: 17] } } }

@EventHandler public void onInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInMainHand(); if (item == null || !item.hasItemMeta()) return;

String weaponId = item.getItemMeta().getPersistentDataContainer().get(weaponKey, PersistentDataType.STRING); if (weaponId == null) return;

Action action = event.getAction(); boolean isShift = player.isSneaking();

// Soulstrike Abilities[cite: 17] if (weaponId.equals("soulstrike")) { if (isShift && (action == Action.LEFT_CLICK_AIR || action == Action.LEFT_CLICK_BLOCK)) { player.sendMessage(ChatColor.AQUA + "Sonic Beam activated!"); //[cite: 17] player.getWorld().playSound(player.getLocation(), Sound.ENTITY_WARDEN_SONIC_BOOM, 1.0f, 1.0f); } else if (!isShift && (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)) { player.launchProjectile(DragonFireball.class); //[cite: 17] player.sendMessage(ChatColor.DARK_PURPLE + "Dragon Breath launched!"); //[cite: 17] } else if (isShift && (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK)) { player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 3600, 1)); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 3600, 1)); player.sendMessage(ChatColor.LIGHT_PURPLE + "Soul Power Activated (Strength II + Speed II)"); //[cite: 17] } }

// Godbreaker Abilities[cite: 18] if (weaponId.equals("godbreaker")) { if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { if (player.getLocation().getBlock().getType() == Material.WATER) { player.sendMessage(ChatColor.BLUE + "Water Tornado Activated!"); //[cite: 18] player.getWorld().spawnParticle(Particle.WATER_SPLASH, player.getLocation(), 150, 2, 2, 2); } } } }

@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { if (!stealEnabled) return; //[cite: 12] Player victim = event.getEntity(); Player killer = victim.getKiller(); if (killer == null) return; //[cite: 12]

List<ItemStack> stolen = new ArrayList<>(); for (ItemStack drop : event.getDrops()) { if (drop.hasItemMeta() && drop.getItemMeta().getPersistentDataContainer().has(weaponKey, PersistentDataType.STRING)) { stolen.add(drop); } }

for (ItemStack item : stolen) { event.getDrops().remove(item); //[cite: 12] killer.getInventory().addItem(item); //[cite: 12] killer.sendMessage(ChatColor.GOLD + "[Weapon Steal] You stole a custom weapon from " + victim.getName() + "!"); //[cite: 12] } } }

Kodari AI
KodariNov 1 at 9:09 am 1
SoulStrikeWeapons
A Minecraft plugin introducing two legendary custom weapons with unique abilities. Soulstrike, a netherite sword, grants resistance on combat, permanent strength, and three special attacks including sonic beam, dragon breath, and soul power. Godbreaker, an enchanted trident, provides water breathing, enhanced combat stats, and a water tornado ability. Features custom crafting recipes, a /sr command system for giving, taking, and toggling weapon stealing on player death, plus tab completion support. Uses persistent data containers for weapon identification and includes particle effects, sounds, and cooldown-based abilities for immersive gameplay.
  1. Create the Gradle/Paper plugin scaffold and /sr command metadata.

  2. Implement both custom weapons, recipes, abilities, passives, cooldowns, and weapon stealing in the main class.

Created the CustomWeapons Paper plugin scaffold and implemented /sr commands, both weapon recipes and passives, abilities with cooldowns, and weapon stealing on player death. It targets Paper 1.21.4 with Java 21.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 475
src/main/java/com/yourname/customweapons/Main.java
package com.yourname.customweapons;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.DragonFireball;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
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.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

public final class Main extends JavaPlugin implements Listener, CommandExecutor, TabCompleter {

    private NamespacedKey weaponKey;
    private boolean stealEnabled = true;
    private final Map<String, ItemStack> weaponRegistry = new HashMap<>();
    private final Map<UUID, Map<String, Long>> cooldowns = new HashMap<>();

    @Override
    public void onEnable() {
        weaponKey = new NamespacedKey(this, "custom_weapon_id");
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("sr").setExecutor(this);
        getCommand("sr").setTabCompleter(this);

        initWeapons();
        registerRecipes();
        startPassiveTask();
        getLogger().info("CustomWeapons enabled.");
    }

    @Override
    public void onDisable() {
        cooldowns.clear();
        getLogger().info("CustomWeapons disabled.");
    }

    private void initWeapons() {
        ItemStack soulstrike = createWeapon("NETHERITE_SWORD", "soulstrike",
            ChatColor.DARK_RED + "" + ChatColor.BOLD + "SOULSTRIKE — Soul Blade",
            Arrays.asList(
                ChatColor.GRAY + "Legendary Netherite Sword",
                "",
                ChatColor.GREEN + "PASSIVE ABILITIES:",
                ChatColor.DARK_GREEN + "• Resistance: " + ChatColor.WHITE + "30s on hit or when hit",
                ChatColor.DARK_GREEN + "• Strength I: " + ChatColor.WHITE + "While held",
                "",
                ChatColor.LIGHT_PURPLE + "SPECIAL ABILITIES:",
                ChatColor.AQUA + "• Sonic Beam: " + ChatColor.YELLOW + "Shift + Left Click (8m cooldown)",
                ChatColor.AQUA + "• Dragon Breath: " + ChatColor.YELLOW + "Right Click (6m cooldown)",
                ChatColor.AQUA + "• Soul Power: " + ChatColor.YELLOW + "Shift + Right Click (3m cooldown)"
            ));
        if (soulstrike != null) {
            weaponRegistry.put("soulstrike", soulstrike);
        }

        ItemStack godbreaker = createWeapon("TRIDENT", "godbreaker",
            ChatColor.AQUA + "" + ChatColor.BOLD + "GODBREAKER — Ocean Destroyer",
            Arrays.asList(
                ChatColor.GRAY + "Water Dominion — Second Strongest Weapon",
                "",
                ChatColor.GOLD + "PASSIVES & ENCHANTS:",
                ChatColor.YELLOW + "• Riptide IV, Impaling V, Sharpness IV, Strength II",
                ChatColor.YELLOW + "• Water Breathing: While held",
                "",
                ChatColor.LIGHT_PURPLE + "SPECIAL ABILITIES:",
                ChatColor.AQUA + "• Water Tornado: " + ChatColor.YELLOW + "Right-click in water (10m cooldown)"
            ));
        if (godbreaker != null) {
            ItemMeta meta = godbreaker.getItemMeta();
            addEnchantment(meta, "RIPTIDE", 4);
            addEnchantment(meta, "IMPALING", 5);
            addEnchantment(meta, "SHARPNESS", 4);
            godbreaker.setItemMeta(meta);
            weaponRegistry.put("godbreaker", godbreaker);
        }
    }

    private ItemStack createWeapon(String materialName, String id, String displayName, List<String> lore) {
        ItemStack item = XMaterial.matchXMaterial(materialName).map(XMaterial::parseItem).orElse(null);
        if (item == null) {
            getLogger().warning("Could not create weapon " + id + ": material " + materialName + " is unavailable.");
            return null;
        }

        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            return null;
        }
        meta.setDisplayName(displayName);
        meta.setLore(lore);
        meta.getPersistentDataContainer().set(weaponKey, PersistentDataType.STRING, id);
        item.setItemMeta(meta);
        return item;
    }

    private void addEnchantment(ItemMeta meta, String name, int level) {
        XEnchantment.matchXEnchantment(name).ifPresent(enchantment ->
            meta.addEnchant(enchantment.getEnchant(), level, true));
    }

    private void registerRecipes() {
        ItemStack soulstrike = weaponRegistry.get("soulstrike");
        if (soulstrike != null) {
            ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "soulstrike_recipe"), soulstrike);
            recipe.shape("BTB", "ESE", "ITI");
            if (setIngredient(recipe, 'B', "BLAZE_ROD")
                && setIngredient(recipe, 'T', "TOTEM_OF_UNDYING")
                && setIngredient(recipe, 'E', "EYE_OF_ENDER")
                && setIngredient(recipe, 'S', "NETHERITE_SWORD")
                && setIngredient(recipe, 'I', "NETHERITE_INGOT")) {
                Bukkit.addRecipe(recipe);
            }
        }

        ItemStack godbreaker = weaponRegistry.get("godbreaker");
        if (godbreaker != null) {
            ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "godbreaker_recipe"), godbreaker);
            recipe.shape("NIN", "WWS", "ETE");
            if (setIngredient(recipe, 'N', "NETHERITE_INGOT")
                && setIngredient(recipe, 'I', "DIAMOND_BLOCK")
                && setIngredient(recipe, 'W', "POTION")
                && setIngredient(recipe, 'S', "WITHER_SKELETON_SKULL")
                && setIngredient(recipe, 'E', "ECHO_SHARD")
                && setIngredient(recipe, 'T', "TRIDENT")) {
                Bukkit.addRecipe(recipe);
            }
        }
    }

    private boolean setIngredient(ShapedRecipe recipe, char symbol, String materialName) {
        Optional<Material> material = XMaterial.matchXMaterial(materialName)
            .map(XMaterial::parseMaterial);
        if (material.isEmpty()) {
            getLogger().warning("Recipe ingredient unavailable: " + materialName);
            return false;
        }
        recipe.setIngredient(symbol, material.get());
        return true;
    }

    private void startPassiveTask() {
        Bukkit.getScheduler().runTaskTimer(this, () -> {
            for (Player player : Bukkit.getOnlinePlayers()) {
                String weaponId = getWeaponId(player.getInventory().getItemInMainHand());
                if ("soulstrike".equals(weaponId)) {
                    applyPotion(player, "STRENGTH", 40, 0);
                } else if ("godbreaker".equals(weaponId)) {
                    applyPotion(player, "STRENGTH", 40, 1);
                    applyPotion(player, "WATER_BREATHING", 40, 0);
                }
            }
        }, 0L, 20L);
    }

    private void applyPotion(Player player, String potionName, int duration, int amplifier) {
        XPotion.matchXPotion(potionName)
            .map(potion -> potion.buildPotionEffect(duration, amplifier))
            .ifPresent(effect -> player.addPotionEffect(effect, true));
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 0) {
            sender.sendMessage(ChatColor.YELLOW + "Usage: /sr <give|take|steal|weapons>");
            return true;
        }