Skplayz444 Skplayz444

Act as an expert Minecraft Paper plugin developer. Create a fully functional God Weapon plugin for Minecraft Java Paper 1.21.x.

Weapon: Use a normal vanilla NETHERITE_SWORD with its original Minecraft texture and appearance.

Ability 1 – Warden Sonic Beam: Right-click the sword to instantly fire a Sonic Beam like the Minecraft Warden's sonic attack. It must deal damage like the real Warden Sonic Boom, including its normal damage behavior against armored players. Every right-click must trigger the ability again, with no cooldown or usage limit. Aim the beam in the direction the player is looking.

Ability 2 – Sharpness 1000: Only when the player holds SHIFT and left-clicks with this sword, activate Sharpness level 1000 so the attack can one-shot enemies. Apply Sharpness 1000 only for this specific attack; do not add any other enchantments. Normal left-click attacks must remain normal unless SHIFT is held.

Important Requirements:

  • Keep the sword's vanilla Netherite Sword appearance.
  • No custom textures, no other enchantments, and no unnecessary visual changes.
  • Both abilities must work reliably and independently.
  • Prevent the Sonic Beam from triggering during the SHIFT + left-click ability.
  • Do not require commands to obtain or activate the abilities; make the weapon naturally available through the plugin's intended implementation.
  • Provide complete, build-ready Java source code, a correct plugin.yml, and all required project files for Paper 1.21.x.
  • Ensure the plugin compiles successfully and explain how to build the JAR and install it on the server.
Kodari AI
KodariOct 27 at 11:35 pm 1
GodWeaponSword
A Paper plugin adding a God Weapon Netherite Sword with two abilities. Right-click fires a Warden Sonic Beam dealing true damage in the player's look direction, with no cooldown. Shift+left-click applies Sharpness 1000 for a single one-shot attack while normal attacks remain vanilla. The weapon uses the standard Netherite Sword texture with no custom models or additional enchantments. Players obtain it via a simple command, and both abilities work independently without conflicts.
  1. Add a Paper 1.21 plugin with a vanilla netherite sword granted automatically on first join.

  2. Implement the armor-bypassing sonic beam and shift-only Sharpness 1000 attack independently.

  3. Add Gradle configuration and plugin.yml; then use Kodari’s Compile flow to build the JAR.

Implemented GodWeapon as a Paper 1.21 plugin. It grants each player one vanilla-appearance Netherite Sword on first join, with no commands required.

  • Right-click: fires a 15-block sonic beam using Minecraft’s sonic-boom damage type, with no cooldown.

  • Sneak + melee hit: adds the damage equivalent of Sharpness 1000 to that hit only. The sword itself has no enchantments, and this bonus does not affect sonic-beam damage.

  • Added the Gradle build files and plugin.yml.

To build in Kodari, click Compile in the desktop top bar—or ⋮ → Compile Project on mobile—then click Compile and download the resulting JAR. Put it in your server’s plugins folder and restart the server.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 185
src/main/java/com/kodari/godweapon/GodWeaponPlugin.java
package com.kodari.godweapon;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.particles.XParticle;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType;
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.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
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.RayTraceResult;
import org.bukkit.util.Vector;
import org.bukkit.FluidCollisionMode;

public final class GodWeaponPlugin extends JavaPlugin implements Listener {
    private static final double BEAM_RANGE = 15.0;
    private static final double SONIC_BOOM_DAMAGE = 10.0;
    private static final double SHARPNESS_1000_BONUS = 500.5;

    private NamespacedKey weaponKey;
    private NamespacedKey grantedKey;

    @Override
    public void onEnable() {
        weaponKey = new NamespacedKey(this, "god_weapon");
        grantedKey = new NamespacedKey(this, "god_weapon_granted");
        getServer().getPluginManager().registerEvents(this, this);
        for (Player player : getServer().getOnlinePlayers()) {
            grantWeaponIfNeeded(player);
        }
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        grantWeaponIfNeeded(event.getPlayer());
    }

    @EventHandler
    public void onRightClick(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND
                || (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
                || !isGodWeapon(event.getItem())) {
            return;
        }
        fireSonicBeam(event.getPlayer());
    }

    @EventHandler
    public void onEntityDamage(EntityDamageByEntityEvent event) {
        if (!(event.getDamager() instanceof Player player)
                || !player.isSneaking()
                || !isGodWeapon(player.getInventory().getItemInMainHand())
                || event.getDamageSource().getDamageType().equals(DamageType.SONIC_BOOM)) {
            return;
        }
        event.setDamage(event.getDamage() + SHARPNESS_1000_BONUS);
    }

    private void fireSonicBeam(Player player) {
        Location start = player.getEyeLocation();
        Vector direction = start.getDirection().normalize();
        World world = player.getWorld();

        RayTraceResult blockHit = world.rayTraceBlocks(start, direction, BEAM_RANGE, FluidCollisionMode.NEVER, true);
        double entityRange = blockHit == null
                ? BEAM_RANGE
                : Math.max(0.0, start.toVector().distance(blockHit.getHitPosition()) - 0.01);
        RayTraceResult entityHit = entityRange > 0.0
                ? world.rayTraceEntities(start, direction, entityRange, 0.5,
                        entity -> entity instanceof LivingEntity && entity != player)
                : null;

        Location end;
        if (entityHit != null) {
            end = entityHit.getHitPosition().toLocation(world);
            Entity target = entityHit.getHitEntity();
            if (target instanceof LivingEntity livingTarget) {
                DamageSource source = DamageSource.builder(DamageType.SONIC_BOOM)
                        .withCausingEntity(player)
                        .withDirectEntity(player)
                        .build();
                livingTarget.damage(SONIC_BOOM_DAMAGE, source);
            }
        } else if (blockHit != null) {
            end = blockHit.getHitPosition().toLocation(world);
        } else {
            end = start.clone().add(direction.clone().multiply(BEAM_RANGE));
        }

        double beamLength = start.distance(end);
        XParticle.of("SONIC_BOOM").ifPresent(particle -> {
            for (double distance = 0.0; distance <= beamLength; distance += 0.35) {
                Location point = start.clone().add(direction.clone().multiply(distance));
                world.spawnParticle(particle.get(), point, 1, 0.0, 0.0, 0.0, 0.0);
            }
        });
    }

    private void grantWeaponIfNeeded(Player player) {
        if (hasGodWeapon(player)) {
            player.getPersistentDataContainer().set(grantedKey, PersistentDataType.BYTE, (byte) 1);
            return;
        }
        if (player.getPersistentDataContainer().has(grantedKey, PersistentDataType.BYTE)) {
            return;
        }

        ItemStack weapon = createGodWeapon();
        Map<Integer, ItemStack> leftovers = player.getInventory().addItem(weapon);
        leftovers.values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
        player.getPersistentDataContainer().set(grantedKey, PersistentDataType.BYTE, (byte) 1);
    }

    private ItemStack createGodWeapon() {
        ItemStack weapon = XMaterial.matchXMaterial("NETHERITE_SWORD")
                .map(XMaterial::parseItem)
                .orElseThrow(() -> new IllegalStateException("NETHERITE_SWORD is unavailable"));
        ItemMeta meta = weapon.getItemMeta();
        meta.getPersistentDataContainer().set(weaponKey, PersistentDataType.BYTE, (byte) 1);
        weapon.setItemMeta(meta);
        return weapon;
    }

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

    private boolean hasGodWeapon(Player player) {
        for (ItemStack item : player.getInventory().getContents()) {
            if (isGodWeapon(item)) {
                return true;
            }
        }
        return false;
    }
}