not_cvr

Act as an expert Minecraft Java Plugin Developer. Create a single, fully functional, build-ready Java source code file along with the plugin.yml for a PaperMC 1.21.11 server.

Requirements for the custom weapon:

  1. Item Base & Name:

- Base Material: STONE_SWORD - Display Name: "§6§lGod Stone Sword" - Lore: Custom lore text explaining its powerful abilities.

  1. True Damage Mechanics (On Hit):

- Every melee attack with this sword must deal exactly 5 Hearts (10 HP) of TRUE DAMAGE to the target player, bypassing all armor protection (even full Netherite Armor with Protection IV) and enchantment reductions.

  1. Massive Knockback:

- Enemies hit by this sword should take extreme horizontal and slight vertical knockback, pushing them far away.

  1. Off-Hand Arrow Shoot:

- When the sword is held in the player's OFF-HAND (left hand), right-clicking or left-clicking with it must shoot a high-velocity Arrow towards where the player is looking. - Include a 1-second cooldown per shot to prevent spamming.

  1. Main-Hand Right-Click Ability:

- When held in the MAIN-HAND, right-clicking triggers a special Dash forward effect (launches the player in the direction they are facing) with a cosmetic particle effect.

  1. In-Game Command & Permission:

- Command: /givegodsword (Gives the custom sword directly to the player executing the command). - Permission: godsword.admin (Only OP or players with this permission can use the command).

Deliverables:

  • Complete main Java class implementing Listener and CommandExecutor.
  • Full plugin.yml content compatible with Paper 1.21.11 API.
  • Ensure proper imports, event registrations, and zero syntax errors so I can compile it into a .jar file directly.
Kodari AI
KodariOct 26 at 10:25 am 1
GodStoneSword
A PaperMC 1.21.11 plugin introducing a legendary God Stone Sword. This custom weapon deals 10 true damage bypassing all armor, applies massive knockback, shoots arrows from off-hand with cooldown, and dashes forward on main-hand right-click. Includes /givegodsword command with godsword.admin permission and particle effects.

I’ll create the main plugin class and its Paper plugin.yml.

Created the God Stone Sword plugin class and plugin.yml. It applies 10 HP of armor-bypassing damage with strong knockback, supports off-hand arrow shots with a one-second cooldown, and adds the main-hand dash ability.

Kodari can make mistakes. Review important code before using.
Files
src
Code
2 168
src/main/java/com/kodari/godsword/GodStoneSwordPlugin.java
package com.kodari.godsword;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
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;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public final class GodStoneSwordPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private static final long ARROW_COOLDOWN_MILLIS = 1_000L;
    private final Map<UUID, Long> lastArrowShot = new HashMap<>();
    private NamespacedKey swordKey;

    @Override
    public void onEnable() {
        swordKey = new NamespacedKey(this, "god_stone_sword");
        getServer().getPluginManager().registerEvents(this, this);
        getCommand("givegodsword").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;
        }
        if (!player.isOp() && !player.hasPermission("godsword.admin")) {
            player.sendMessage("§cYou do not have permission to use this command.");
            return true;
        }

        Map<Integer, ItemStack> leftovers = player.getInventory().addItem(createGodSword());
        leftovers.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
        player.sendMessage("§aYou received the God Stone Sword.");
        return true;
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onMeleeHit(EntityDamageByEntityEvent event) {
        if (!(event.getDamager() instanceof Player attacker)
                || !(event.getEntity() instanceof Player target)
                || !isGodSword(attacker.getInventory().getItemInMainHand())) {
            return;
        }

        event.setCancelled(true);
        target.setHealth(Math.max(0.0, target.getHealth() - 10.0));

        Vector knockback = target.getLocation().toVector().subtract(attacker.getLocation().toVector());
        knockback.setY(0.0);
        if (knockback.lengthSquared() < 1.0E-6) {
            knockback = attacker.getLocation().getDirection().setY(0.0);
        }
        if (knockback.lengthSquared() < 1.0E-6) {
            knockback = new Vector(0.0, 0.0, 1.0);
        }
        knockback.normalize().multiply(2.8).setY(0.45);
        target.setVelocity(knockback);
    }

    @EventHandler(ignoreCancelled = true)
    public void onInteract(PlayerInteractEvent event) {
        Player player = event.getPlayer();
        if (!isGodSword(player.getInventory().getItem(event.getHand()))) {
            return;
        }

        Action action = event.getAction();
        boolean rightClick = action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK;
        if (!rightClick) {
            return;
        }

        if (event.getHand() == EquipmentSlot.OFF_HAND) {
            shootArrow(player);
        } else if (event.getHand() == EquipmentSlot.HAND) {
            dash(player);
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onSwing(PlayerAnimationEvent event) {
        Player player = event.getPlayer();
        if (isGodSword(player.getInventory().getItemInOffHand())) {
            shootArrow(player);
        }
    }

    private void shootArrow(Player player) {
        long now = System.currentTimeMillis();
        Long lastShot = lastArrowShot.get(player.getUniqueId());
        if (lastShot != null && now - lastShot < ARROW_COOLDOWN_MILLIS) {
            return;
        }

        lastArrowShot.put(player.getUniqueId(), now);
        Vector direction = player.getEyeLocation().getDirection().normalize();
        Arrow arrow = player.getWorld().spawnArrow(player.getEyeLocation(), direction, 4.0f, 0.0f);
        arrow.setShooter(player);
    }

    private void dash(Player player) {
        Vector velocity = player.getLocation().getDirection().normalize().multiply(2.0);
        velocity.setY(Math.max(0.25, velocity.getY()));
        player.setVelocity(velocity);
        XParticle.of("CLOUD").ifPresent(particle -> player.getWorld().spawnParticle(
                particle.get(), player.getLocation(), 18, 0.4, 0.3, 0.4, 0.02));
    }

    private ItemStack createGodSword() {
        ItemStack sword = XMaterial.matchXMaterial("STONE_SWORD")
                .map(XMaterial::parseItem)
                .orElseThrow(() -> new IllegalStateException("STONE_SWORD is unavailable."));
        ItemMeta meta = sword.getItemMeta();
        meta.setDisplayName("§6§lGod Stone Sword");
        meta.setLore(Arrays.asList(
                "§7A blade infused with ancient power.",
                "§cDeals 5 hearts of true damage and massive knockback.",
                "§eOff-hand: shoot a high-velocity arrow.",
                "§6Main hand: right-click to dash forward."
        ));
        meta.getPersistentDataContainer().set(swordKey, PersistentDataType.BYTE, (byte) 1);
        sword.setItemMeta(meta);
        return sword;
    }

    private boolean isGodSword(ItemStack item) {
        if (item == null || !item.hasItemMeta()) {
            return false;
        }
        ItemMeta meta = item.getItemMeta();
        return meta.getPersistentDataContainer().has(swordKey, PersistentDataType.BYTE);
    }
}