Package com.ultikits.ultitools.utils
Class PowerActionHandler
java.lang.Object
com.ultikits.ultitools.utils.PowerActionHandler
- All Implemented Interfaces:
CloudRequestHandler
Handles the ack-first
server.power request: a structured stop or restart that never
passes through the command blocklist and is allowed only while the operator's
ultipanel.capabilities.power-actions switch is on.
The id is recorded and persisted before command.ack is sent, so a redelivered id is
acknowledged again but never stops or restarts the server a second time. The result frame is
handed to the channel before the pre-shutdown hook runs and before the power action is
scheduled, so the panel always learns what happened before the server begins to go down.
Restart is pre-checked against the server's restart-script: Spigot's own restart stops
the server when that script is missing, which would turn a requested restart into a stop that
nobody asked for. The check therefore answers power_unsupported instead of degrading.
Package-private framework plumbing; not for module use.
- Since:
- 6.3.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interfaceThe two callsBukkitPowerExecutorturns into a main-thread stop or restart, kept behind an interface so the handler stays unit-testable without a live server. -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringThe contract's second action value.(package private) static final StringThe contract's first action value.private final Consumer<RemoteActionLog.Entry> (package private) static final Stringserver.powercarries no executor field, so the action log names the panel itself.private final PowerActionHandler.PowerExecutorprivate final DedupeLedgerprivate static final Loggerprivate final BooleanSupplierprivate final Runnable(package private) static final StringThe frozen contract result type every delivery is answered with.(package private) static final StringThe frozen contract request type this handler consumes. -
Constructor Summary
ConstructorsConstructorDescriptionPowerActionHandler(DedupeLedger ledger, BooleanSupplier powerEnabled, PowerActionHandler.PowerExecutor executor, Runnable preShutdownHook, Consumer<RemoteActionLog.Entry> actionLog) Creates the handler. -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringactionType(String action) private voidexecute(CloudRequest request, CloudChannel channel, String action) Runs once per newly recorded id: the operator switch, then (for a restart) the restart pre-check, then the result, the pre-shutdown hook and the scheduled power action in that order.voidhandle(CloudRequest request, CloudChannel channel) Validates the action, then runs persist-acknowledge-execute.private voidrecord(RemoteActionLog.Entry entry) private voidrunPreShutdownHook(String action) A failing hook must not cancel an action the operator asked for: it is logged once and the power action proceeds.private voidThe result frame was already handed to the channel, so a scheduler refusal is reported locally and nothing tries to answer the panel a second time.
-
Field Details
-
TYPE
The frozen contract request type this handler consumes.- See Also:
-
RESULT_TYPE
The frozen contract result type every delivery is answered with.- See Also:
-
ACTION_STOP
The contract's first action value.- See Also:
-
ACTION_RESTART
The contract's second action value.- See Also:
-
ACTOR
server.powercarries no executor field, so the action log names the panel itself.- See Also:
-
LOGGER
-
ledger
-
powerEnabled
-
executor
-
preShutdownHook
-
actionLog
-
-
Constructor Details
-
PowerActionHandler
PowerActionHandler(DedupeLedger ledger, BooleanSupplier powerEnabled, PowerActionHandler.PowerExecutor executor, Runnable preShutdownHook, Consumer<RemoteActionLog.Entry> actionLog) Creates the handler.- Parameters:
ledger- the session ledger the request id is recorded in before the acknowledgementpowerEnabled- the operator'spower-actionsswitch, read on every deliveryexecutor- schedules the stop or restart and reports whether a restart is possiblepreShutdownHook- runs after the result frame and before the power action is scheduledactionLog- receives one allowed or denied entry per delivery, or null to record nothing
-
-
Method Details
-
handle
Validates the action, then runs persist-acknowledge-execute. A payload that does not match the contract propagates asinvalid_messagebefore anything is recorded.- Specified by:
handlein interfaceCloudRequestHandler- Parameters:
request- the parsed requestchannel- the reply channel
-
execute
Runs once per newly recorded id: the operator switch, then (for a restart) the restart pre-check, then the result, the pre-shutdown hook and the scheduled power action in that order. -
runPreShutdownHook
A failing hook must not cancel an action the operator asked for: it is logged once and the power action proceeds. -
schedule
The result frame was already handed to the channel, so a scheduler refusal is reported locally and nothing tries to answer the panel a second time. -
record
-
actionType
-