probada125

Create a Minecraft Spigot/Paper plugin with the following behavior:

  1. The plugin must continuously monitor the number of online players on the server.
  2. If the number of online players becomes 0, start a 5 minute countdown timer.
  3. During this 5 minute period:

* If any player joins the server, the timer must be cancelled immediately.

  1. If after the full 5 minutes there are still 0 players online, the plugin must automatically restart the server using the Bukkit/Spigot API (Bukkit.spigot().restart() or equivalent safe restart method).
  2. The plugin must:

* Work on Spigot and Paper servers * Be lightweight and efficient * Not cause lag

  1. Add a config.yml file with these options:

* check-interval: 60 (seconds between checks) * restart-delay: 300 (seconds to wait when player count is 0)

  1. Add console messages such as:

* "No players online. Restart scheduled in 5 minutes." * "Player joined. Restart cancelled." * "Server restarting due to inactivity."

Important:

* Do not add any other features. * Do not modify gameplay. * Only implement the auto restart when server stays empty for 5 minutes.

Kodari AI
KodariMar 6 at 8:22 am 15,684 (v2)

I’ll create a lightweight auto-restart plugin that monitors player count and restarts the server after 5 minutes of inactivity.

AutoRestartPlugin
Automatically restarts the server when no players are online for a configured period. Monitors player count at regular intervals and schedules a restart if the server stays empty. Restart is cancelled immediately if a player joins during the countdown. Lightweight and efficient with configurable check and delay timers.

Now I’ll create the plugin files:

Plugin created successfully!

How it works:

  • Checks player count every 60 seconds (configurable)

  • When 0 players detected, schedules restart in 5 minutes (300 seconds, configurable)

  • If player joins during countdown, restart is cancelled immediately

  • Uses Bukkit.spigot().restart() for safe server restart

  • Lightweight with minimal overhead

Configuration:

  • check-interval: 60 - seconds between player count checks

  • restart-delay: 300 - seconds to wait before restart (5 minutes)

Console messages:

  • “No players online. Restart scheduled in 5 minutes.”

  • “Player joined. Restart cancelled.”

  • “Server restarting due to inactivity.”

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

import com.autorestart.listener.PlayerJoinListener;
import lombok.Getter;
import org.bukkit.plugin.java.JavaPlugin;

@Getter
public class AutoRestartPlugin extends JavaPlugin {
    private RestartManager restartManager;
    
    @Override
    public void onEnable() {
        saveDefaultConfig();
        
        restartManager = new RestartManager(this);
        restartManager.startChecking();
        
        getServer().getPluginManager().registerEvents(new PlayerJoinListener(this), this);
        
        getLogger().info("AutoRestart enabled - monitoring player count");
    }
    
    @Override
    public void onDisable() {
        if (restartManager != null) {
            restartManager.stopChecking();
        }
        getLogger().info("AutoRestart disabled");
    }
}