Jeevan Bohara

Make a combat plugin for 1.21.11 version paper no lag /combat menu where there is option to disable all combat settings no death in combat anything and in menu another option combat duration and + - option left click to add right click to minus and setted duration shall be combat and a another option to where combat shows actionbar , bossbar , weapon Cooldown, and another option to choose punishment for log kill,clearinventory , none chat and if a players is kicked for connection timeout or ping issue or timed out or server restart server stop they shall not be executed and send message if they combat log from the another user and a webhook useable for dc those who every combats from whom send messages In dc webhook and option to true false and it shall not punishment players if they have kicked from server restart ping issue timeout etc only if player logs and clean prefixes different lines for command info and small caps fonts used in everything and no lag smooth no ping buffer etc and like this combat colour &bcombat: &8<duration> in every where and if bossbar bossbar shall be blue and just like donut smp.

Kodari AI
KodariOct 21 at 12:57 pm 1
CombatControl
A Paper 1.21.11 combat management plugin with a /combat menu featuring toggleable combat settings, configurable combat duration with left-click to increase and right-click to decrease, display options for actionbar, bossbar (blue), and weapon cooldown indicators. Includes punishment selection for combat logging (kill, clear inventory, none) with chat notifications, webhook integration for Discord alerts, and protection from punishment for disconnections caused by ping issues, timeouts, server restarts, or stops. Features a cyan "&amp;bcombat: &amp;8&lt;duration&gt;" display format throughout, small caps styling, and optimized lag-free performance with no ping buffering.
  1. Create the Paper 1.21.11 project files and configuration.

  2. Implement combat tagging, disconnect-safe handling, punishments, and optional webhook reports.

  3. Add the /combat menu for toggles and duration controls.

Created the Paper 1.21.11 combat plugin with /combat controls for combat tagging, duration, actionbar/bossbar display, weapon cooldown display, and logout punishment. Admins can configure the Discord webhook with /combat webhook <url|off>; kicks and plugin shutdowns are exempt from combat-log punishment.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
7 587
src/main/java/com/kodari/combat/CombatPlugin.java
package com.kodari.combat;

import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import com.cryptomorin.xseries.XMaterial;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;

public final class CombatPlugin extends JavaPlugin implements Listener, CommandExecutor {
    private static final String PREFIX = "&bᴄᴏᴍʙᴀᴛ: &8";

    private final Set<UUID> kickedPlayers = new HashSet<>();
    private CombatManager combatManager;
    private CombatMenu combatMenu;
    private WebhookNotifier webhookNotifier;
    private boolean shuttingDown;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        combatManager = new CombatManager(this);
        combatMenu = new CombatMenu(this);
        webhookNotifier = new WebhookNotifier(this);
        getServer().getPluginManager().registerEvents(this, this);
        getServer().getPluginManager().registerEvents(combatMenu, this);
        getCommand("combat").setExecutor(this);
        combatManager.start();
    }

    @Override
    public void onDisable() {
        shuttingDown = true;
        if (combatManager != null) {
            combatManager.clearAll();
        }
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onPlayerDamage(EntityDamageByEntityEvent event) {
        if (!(event.getEntity() instanceof Player victim) || event.getFinalDamage() <= 0) {
            return;
        }

        Player attacker = null;
        if (event.getDamager() instanceof Player player) {
            attacker = player;
        } else if (event.getDamager() instanceof Projectile projectile && projectile.getShooter() instanceof Player player) {
            attacker = player;
        }

        if (attacker == null || attacker.equals(victim) || !getConfig().getBoolean("combat.enabled", true)) {
            return;
        }

        boolean newCombat = !combatManager.isInCombat(attacker.getUniqueId())
                || !combatManager.isInCombat(victim.getUniqueId());
        combatManager.tag(attacker, victim);
        if (newCombat) {
            webhookNotifier.send("Combat started", attacker.getName() + " and " + victim.getName() + " entered combat.");
        }
    }

    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        combatManager.end(event.getEntity().getUniqueId());
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onPlayerKick(PlayerKickEvent event) {
        kickedPlayers.add(event.getPlayer().getUniqueId());
    }

    @EventHandler(priority = EventPriority.MONITOR)
    public void onPlayerQuit(PlayerQuitEvent event) {
        Player player = event.getPlayer();
        UUID playerId = player.getUniqueId();
        UUID opponentId = combatManager.getOpponent(playerId);
        if (opponentId == null) {
            kickedPlayers.remove(playerId);
            return;
        }

        boolean exempt = shuttingDown || kickedPlayers.remove(playerId);
        combatManager.end(playerId);
        if (exempt) {
            return;
        }

        Player opponent = Bukkit.getPlayer(opponentId);
        String opponentName = opponent == null ? opponentId.toString() : opponent.getName();
        if (opponent != null) {
            opponent.sendMessage(color(PREFIX + player.getName() + " logged out during combat."));
        }
        webhookNotifier.send("Combat log", player.getName() + " combat-logged against " + opponentName + ".");
        applyPunishment(player);
    }

    private void applyPunishment(Player player) {
        switch (getConfig().getString("punishment", "KILL").toUpperCase(Locale.ROOT)) {
            case "CLEAR_INVENTORY" -> player.getInventory().clear();
            case "NONE" -> {
            }
            default -> {
                if (!player.isDead()) {
                    player.setHealth(0.0);
                }
            }
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 0 || args[0].equalsIgnoreCase("menu")) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage(color(PREFIX + "only players can open the menu."));
                return true;
            }
            combatMenu.open(player);
            return true;
        }

        if (args[0].equalsIgnoreCase("reload")) {
            if (!requireAdmin(sender)) {
                return true;
            }
            reloadConfig();
            if (!getConfig().getBoolean("combat.enabled", true)) {
                combatManager.clearAll();
            }
            sender.sendMessage(color(PREFIX + "settings reloaded."));
            return true;
        }

        if (args[0].equalsIgnoreCase("webhook")) {
            if (!requireAdmin(sender)) {
                return true;
            }
            if (args.length != 2) {
                sender.sendMessage(color(PREFIX + "use /combat webhook <url|off>"));
                return true;
            }
            if (args[1].equalsIgnoreCase("off")) {
                getConfig().set("webhook.enabled", false);
                getConfig().set("webhook.url", "");
                saveConfig();
                sender.sendMessage(color(PREFIX + "webhook disabled."));
                return true;
            }
            getConfig().set("webhook.url", args[1]);
            getConfig().set("webhook.enabled", true);
            saveConfig();
            sender.sendMessage(color(PREFIX + "webhook enabled."));
            return true;
        }

        sender.sendMessage(color(PREFIX + "commands: /combat menu, /combat reload, /combat webhook <url|off>"));
        return true;
    }

    private boolean requireAdmin(CommandSender sender) {
        if (sender.hasPermission("combat.admin")) {
            return true;
        }
        sender.sendMessage(color(PREFIX + "you do not have permission."));
        return false;
    }

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

    static ItemStack createItem(String materialName, String name, String... lore) {
        ItemStack item = XMaterial.matchXMaterial(materialName)
                .map(XMaterial::parseItem)
                .orElseThrow(() -> new IllegalArgumentException("Unknown menu material: " + materialName));
        item.setAmount(1);
        var meta = item.getItemMeta();
        meta.setDisplayName(color(name));