lefiraaya

Create plugin for server restart first show 30s countdown in actionbar then execute command/combat removetag all then execute/restart and config so i can do some changes add command /autorestart to execute all things

Kodari AI
KodariJul 31 at 11:48 am 1
AutoRestartPlugin
A configurable Minecraft server restart plugin that starts a 30-second action-bar countdown for every online player, broadcasts customizable status messages, and executes administrator-defined console commands in sequence when the countdown ends. The default sequence removes all combat tags with `combat removetag all` and then runs `restart`. Administrators start or cancel the process with `/autorestart`, while permissions, countdown duration, messages, and command order are managed in the configuration.

Created AutoRestartPlugin.

  • /autorestart starts a configurable 30-second action-bar countdown.

  • /autorestart cancel stops an active countdown.

  • Executes combat removetag all, then restart through the console.

  • Added configurable countdown duration, action-bar text, messages, command sequence, and permission settings.

  • Project includes Gradle build files and Bukkit plugin metadata.

lefiraaya

Did you add config.yml so i can change broadcast messages

Kodari AI
KodariJul 31 at 11:52 am 1

Yes. src/main/resources/config.yml was added with configurable broadcast/action-bar messages, countdown duration, commands, and permission settings.

You can edit the messages there, then reload or restart the plugin for changes to take effect.

lefiraaya

Actionbar and restart not working and also add reload system

Kodari AI
KodariJul 31 at 12:07 pm 1
  1. Fix the action-bar countdown and restart command execution.

  2. Add a reload command that reloads config.yml without restarting the server.

  1. Fixed action-bar delivery using the compatible Spigot component format.

  2. Fixed console command execution through the server command dispatcher.

  3. Added /autorestart reload to reload config.yml.

  4. Added the autorestart.reload permission.

  5. Added configurable reload and usage messages.

Commands:

Plain Text
/autorestart
/autorestart start
/autorestart cancel
/autorestart reload

After updating the plugin JAR, use:

Plain Text
/autorestart reload

The countdown still runs for the configured countdown-seconds, then executes the commands in config.yml in order.

lefiraaya

I gave you before that command combat removetag all execute it at last 5s

Kodari AI
KodariJul 31 at 12:10 pm 1
  1. Move combat removetag all to the 5-second point of the countdown.

  2. Keep the final configured restart command(s) executing when the countdown reaches zero.

Updated the restart sequence:

  • At exactly 5 seconds remaining, it executes:

    Plain Text
    combat removetag all
    
  • At 0 seconds, it executes the configured command:

    Plain Text
    restart
    

The command is configurable in config.yml:

YAML
combat-removetag-command: "combat removetag all"
commands:
  - "restart"
lefiraaya

Make its 1000x optimized

Kodari AI
KodariJul 31 at 12:23 pm 2
  1. Reduce restart-task overhead to one lightweight countdown task.

  2. Cache configuration values and avoid repeated config lookups, allocations, and unnecessary broadcasts.

  3. Preserve the 5-second combat-removal trigger, restart execution, cancellation, and reload behavior.

The current task already runs on a single scheduled countdown, but it reloads configuration and recolors messages during the countdown. I’m caching all settings on enable/reload and removing the unused event listener registration.

Optimized the plugin:

  • Cached all configuration values on enable and /autorestart reload.

  • Removed unnecessary event listener registration.

  • Reused the formatted action-bar component for all players each second.

  • Cached restart commands and messages instead of reading config repeatedly.

  • Kept combat removetag all executing at exactly 5 seconds remaining.

  • Kept restart commands executing at 0 seconds.

  • Preserved /autorestart, /autorestart cancel, and /autorestart reload.

lefiraaya

Remove actionbar because its not working. And add countdown in chat

Kodari AI
KodariJul 31 at 12:30 pm 1
  1. Remove action-bar countdown handling.

  2. Send the countdown through chat messages instead.

  3. Preserve the 5-second combat-removal command, final restart commands, cancellation, and reload support.

Updated:

  • Removed all action-bar code and configuration.

  • Added chat countdown messages to every online player.

  • Added configurable message in config.yml:

YAML
countdown-message: "&cServer restarting in &e%seconds%s&c!"
  • %seconds% is replaced with the remaining time.

  • combat removetag all still executes at 5 seconds.

  • Restart commands still execute at 0 seconds.

  • Reload remains available with /autorestart reload.

lefiraaya

Server restarting not working fix it

Kodari AI
KodariJul 31 at 12:39 pm 1

Fixed the restart execution.

If the configured restart command is not registered or fails to dispatch, the plugin now falls back to Spigot’s native restart method:

YAML
commands:
  - "restart"

The 30-second chat countdown and combat removetag all at 5 seconds remain unchanged. Restart the server once after installing the updated plugin JAR.

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

public class AutoRestartPlugin extends JavaPlugin implements CommandExecutor {

    private BukkitTask countdownTask;
    private int countdownSeconds;
    private String combatRemovetagCommand;
    private String countdownMessage;
    private List<String> restartCommands = Collections.emptyList();
    private String startedMessage;
    private String alreadyRunningMessage;
    private String cancelledMessage;
    private String notRunningMessage;
    private String noPermissionMessage;
    private String usageMessage;
    private String reloadedMessage;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadSettings();

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

    @Override
    public void onDisable() {
        cancelCountdown(false);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
            if (!sender.hasPermission("autorestart.reload")) {
                sendMessage(sender, "no-permission");
                return true;
            }

            reloadConfig();
            loadSettings();
            sendMessage(sender, "reloaded");
            return true;
        }

        if (!sender.hasPermission("autorestart.use")) {
            sendMessage(sender, "no-permission");
            return true;
        }

        if (args.length == 0 || args[0].equalsIgnoreCase("start")) {
            startCountdown(sender);
            return true;
        }

        if (args[0].equalsIgnoreCase("cancel")) {
            if (!isRunning()) {
                sendMessage(sender, "not-running");
                return true;
            }

            cancelCountdown(true);
            sendMessage(sender, "cancelled");
            return true;
        }

        sendMessage(sender, "usage");
        return true;
    }

    private void startCountdown(CommandSender sender) {
        if (isRunning()) {
            sendMessage(sender, "already-running");
            return;
        }

        final int seconds = countdownSeconds;
        final int combatTriggerSecond = Math.min(5, seconds);

        sendMessage(sender, "started");

        countdownTask = new BukkitRunnable() {
            private int remaining = seconds;

            @Override
            public void run() {
                if (remaining <= 0) {
                    countdownTask = null;
                    cancel();
                    executeRestartCommands();
                    return;
                }

                if (remaining == combatTriggerSecond) {
                    executeCommand(combatRemovetagCommand);
                }

                sendCountdownMessage(remaining);
                remaining--;
            }
        }.runTaskTimer(this, 0L, 20L);
    }

    private void executeRestartCommands() {
        for (String configuredCommand : restartCommands) {
            executeCommand(configuredCommand);
        }
    }

    private void executeCommand(String configuredCommand) {
        if (configuredCommand == null) {
            return;
        }

        String command = configuredCommand.trim();
        if (command.startsWith("/")) {
            command = command.substring(1).trim();
        }

        if (!command.isEmpty()) {
            boolean executed = getServer().dispatchCommand(getServer().getConsoleSender(), command);
            if (!executed && command.equalsIgnoreCase("restart")) {
                getServer().spigot().restart();
            }
        }
    }

    private void sendCountdownMessage(int seconds) {
        String message = countdownMessage.replace("%seconds%", String.valueOf(seconds));
        for (Player player : Bukkit.getOnlinePlayers()) {
            player.sendMessage(message);
        }
    }

    private void sendMessage(CommandSender sender, String path) {
        String message;

        switch (path) {
            case "started":
                message = startedMessage;
                break;
            case "already-running":
                message = alreadyRunningMessage;
                break;
            case "cancelled":
                message = cancelledMessage;
                break;
            case "not-running":
                message = notRunningMessage;
                break;
            case "no-permission":
                message = noPermissionMessage;
                break;
            case "usage":
                message = usageMessage;
                break;
            case "reloaded":
                message = reloadedMessage;
                break;
            default:
                return;
        }

        if (!message.isEmpty()) {
            sender.sendMessage(message);
        }
    }

    private void loadSettings() {
        countdownSeconds = Math.max(1, getConfig().getInt("countdown-seconds", 30));
        combatRemovetagCommand = getConfig().getString("combat-removetag-command", "combat removetag all");
        countdownMessage = color(getConfig().getString("countdown-message", "&cServer restarting in &e%seconds%s&c!"));
        restartCommands = Collections.unmodifiableList(new ArrayList<>(getConfig().getStringList("commands")));

        startedMessage = configuredMessage("started");
        alreadyRunningMessage = configuredMessage("already-running");
        cancelledMessage = configuredMessage("cancelled");
        notRunningMessage = configuredMessage("not-running");
        noPermissionMessage = configuredMessage("no-permission");
        usageMessage = configuredMessage("usage");
        reloadedMessage = configuredMessage("reloaded");
    }