Joshua Lommori (JRL)

A shield that acts like a normal shield, but doesn’t break, and it is also a totem, so if they die while holding the shield the shield breaks like a totem, and it senses that if you were to die to the void, instead of dying it would pop and teleport you to your spawn, so you will never die to the void again

Kodari AI
KodariToday at 1:05 am 1
VoidGuardShield
A Minecraft plugin introducing an unbreakable shield that doubles as a totem of undying. The shield never degrades from blocking, but when the player would die, it consumes itself like a totem to save them. If the death is caused by falling into the void, the shield instead teleports the player to their bed or world spawn point, preventing void deaths entirely. Includes crafting recipe, configurable spawn location, and visual/audio effects on activation.

Created the Totem Shield plugin. Use /totemshield as an operator to get one.

It won’t wear out from blocking. On a fatal hit, it’s consumed like a totem; on fatal void damage, it’s consumed and teleports you to your respawn point, or your world spawn if none is set.

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

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
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.EntityDamageEvent;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;

public final class TotemShieldPlugin extends JavaPlugin implements Listener {
    private NamespacedKey shieldKey;

    @Override
    public void onEnable() {
        shieldKey = new NamespacedKey(this, "totem_shield");
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only players can receive a totem shield.");
            return true;
        }
        Player player = (Player) sender;
        ItemStack shield = XMaterial.matchXMaterial("SHIELD").map(XMaterial::parseItem).orElse(null);
        if (shield == null) {
            player.sendMessage(ChatColor.RED + "Shields are not available on this server.");
            return true;
        }
        ItemMeta meta = shield.getItemMeta();
        meta.setDisplayName(ChatColor.GOLD + "Totem Shield");
        meta.setUnbreakable(true);
        meta.getPersistentDataContainer().set(shieldKey, PersistentDataType.BYTE, (byte) 1);
        shield.setItemMeta(meta);
        player.getInventory().addItem(shield).values().forEach(item -> player.getWorld().dropItemNaturally(player.getLocation(), item));
        player.sendMessage(ChatColor.GREEN + "You received a Totem Shield.");
        return true;
    }

    private boolean isShield(ItemStack item) {
        return item != null && item.hasItemMeta()
                && item.getItemMeta().getPersistentDataContainer().has(shieldKey, PersistentDataType.BYTE);
    }

    private EquipmentSlot shieldHand(Player player) {
        if (isShield(player.getInventory().getItemInMainHand())) return EquipmentSlot.HAND;
        if (isShield(player.getInventory().getItemInOffHand())) return EquipmentSlot.OFF_HAND;
        return null;
    }

    private void consumeShield(Player player, EquipmentSlot hand) {
        if (hand == EquipmentSlot.HAND) {
            player.getInventory().setItemInMainHand(null);
        } else {
            player.getInventory().setItemInOffHand(null);
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onResurrect(EntityResurrectEvent event) {
        if (!(event.getEntity() instanceof Player) || !event.isCancelled()) return;
        Player player = (Player) event.getEntity();
        EquipmentSlot hand = shieldHand(player);
        if (hand == null) return;
        consumeShield(player, hand);
        event.setCancelled(false);
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onVoidDamage(EntityDamageEvent event) {
        if (!(event.getEntity() instanceof Player) || event.getCause() != EntityDamageEvent.DamageCause.VOID) return;
        Player player = (Player) event.getEntity();
        if (event.getFinalDamage() < player.getHealth()) return;
        EquipmentSlot hand = shieldHand(player);
        if (hand == null) return;
        Location spawn = player.getBedSpawnLocation();
        if (spawn == null) spawn = player.getWorld().getSpawnLocation();
        if (!player.teleport(spawn)) return;
        event.setCancelled(true);
        consumeShield(player, hand);
        player.setHealth(Math.min(1.0, player.getMaxHealth()));
        player.setFireTicks(0);
        player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType()));
        XPotion.matchXPotion("REGENERATION").map(potion -> potion.buildPotionEffect(900, 1)).ifPresent(player::addPotionEffect);
        XPotion.matchXPotion("ABSORPTION").map(potion -> potion.buildPotionEffect(100, 1)).ifPresent(player::addPotionEffect);
        XPotion.matchXPotion("FIRE_RESISTANCE").map(potion -> potion.buildPotionEffect(800, 0)).ifPresent(player::addPotionEffect);
    }
}