F

make a plugin that when a op does /apexsword <player> it gives the player a netherite sword that when hit theres a 40% chance you steal the 3 hearts from a player in in the action bar it says you stole <player>'s hearts and also say a cooldown for 30 seconds right after

Kodari AI
KodariJun 23 at 6:44 am 5
ApexSword
A Minecraft plugin that lets OPs give players a powerful Netherite Sword via /apexsword &lt;player&gt;. On hit, the sword has a 40% chance to steal 3 hearts from the target, healing the wielder. Both players see action bar messages indicating the steal. After a successful steal, the sword enters a 30-second cooldown displayed in the action bar, blocking further steals until it expires.

Three classes: main plugin, command, and listener. The sword is tagged via PersistentDataContainer for reliable identification.

Here’s what the plugin does:

  • /apexsword <player> — OP-only command that gives a named & lored Netherite Sword tagged with a PDC key (so it survives enchant tables, anvils, etc.)

  • On hit (Player → Player): 40% chance fires a steal — takes up to 3 hearts (6 HP) from the victim and adds it to the attacker’s health (capped at max)

  • Action bar messages:

    • Attacker: “You stole [victim]'s hearts!”

    • Victim: “[attacker] stole your hearts!”

    • After 30s cooldown expires: “Apex Sword ready!”

    • During cooldown: shows remaining seconds on every swing attempt

  • 30s cooldown tracked per-attacker UUID in memory

F

make that the player i stole them from theyre hearts get removed and i get theyre hearts for 10 seconds and then after 10 seconds they get them back

Kodari AI
KodariJun 23 at 6:51 am 9

Here’s what changed:

  • Victim’s hearts are removed — their current health drops by up to 3 hearts (6 HP)

  • Attacker’s max health is temporarily increased by the stolen amount (so they can actually hold the extra hearts), and they’re healed for that amount

  • After 10 seconds:

    • Attacker’s max health is reduced back to normal; if their current HP now exceeds the cap it’s clamped down

    • Victim gets their hearts restored (up to their natural max)

    • Action bar messages notify both players ("The stolen hearts have faded." / "Your hearts have been returned!")

  • 30s cooldown notification still fires separately after the full cooldown expires

F

and make that it has 0 enchants

Kodari AI
KodariJun 23 at 6:53 am 3

Also removing the unused XEnchantment import:

All three enchants (Sharpness V, Unbreaking III, Looting III) removed — the sword now has zero enchants.

F

make that it overwrites any other plugin and just remove the persons hearts and give them to me

Kodari AI
KodariJun 23 at 6:59 am 11

The key changes: use EventPriority.HIGHEST so it runs last (overwriting other plugins), call event.setDamage(0) so the normal hit damage doesn’t kill the victim, and directly set health without touching max health attributes — just raw HP manipulation.Full rewrite is cleanest here:

Key changes:

  • EventPriority.HIGHEST — runs after every other plugin, so our HP changes win

  • event.setDamage(0) — the normal hit does zero damage; only our steal manipulates HP

  • Applied next tick via runTask — guarantees no other listener can overwrite our values after us

  • Removed XAttribute dependency entirely, using raw Attribute.GENERIC_MAX_HEALTH

F

The compilation failed with this error:

code
Compilation failed with 3 error(s):

ERROR in src/main/java/com/kodari/apexsword/ApexSwordListener.java at line 64: cannot find symbol
        final double attackerMax = attacker.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
                                                                  ^
  symbol: variable GENERIC_MAX_HEALTH
  location: interface Attribute

ERROR in src/main/java/com/kodari/apexsword/ApexSwordListener.java at line 92: cannot find symbol
                double attMax = att.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
                                                          ^
  symbol: variable GENERIC_MAX_HEALTH
  location: interface Attribute

ERROR in src/main/java/com/kodari/apexsword/ApexSwordListener.java at line 98: cannot find symbol
                double vicMax = vic.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
                                                          ^
  symbol: variable GENERIC_MAX_HEALTH
  location: interface Attribute


=== COMPILATION ERROR ANALYSIS ===

FILES TO INVESTIGATE:
  - src/main/java/com/kodari/apexsword/ApexSwordListener.java

Please fix this error by creating a new artifact with the corrected code.

Kodari AI
KodariJun 23 at 7:01 am 4

Attribute.GENERIC_MAX_HEALTH was renamed in newer Paper versions. Use XAttribute instead, and drop the unused attMax/vicMax variables:

Replaced all three Attribute.GENERIC_MAX_HEALTH usages with XAttribute.of("generic.max_health") — this resolves the symbol error across all server versions.

F

just make that they have instant damage that they loose 3 hearts and that i get +3 hearts

Kodari AI
KodariJun 23 at 7:06 am 13

Also cleaning up the now-unused XAttribute import:

Done. The logic is now fully simplified:

  • Victim instantly loses 3 hearts (-6 HP), floored at 0.5 so they can’t be killed by the steal alone

  • Attacker instantly gains 3 hearts (+6 HP), capped at 20 HP (10 hearts)

  • No restore, no temporary buffs — it’s a permanent instant transfer

  • 30s cooldown and action bar messages unchanged

F

make it that when held you get 1 block + entity reach and make that all hostile mobs insantly die

Kodari AI
KodariJun 23 at 7:14 am 6

Two additions needed: attribute modifier for reach when holding the sword (track via equip/unequip events + held item change), and instant-kill hostile mobs on hit.

Here’s what was added:

  • +1 block & entity reach — applied the moment you hold the sword (PlayerItemHeldEvent, and on join if already held). Removed when you switch away or disconnect. Uses PLAYER_BLOCK_INTERACTION_RANGE and PLAYER_ENTITY_INTERACTION_RANGE attributes (Paper 1.20.5+). The try/catch silently skips on older versions where those attributes don’t exist.

  • Instant-kill hostile mobs — any Monster entity (zombies, skeletons, creepers, etc.) hit with the sword takes overkill damage and dies immediately. Player-vs-player heart steal logic is untouched.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
5 279
src/main/java/com/kodari/apexsword/ApexSword.java
package com.kodari.apexsword;

import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;

public class ApexSword extends JavaPlugin {

    private NamespacedKey swordKey;

    @Override
    public void onEnable() {
        swordKey = new NamespacedKey(this, "apex_sword");

        getCommand("apexsword").setExecutor(new ApexSwordCommand(this));
        getServer().getPluginManager().registerEvents(new ApexSwordListener(this), this);
    }

    public NamespacedKey getSwordKey() {
        return swordKey;
    }
}