ColdEyesEditz

Sword abilities

  • Warden Charge: Activated by holding the sword and crouching.
  • SpeedChamber: Activated by crouching + pressing F (offhand key). Gives unlimited critical-hit attacks for 3 seconds, with no cooldown.
Kodari AI
KodariNov 12 at 4:55 pm 1
WardenCombat
WardenCombat is a Minecraft plugin adding a unique sword with two powerful abilities. The Warden Charge activates when the player holds the sword and crouches, launching them forward in a devastating dash attack. The SpeedChamber ability triggers when crouching and pressing the offhand key (F), granting unlimited critical-hit attacks for 3 seconds with no cooldown, allowing rapid high-damage strikes. The plugin handles ability cooldowns, activation detection, and visual/sound effects for immersive combat gameplay.

Created the sword abilities plugin:

  • Warden Charge: crouch with a sword to dash forward; 5-second cooldown.

  • SpeedChamber: crouch and press F to gain 1.5× sword damage for 3 seconds, with no cooldown. This is a damage multiplier rather than forced vanilla critical hits.

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

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

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

public final class SwordAbilities extends JavaPlugin implements Listener {
    private static final long CHARGE_COOLDOWN_NANOS = 5_000_000_000L;
    private static final long SPEED_CHAMBER_NANOS = 3_000_000_000L;
    private final Map<UUID, Long> lastCharge = new HashMap<>();
    private final Map<UUID, Long> speedChamberUntil = new HashMap<>();

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

    private boolean isSword(ItemStack item) {
        return item != null && XMaterial.matchXMaterial(item.getType()).name().endsWith("_SWORD");
    }

    @EventHandler(ignoreCancelled = true)
    public void onSneak(PlayerToggleSneakEvent event) {
        Player player = event.getPlayer();
        if (!event.isSneaking() || !isSword(player.getInventory().getItemInMainHand())) {
            return;
        }

        long now = System.nanoTime();
        Long previous = lastCharge.get(player.getUniqueId());
        if (previous != null && now - previous < CHARGE_COOLDOWN_NANOS) {
            return;
        }
        lastCharge.put(player.getUniqueId(), now);
        Vector direction = player.getLocation().getDirection().setY(0);
        if (direction.lengthSquared() < 0.0001) {
            return;
        }
        player.setVelocity(direction.normalize().multiply(1.5).setY(0.25));
    }

    @EventHandler(ignoreCancelled = true)
    public void onSwapHands(PlayerSwapHandItemsEvent event) {
        Player player = event.getPlayer();
        if (!player.isSneaking() || !isSword(player.getInventory().getItemInMainHand())) {
            return;
        }
        event.setCancelled(true);
        speedChamberUntil.put(player.getUniqueId(), System.nanoTime() + SPEED_CHAMBER_NANOS);
        player.sendMessage("§bSpeedChamber activated for 3 seconds!");
    }

    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    public void onDamage(EntityDamageByEntityEvent event) {
        if (!(event.getDamager() instanceof Player player)
                || !(event.getEntity() instanceof LivingEntity)
                || !isSword(player.getInventory().getItemInMainHand())) {
            return;
        }
        Long expires = speedChamberUntil.get(player.getUniqueId());
        if (expires == null) {
            return;
        }
        if (System.nanoTime() - expires >= 0) {
            speedChamberUntil.remove(player.getUniqueId());
            return;
        }
        event.setDamage(event.getDamage() * 1.5);
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
        lastCharge.remove(event.getPlayer().getUniqueId());
        speedChamberUntil.remove(event.getPlayer().getUniqueId());
    }
}