not_cvr

Act as an expert Minecraft Java Edition plugin developer. I want you to create a custom PaperMC plugin (compatible with Minecraft 1.21+) in Java.

I do NOT want any command to get a custom sword, and I do NOT want any command to convert items. I want ANY vanilla/normal Stone Sword in the player's inventory or hand to automatically act as the "Stone God Sword" and have all the custom abilities built into it.

Please write the complete code (Main class and plugin.yml) with the following specific abilities and requirements:

  1. Automatic Item Detection (No Commands Needed):

- The plugin should check if the item in the player's hand is a standard, vanilla Stone Sword (using Material.STONE_SWORD). - If it's a normal Stone Sword, it will automatically grant the custom abilities when used.

  1. Ability 1 - Thunder Lightning (Right-Click Hold):

- When the player holds down the right-click with a normal Stone Sword, lightning strikes continuously at the target block/location where the player is looking. - If the player holds it continuously for 10 seconds, trigger a 30-second cooldown for this ability.

  1. Ability 2 - Arrow Shoot Combo:

- When the player right-clicks with the Stone Sword, it rapidly shoots 5 arrows at once. - The damage should follow Minecraft's vanilla armor protection mechanics (e.g., deals lower damage if the target wears Netherite or Diamond armor, and standard ~2 hearts equivalent against unarmored targets). - This ability has a 30-second cooldown.

  1. Ability 3 - Player Boost (Shift + Left-Click):

- When the player holds Shift (Sneaking) and does a Left-Click with the Stone Sword, they get boosted/propelled forward through the air. - This ability deals NO fall or direct damage to the user. - This ability has a 30-second cooldown.

  1. Technical Details:

- Use modern Paper/Spigot API. - Implement proper cooldown management for each ability using UUID checks. - Send clear chat feedback messages to the player when abilities are on cooldown or activated.

Please provide the full source code clearly, along with instructions on how to compile it.

Kodari AI
KodariOct 27 at 5:46 am 1
StoneGodSword
Automatic Stone Sword enhancement plugin for PaperMC 1.21+. Detects vanilla Stone Swords in hand and grants three abilities: hold right-click for continuous lightning strikes with 10-second hold triggering 30-second cooldown, right-click fires 5 arrows simultaneously respecting armor damage reduction with 30-second cooldown, and shift+left-click propels player forward without fall damage on 30-second cooldown. Uses UUID-based cooldown tracking, chat feedback messages, and modern Paper API. No commands needed - all abilities activate automatically on vanilla items.
  1. Create the Paper 1.21+ Gradle project and plugin metadata.

  2. Implement automatic Stone Sword detection, arrow volley, lightning channel, boost, and UUID cooldowns.

  3. Note the server-side limitation around detecting a held right mouse button.

Created the Stone God Sword plugin with automatic Material.STONE_SWORD detection and no item-grant or conversion commands.

  • Right-click fires five arrows. Each is configured for 0.8 base damage, approximately 4 damage points (2 hearts) total if all five hit an unarmored target; vanilla armor reduces damage.

  • Right-click also starts a 10-second lightning channel, striking the target location every 10 ticks with visual-only lightning.

  • Sneak + left-click boosts the player forward and prevents fall damage from that boost.

  • Each ability has its own 30-second UUID-based cooldown and player feedback.

Input limitation: Paper does not expose whether a player is holding right-click with a Stone Sword. Since both abilities use right-click, this implementation fires the arrows and starts lightning on the same click; the lightning channel continues while the sword remains in the main hand, even if the player releases the button. A separate input would be needed to distinguish a tap from a hold.

To compile in Kodari, click Compile in the desktop top bar, or ⋮ → Compile Project on phone. Click Compile in the window, then Download when the build succeeds. The project includes the Paper 1.21.4 Gradle setup and plugin metadata.

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

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Arrow;
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.EntityDamageEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerAnimationType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.Vector;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public final class StoneGodSwordPlugin extends JavaPlugin implements Listener {
    private static final long COOLDOWN_MILLIS = 30_000L;
    private static final long LIGHTNING_CHANNEL_TICKS = 20L * 10L;
    private static final String PREFIX = ChatColor.GRAY + "[" + ChatColor.AQUA + "Stone God Sword" + ChatColor.GRAY + "] ";

    private final Map<UUID, Long> arrowCooldowns = new HashMap<>();
    private final Map<UUID, Long> lightningCooldowns = new HashMap<>();
    private final Map<UUID, Long> boostCooldowns = new HashMap<>();
    private final Map<UUID, BukkitTask> activeLightningChannels = new HashMap<>();
    private final Set<UUID> boostFallProtection = new HashSet<>();
    private final Set<UUID> airborneAfterBoost = new HashSet<>();

    @Override
    public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);
    }

    @Override
    public void onDisable() {
        activeLightningChannels.values().forEach(BukkitTask::cancel);
        activeLightningChannels.clear();
        boostFallProtection.clear();
        airborneAfterBoost.clear();
    }

    @EventHandler(ignoreCancelled = true)
    public void onRightClick(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND) {
            return;
        }

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

        Player player = event.getPlayer();
        if (!isHoldingStoneSword(player)) {
            return;
        }

        shootArrowCombo(player);
        startLightningChannel(player);
    }

    @EventHandler(ignoreCancelled = true)
    public void onPlayerSwing(PlayerAnimationEvent event) {
        if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) {
            return;
        }

        Player player = event.getPlayer();
        if (!player.isSneaking() || !isHoldingStoneSword(player)) {
            return;
        }

        UUID playerId = player.getUniqueId();
        if (sendCooldownIfActive(player, boostCooldowns, "Player Boost")) {
            return;
        }

        boostCooldowns.put(playerId, System.currentTimeMillis() + COOLDOWN_MILLIS);
        boostFallProtection.add(playerId);
        airborneAfterBoost.remove(playerId);

        Vector direction = player.getLocation().getDirection();
        direction.setY(0);
        if (direction.lengthSquared() < 0.0001) {
            direction = new Vector(0, 0, 1);
        }
        direction.normalize().multiply(1.5).setY(0.8);
        player.setVelocity(direction);
        player.setFallDistance(0.0f);
        player.sendMessage(PREFIX + ChatColor.GREEN + "Player Boost activated! Cooldown: 30 seconds.");

        Bukkit.getScheduler().runTaskLater(this, () -> {
            boostFallProtection.remove(playerId);
            airborneAfterBoost.remove(playerId);
        }, 20L * 20L);
    }

    @EventHandler(ignoreCancelled = true)
    public void onMoveAfterBoost(PlayerMoveEvent event) {
        UUID playerId = event.getPlayer().getUniqueId();
        if (boostFallProtection.contains(playerId) && !event.getPlayer().isOnGround()) {
            airborneAfterBoost.add(playerId);
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onBoostFallDamage(EntityDamageEvent event) {
        if (event.getCause() != EntityDamageEvent.DamageCause.FALL || !(event.getEntity() instanceof Player player)) {
            return;
        }

        UUID playerId = player.getUniqueId();
        if (boostFallProtection.contains(playerId) && airborneAfterBoost.contains(playerId)) {
            event.setCancelled(true);
            player.setFallDistance(0.0f);
            boostFallProtection.remove(playerId);
            airborneAfterBoost.remove(playerId);
        }
    }

    private void shootArrowCombo(Player player) {
        UUID playerId = player.getUniqueId();
        if (sendCooldownIfActive(player, arrowCooldowns, "Arrow Shoot Combo")) {
            return;
        }

        arrowCooldowns.put(playerId, System.currentTimeMillis() + COOLDOWN_MILLIS);
        Location origin = player.getEyeLocation();
        Vector direction = origin.getDirection().normalize();
        World world = player.getWorld();

        for (int i = 0; i < 5; i++) {
            Arrow arrow = world.spawnArrow(origin, direction, 1.6f, 0.0f);
            arrow.setShooter(player);
            arrow.setDamage(0.8);
        }

        player.sendMessage(PREFIX + ChatColor.GREEN + "Arrow Shoot Combo activated: fired 5 arrows. Cooldown: 30 seconds.");
    }

    private void startLightningChannel(Player player) {
        UUID playerId = player.getUniqueId();
        if (activeLightningChannels.containsKey(playerId)) {
            return;
        }
        if (sendCooldownIfActive(player, lightningCooldowns, "Thunder Lightning")) {
            return;
        }

        player.sendMessage(PREFIX + ChatColor.YELLOW + "Thunder Lightning channel started; lightning will strike your target for 10 seconds.");
        long[] elapsedTicks = {0L};
        BukkitTask[] taskReference = new BukkitTask[1];
        taskReference[0] = Bukkit.getScheduler().runTaskTimer(this, () -> {
            Player channelingPlayer = Bukkit.getPlayer(playerId);
            if (channelingPlayer == null || !channelingPlayer.isOnline() || !isHoldingStoneSword(channelingPlayer)) {
                activeLightningChannels.remove(playerId);
                taskReference[0].cancel();
                return;
            }

            strikeAtTarget(channelingPlayer);
            elapsedTicks[0] += 10L;
            if (elapsedTicks[0] >= LIGHTNING_CHANNEL_TICKS) {
                activeLightningChannels.remove(playerId);
                lightningCooldowns.put(playerId, System.currentTimeMillis() + COOLDOWN_MILLIS);
                taskReference[0].cancel();
                channelingPlayer.sendMessage(PREFIX + ChatColor.GREEN + "Thunder Lightning finished. Cooldown: 30 seconds.");
            }
        }, 0L, 10L);
        activeLightningChannels.put(playerId, taskReference[0]);
    }

    private void strikeAtTarget(Player player) {
        Location target = player.getTargetBlockExact(30) == null
                ? player.getEyeLocation().add(player.getEyeLocation().getDirection().multiply(30))
                : player.getTargetBlockExact(30).getLocation().add(0.5, 0.5, 0.5);
        player.getWorld().strikeLightningEffect(target);
    }

    private boolean sendCooldownIfActive(Player player, Map<UUID, Long> cooldowns, String abilityName) {
        Long expiresAt = cooldowns.get(player.getUniqueId());
        if (expiresAt == null) {
            return false;
        }

        long remainingMillis = expiresAt - System.currentTimeMillis();
        if (remainingMillis <= 0L) {
            cooldowns.remove(player.getUniqueId());