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
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
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
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
and make that it has 0 enchants
Also removing the unused XEnchantment import:
All three enchants (Sharpness V, Unbreaking III, Looting III) removed — the sword now has zero enchants.
make that it overwrites any other plugin and just remove the persons hearts and give them to me
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 winevent.setDamage(0)— the normal hit does zero damage; only our steal manipulates HPApplied next tick via
runTask— guarantees no other listener can overwrite our values after usRemoved
XAttributedependency entirely, using rawAttribute.GENERIC_MAX_HEALTH
The compilation failed with this error:
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.
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.
just make that they have instant damage that they loose 3 hearts and that i get +3 hearts
Also cleaning up the now-unused XAttribute import:
Done. The logic is now fully simplified:
Victim instantly loses 3 hearts (
-6 HP), floored at0.5so they can’t be killed by the steal aloneAttacker instantly gains 3 hearts (
+6 HP), capped at20 HP(10 hearts)No restore, no temporary buffs — it’s a permanent instant transfer
30s cooldown and action bar messages unchanged
make it that when held you get 1 block + entity reach and make that all hostile mobs insantly die
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. UsesPLAYER_BLOCK_INTERACTION_RANGEandPLAYER_ENTITY_INTERACTION_RANGEattributes (Paper 1.20.5+). Thetry/catchsilently skips on older versions where those attributes don’t exist.Instant-kill hostile mobs — any
Monsterentity (zombies, skeletons, creepers, etc.) hit with the sword takes overkill damage and dies immediately. Player-vs-player heart steal logic is untouched.
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;
}
}