Jeewan Joshi

On taking damage, if player is wearing netherite helmet named &0&l HELMET and netherite boots named &0&l BOOTS and the cause of damage is fire tick or suffocation then the event is cancelled

Kodari AI
KodariOct 27 at 11:21 am 1
NetheriteFireProtection
This plugin provides enhanced fire and suffocation protection for players wearing specific netherite armor pieces. When a player takes damage, the plugin checks if they are wearing a netherite helmet named "&0&l HELMET" and netherite boots named "&0&l BOOTS" simultaneously. If both conditions are met and the damage cause is either fire tick or suffocation, the damage event is completely cancelled, preventing any health loss. The plugin listens to the EntityDamageEvent, validates the armor names exactly as specified, verifies the damage cause against the allowed types, and cancels the event when all criteria are satisfied. This creates a unique gameplay mechanic where specific named armor combinations grant immunity to environmental hazards like burning and suffocation, encouraging players to seek out and equip these particular items for survival advantages in hazardous areas.
  1. Create the Gradle plugin setup and plugin.yml.

  2. Add a damage listener that checks both named netherite armor pieces.

  3. Cancel damage only for fire tick and suffocation.

Added ArmorDamageGuard: damage is cancelled for fire tick or suffocation when the player wears a netherite helmet named &0&l HELMET and netherite boots named &0&l BOOTS.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
3 75
src/main/java/com/kodari/armordamageguard/ArmorDamageGuardPlugin.java
package com.kodari.armordamageguard;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

public final class ArmorDamageGuardPlugin extends JavaPlugin implements Listener {
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler(ignoreCancelled = true)
    public void onPlayerDamage(EntityDamageEvent event) {
        if (!(event.getEntity() instanceof Player player)) {
            return;
        }

        EntityDamageEvent.DamageCause cause = event.getCause();
        if (cause != EntityDamageEvent.DamageCause.FIRE_TICK
                && cause != EntityDamageEvent.DamageCause.SUFFOCATION) {
            return;
        }

        if (hasNamedArmor(player.getInventory().getHelmet(), "NETHERITE_HELMET", "&0&l HELMET")
                && hasNamedArmor(player.getInventory().getBoots(), "NETHERITE_BOOTS", "&0&l BOOTS")) {
            event.setCancelled(true);
        }
    }

    private boolean hasNamedArmor(ItemStack item, String materialName, String displayName) {
        if (item == null || !XMaterial.matchXMaterial(item.getType()).name().equals(materialName)) {
            return false;
        }

        ItemMeta meta = item.getItemMeta();
        return meta != null
                && meta.hasDisplayName()
                && meta.getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', displayName));
    }
}