ayeryuzen

make a grace period and when ever it starts it shows grace period in ren gradent and it turns into a bossbar and when it ends play the dragon roar sound and make it say grace period over!!!

Kodari AI
KodariFri at 7:06 am 1
GracePeriodAnnouncer
A Minecraft plugin that announces a configurable grace period. When the period starts, it displays "GRACE PERIOD" in a rainbow gradient chat message, then converts it into a bossbar showing remaining time. When the period ends, it plays the Ender Dragon roar sound and broadcasts "GRACE PERIOD OVER!!!" in bold. Includes commands to start, stop, and configure the grace period duration.

I’ll add a configurable grace period with PvP protection, a red-gradient boss bar, and commands to start or end it.

Created the grace period plugin. It starts with the server, blocks PvP, and displays a red-gradient boss bar. When it ends, players hear the dragon roar and see “Grace period over!!!”

Operators can use /grace start [seconds], /grace end, and /grace status. The default duration is five minutes.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 205
src/main/java/com/kodari/graceperiod/GracePeriodPlugin.java
package com.kodari.graceperiod;

import com.cryptomorin.xseries.XSound;
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.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.scheduler.BukkitTask;

import java.util.Locale;

public final class GracePeriodPlugin extends JavaPlugin implements Listener {
    private BossBar bossBar;
    private BukkitTask timer;
    private long endsAt;
    private long durationMillis;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        bossBar = Bukkit.createBossBar(gradient("Grace Period"), BarColor.RED, BarStyle.SOLID);
        getServer().getPluginManager().registerEvents(this, this);
        if (getConfig().getBoolean("start-on-enable", true)) {
            startGrace(Math.max(1, getConfig().getInt("duration-seconds", 300)));
        }
    }

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

    private void startGrace(int seconds) {
        if (timer != null) {
            timer.cancel();
        }
        durationMillis = seconds * 1000L;
        endsAt = System.currentTimeMillis() + durationMillis;
        bossBar.setVisible(true);
        for (Player player : Bukkit.getOnlinePlayers()) {
            bossBar.addPlayer(player);
        }
        updateBar();
        timer = Bukkit.getScheduler().runTaskTimer(this, () -> {
            if (System.currentTimeMillis() >= endsAt) {
                endGrace();
            } else {
                updateBar();
            }
        }, 20L, 20L);
    }

    private void updateBar() {
        long remaining = Math.max(0, endsAt - System.currentTimeMillis());
        long seconds = (remaining + 999) / 1000;
        bossBar.setTitle(gradient("Grace Period") + ChatColor.WHITE + " - "
                + String.format(Locale.ROOT, "%02d:%02d", seconds / 60, seconds % 60));
        bossBar.setProgress(Math.min(1.0, (double) remaining / durationMillis));
    }

    private void endGrace() {
        if (timer == null) {
            return;
        }
        timer.cancel();
        timer = null;
        bossBar.removeAll();
        bossBar.setVisible(false);
        Bukkit.broadcastMessage(ChatColor.RED + "Grace period over!!!");
        XSound.matchXSound("ENTITY_ENDER_DRAGON_GROWL").ifPresent(sound -> {
            for (Player player : Bukkit.getOnlinePlayers()) {
                sound.play(player);
            }
        });
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        if (timer != null) {
            bossBar.addPlayer(event.getPlayer());
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onDamage(EntityDamageByEntityEvent event) {
        if (timer == null || !(event.getEntity() instanceof Player)) {
            return;
        }
        Entity attacker = event.getDamager();
        if (attacker instanceof Player) {
            event.setCancelled(true);
        } else if (attacker instanceof Projectile) {
            ProjectileSource shooter = ((Projectile) attacker).getShooter();
            if (shooter instanceof Player) {
                event.setCancelled(true);
            }
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 1 && args[0].equalsIgnoreCase("end")) {
            if (timer == null) {
                sender.sendMessage(ChatColor.RED + "There is no active grace period.");
            } else {
                endGrace();
            }
            return true;
        }
        if (args.length == 1 && args[0].equalsIgnoreCase("status")) {
            if (timer == null) {
                sender.sendMessage(ChatColor.YELLOW + "Grace period is not active.");
            } else {
                long seconds = (Math.max(0, endsAt - System.currentTimeMillis()) + 999) / 1000;
                sender.sendMessage(ChatColor.YELLOW + "Grace period: " + seconds + " seconds remaining.");
            }
            return true;
        }
        if ((args.length == 1 || args.length == 2) && args[0].equalsIgnoreCase("start")) {
            int seconds = getConfig().getInt("duration-seconds", 300);
            if (args.length == 2) {
                try {
                    seconds = Integer.parseInt(args[1]);
                } catch (NumberFormatException ex) {
                    sender.sendMessage(ChatColor.RED + "Enter a positive whole number of seconds.");
                    return true;
                }
            }
            if (seconds < 1) {
                sender.sendMessage(ChatColor.RED + "Enter a positive whole number of seconds.");
                return true;
            }
            startGrace(seconds);
            sender.sendMessage(ChatColor.GREEN + "Grace period started for " + seconds + " seconds.");
            return true;
        }
        return false;
    }

    private String gradient(String text) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < text.length(); i++) {
            int green = 30 + 70 * i / Math.max(1, text.length() - 1);
            String hex = String.format(Locale.ROOT, "%02x%02x%02x", 255, green, green);
            result.append('\u00a7').append('x');
            for (char digit : hex.toCharArray()) {
                result.append('\u00a7').append(digit);
            }
            result.append(text.charAt(i));
        }
        return result.toString();
    }
}