Arjun

🔴 ARED SMP — STARTING SOON!

🟢 Start Sequence 1️⃣ White Color 2️⃣ Yellow Color 3️⃣ Red Color 🔴 ➡️ SMP STARTS!

🔊 Start Sound: Totem Pop

⚔️ PvP: OFF during the grace period ⏳ Grace Period: 20 Minutes

🌱 Once the 20-minute grace period ends, PvP will be enabled.

🔥 Get Ready — Ared SMP is starting!

Kodari AI
KodariOct 3 at 4:55 am 1
AredSmpStartSequence
Manages the Ared SMP server start sequence. When triggered, the plugin broadcasts a three-step color countdown (white, yellow, red) with a totem pop sound effect, followed by an SMP started message. It enforces a 20-minute PvP grace period after the sequence completes, disabling PvP damage during this time. Once the grace period expires, PvP is automatically enabled and players are notified. The plugin provides a command to initiate the start sequence and handles all timing, messaging, and PvP state management automatically.
  1. Add the /aredstart admin command and a timed white → yellow → red startup sequence.

  2. Enforce a configurable 20-minute PvP grace period, then announce that PvP is enabled.

  3. Add the plugin descriptor and default messages/settings.

Created the AredSMP plugin with /aredstart, the timed white → yellow → red sequence, a totem-pop sound, and a configurable 20-minute PvP grace period. PvP is blocked for player melee and player-fired projectiles during the grace period.

Kodari can make mistakes. Review important code before using.
Files
src
Code
3 155
src/main/java/com/ared/smp/AredSMPPlugin.java
package com.ared.smp;

import com.cryptomorin.xseries.XSound;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
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.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

public final class AredSMPPlugin extends JavaPlugin implements Listener {
    private BukkitTask countdownTask;
    private BukkitTask gracePeriodTask;
    private boolean gracePeriodActive;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        getServer().getPluginManager().registerEvents(this, this);
    }

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

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!command.getName().equalsIgnoreCase("aredstart")) {
            return false;
        }
        if (!sender.hasPermission("ared.start")) {
            sender.sendMessage(color(getConfig().getString("messages.no-permission", "&cYou do not have permission to start the SMP.")));
            return true;
        }
        if (countdownTask != null || gracePeriodActive) {
            sender.sendMessage(color(getConfig().getString("messages.already-started", "&cThe start sequence or grace period is already active.")));
            return true;
        }

        sender.sendMessage(color(getConfig().getString("messages.command-started", "&aAred SMP start sequence started.")));
        startSequence();
        return true;
    }

    private void startSequence() {
        broadcast("messages.starting-soon");
        long stepTicks = Math.max(1L, getConfig().getLong("countdown-step-seconds", 5L) * 20L);

        countdownTask = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
            private int step;

            @Override
            public void run() {
                java.util.List<String> sequence = getConfig().getStringList("messages.sequence");
                if (step < sequence.size()) {
                    Bukkit.broadcastMessage(color(sequence.get(step)));
                    step++;
                    return;
                }

                countdownTask.cancel();
                countdownTask = null;
                broadcast("messages.smp-starts");
                playStartSound();
                beginGracePeriod();
            }
        }, stepTicks, stepTicks);
    }

    private void beginGracePeriod() {
        gracePeriodActive = true;
        long graceMinutes = Math.max(1L, getConfig().getLong("grace-period-minutes", 20L));
        for (String message : getConfig().getStringList("messages.grace-period")) {
            Bukkit.broadcastMessage(color(message.replace("{minutes}", Long.toString(graceMinutes))));
        }

        gracePeriodTask = Bukkit.getScheduler().runTaskLater(this, () -> {
            gracePeriodActive = false;
            gracePeriodTask = null;
            broadcast("messages.pvp-enabled");
        }, graceMinutes * 60L * 20L);
    }

    @EventHandler
    public void onPlayerDamage(EntityDamageByEntityEvent event) {
        if (!gracePeriodActive || !(event.getEntity() instanceof Player)) {
            return;
        }

        if (event.getDamager() instanceof Player
                || event.getDamager() instanceof Projectile projectile && projectile.getShooter() instanceof Player) {
            event.setCancelled(true);
        }
    }

    private void playStartSound() {
        String soundName = getConfig().getString("start-sound", "ENTITY_TOTEM_USE");
        XSound.matchXSound(soundName).ifPresent(sound -> Bukkit.getOnlinePlayers().forEach(sound::play));
    }

    private void broadcast(String path) {
        String message = getConfig().getString(path);
        if (message != null && !message.isBlank()) {
            Bukkit.broadcastMessage(color(message));
        }
    }

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