dexfvv

make a custom helmet that gives infinite speed 2 and strength 2 and make it netherite make sure this is a custom helmet not all netherite helmets should do this only this custom one also make it only obtainable with operator commands i only want ops to get this using commands make the sword have a config where i can edit stuff about it and make it so i can rename this and yeah thats it

Kodari AI
KodariAug 9 at 7:08 pm 5
OpsGodHelmet
A Minecraft plugin that adds a custom Netherite helmet granting infinite Speed II and Strength II effects. Only obtainable via operator-only commands, ensuring regular Netherite helmets remain unaffected. Features a configurable YAML file allowing server admins to edit effect levels, durations, lore, and display name. Includes a custom give command restricted to operators, with permission-based access control. The helmet is uniquely identified by a custom item flag or NBT tag, preventing duplication exploits and ensuring only the designated item provides the buffs. Config supports renaming the helmet and adjusting all potion effect parameters.
  • Create a Paper plugin with an operator-only /customhelmet command.

  • Mark issued helmets with persistent custom data so ordinary netherite helmets never qualify.

  • Keep configurable name, lore, and effects in config.yml, including reload support.

Implemented the custom operator-only netherite helmet plugin.

  • /customhelmet give [player] issues the marked custom helmet.

  • /customhelmet reload reloads name, lore, effects, and amplifiers from config.yml.

  • Only helmets issued by the command grant infinite Speed II and Strength II; ordinary netherite helmets are unaffected.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 221
src/main/java/com/kodari/customhelmet/CustomHelmetPlugin.java
package com.kodari.customhelmet;

import com.cryptomorin.xseries.XItemFlag;
import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitTask;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class CustomHelmetPlugin extends JavaPlugin implements CommandExecutor {

    private static final int EFFECT_DURATION_TICKS = 60;

    private NamespacedKey helmetKey;
    private BukkitTask effectTask;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        helmetKey = new NamespacedKey(this, "custom_helmet");

        PluginCommand command = getCommand("customhelmet");
        if (command != null) {
            command.setExecutor(this);
        }

        effectTask = Bukkit.getScheduler().runTaskTimer(this, this::refreshHelmetEffects, 0L, 20L);
    }

    @Override
    public void onDisable() {
        if (effectTask != null) {
            effectTask.cancel();
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.hasPermission("customhelmet.admin") || sender instanceof Player && !sender.isOp()) {
            sender.sendMessage(color("&cOnly operators can use this command."));
            return true;
        }

        if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
            reloadConfig();
            sender.sendMessage(color("&aCustom helmet configuration reloaded."));
            return true;
        }

        if (args.length > 0 && !args[0].equalsIgnoreCase("give")) {
            sender.sendMessage(color("&cUsage: /" + label + " <give [player]|reload>"));
            return true;
        }

        Player target;
        if (args.length >= 2) {
            target = Bukkit.getPlayerExact(args[1]);
            if (target == null) {
                sender.sendMessage(color("&cThat player is not online."));
                return true;
            }
        } else if (sender instanceof Player) {
            target = (Player) sender;
        } else {
            sender.sendMessage(color("&cConsole usage: /" + label + " give <player>"));
            return true;
        }

        ItemStack helmet = createHelmet();
        if (helmet == null) {
            sender.sendMessage(color("&cThe netherite helmet material is unavailable on this server."));
            return true;
        }

        target.getInventory().addItem(helmet).values().forEach(item -> target.getWorld().dropItemNaturally(target.getLocation(), item));
        sender.sendMessage(color("&aGave the custom helmet to &e" + target.getName() + "&a."));
        if (!target.equals(sender)) {
            target.sendMessage(color("&aYou received a custom helmet from an operator."));
        }
        return true;
    }

    private ItemStack createHelmet() {
        ItemStack helmet = XMaterial.matchXMaterial("NETHERITE_HELMET")
                .map(XMaterial::parseItem)
                .orElse(null);
        if (helmet == null) {
            return null;
        }

        ItemMeta meta = helmet.getItemMeta();
        if (meta == null) {
            return null;
        }

        FileConfiguration config = getConfig();
        meta.setDisplayName(color(config.getString("helmet.name", "&6&lTitan Helmet")));

        List<String> lore = new ArrayList<>();
        for (String line : config.getStringList("helmet.lore")) {
            lore.add(color(line));
        }
        meta.setLore(lore);
        meta.setUnbreakable(true);
        XItemFlag.of("HIDE_UNBREAKABLE").ifPresent(flag -> flag.set(meta));

        PersistentDataContainer container = meta.getPersistentDataContainer();
        container.set(helmetKey, PersistentDataType.BYTE, (byte) 1);
        helmet.setItemMeta(meta);
        return helmet;
    }

    private void refreshHelmetEffects() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (!isCustomHelmet(player.getInventory().getHelmet())) {
                continue;
            }

            applyConfiguredEffect(player, "helmet.speed");
            applyConfiguredEffect(player, "helmet.strength");
        }
    }

    private boolean isCustomHelmet(ItemStack item) {
        if (item == null || !item.hasItemMeta()) {
            return false;
        }

        Byte marker = item.getItemMeta().getPersistentDataContainer().get(helmetKey, PersistentDataType.BYTE);
        return marker != null && marker == (byte) 1;
    }

    private void applyConfiguredEffect(Player player, String path) {
        String type = getConfig().getString(path + ".type");
        if (type == null || type.trim().isEmpty()) {
            return;
        }

        int amplifier = Math.max(0, getConfig().getInt(path + ".amplifier", 1));
        Optional<XPotion> potion = XPotion.matchXPotion(type);
        potion.map(value -> value.buildPotionEffect(EFFECT_DURATION_TICKS, amplifier))
                .ifPresent(effect -> applyEffect(player, effect));
    }

    private void applyEffect(Player player, PotionEffect effect) {
        player.addPotionEffect(effect, true);
    }

    private String color(String message) {
        return ChatColor.translateAlternateColorCodes('&', message);
    }
}