Class BukkitPowerExecutor

java.lang.Object
com.ultikits.ultitools.utils.BukkitPowerExecutor
All Implemented Interfaces:
PowerActionHandler.PowerExecutor

final class BukkitPowerExecutor extends Object implements PowerActionHandler.PowerExecutor
Turns the handler's stop or restart into one main-thread scheduler task, and answers whether a restart would actually restart this server.

The action is scheduled 20L ticks after the result frame was handed to the socket, so the panel always receives its answer first. Scheduling goes through PluginInitiationUtils.scheduleUnlessDisabling(String, java.util.function.Supplier), the single hand-off check every scheduler call reachable from the socket thread uses: while the framework is disabling the work is dropped with one FINE line instead of throwing.

Restart is supported only when the file the server would run — the part of settings.restart-script in spigot.yml before its first space, or "./start.sh" when the key is absent — exists as a regular file, resolved against the server's working directory when that path is relative. Spigot's own restart stops the server when that file is missing; this check keeps a requested restart from silently becoming a stop.

This is the only Bukkit-facing part of the power path; the handler stays unit-testable without a live server. Package-private framework plumbing; not for module use.

Since:
6.3.1
  • Field Details

    • DELAY_TICKS

      static final long DELAY_TICKS
      The delay between the result frame and the stop or restart, matching the contract's "1 s".
      See Also:
    • DEFAULT_RESTART_SCRIPT

      static final String DEFAULT_RESTART_SCRIPT
      The value Spigot uses for settings.restart-script when the key is absent.
      See Also:
    • plugin

      private final org.bukkit.plugin.Plugin plugin
    • workingDirectory

      private final File workingDirectory
    • restartScriptPath

      private final Supplier<String> restartScriptPath
    • stopAction

      private final Runnable stopAction
    • restartAction

      private final Runnable restartAction
  • Constructor Details

    • BukkitPowerExecutor

      BukkitPowerExecutor(org.bukkit.plugin.Plugin plugin, File workingDirectory, Supplier<String> restartScriptPath, Runnable stopAction, Runnable restartAction)
      Creates the executor over explicit collaborators.
      Parameters:
      plugin - the plugin whose scheduler task owns the stop or restart
      workingDirectory - the server's working directory, against which a relative restart-script path is resolved
      restartScriptPath - supplies settings.restart-script as configured, or null
      stopAction - what the scheduled task does on a stop; production passes Bukkit::shutdown
      restartAction - what the scheduled task does on a restart; production passes Bukkit.spigot()::restart
  • Method Details

    • create

      static BukkitPowerExecutor create()
      Builds the production executor: this plugin's scheduler, the process working directory, the live spigot.yml value, and the platform's own stop and restart calls.
      Returns:
      the executor the wiring uses
    • restartSupported

      public boolean restartSupported()
      Whether the file the platform would actually run exists as a regular file.

      This mirrors Spigot's own rule exactly, because any laxer answer turns a requested restart into a stop: only the part of the value before the first space names the script (the rest is passed to it as arguments), the value is never trimmed, and "./start.sh" applies only when the key is absent — never to an explicitly empty value, which names no file at all. A directory of that name is not a restart script.

      Specified by:
      restartSupported in interface PowerActionHandler.PowerExecutor
      Returns:
      true when a restart would restart rather than stop
    • scheduleStop

      public void scheduleStop()
      Schedules the stop on the main thread, 20L ticks from now.
      Specified by:
      scheduleStop in interface PowerActionHandler.PowerExecutor
    • scheduleRestart

      public void scheduleRestart()
      Schedules the restart on the main thread, 20L ticks from now.
      Specified by:
      scheduleRestart in interface PowerActionHandler.PowerExecutor
    • schedule

      private void schedule(String what, Runnable action)