Skip to content
MateoF24 edited this page Aug 15, 2026 · 5 revisions

API

For mod developers. Everything here is server-side.

OnTimeAPI.API_VERSION is 2. Version 1 was OnTime 4.x.

This is the one page in the wiki that talks about older versions. Anyone compiling against a contract needs to know what moved and what to use instead; everywhere else, the current version is the only one described.

Getting hold of it

OnTimeAPI api = OnTimeAPI.getInstance();

There is also an entrypoint, called once when OnTime is ready:

public class MyIntegration implements OnTimeEntrypoint {
    @Override
    public void onOntimeInitialize(OnTimeAPI api) {
        api.onRunFinish(run -> myThing(run.timerName()));
    }
}
  • Fabric — declare it under the ontime entrypoint in fabric.mod.json.
  • NeoForge and Forge — send it by IMC with the method register.

Definitions and executions

The distinction runs through the whole API, and it is the thing to understand first:

TimerDefinition what an operator set up: length, commands, titles, repeat, sequence, triggers, position
TimerRunInfo one execution of it: its runId, its clock, its phase, its audience, its owner

A definition can have no executions, or twenty. Reading a definition never tells you what is on screen — that belongs to an execution, and there may be several different answers at once. See Runs and Audiences.

Anything that acts on an execution takes its runId.

Timers

boolean                   createTimer(String name, int h, int m, int s, boolean countUp)
boolean                   removeTimer(String name)
boolean                   hasTimer(String name)
Optional<TimerDefinition> getDefinition(String name)
List<TimerDefinition>     getDefinitions()

boolean setTimerTime(String name, int h, int m, int s)
boolean addTimerTime(String name, int h, int m, int s)
boolean setTimerRepeat(String name, boolean repeat, int count)
boolean setTimerTitle(String name, String slot, String text)
boolean clearTimerTitles(String name)
boolean setTimerPosition(String name, String preset)
boolean setTimerCustomPosition(String name, int x, int y)
boolean setTimerScale(String name, Float scale)
boolean addScheduledCommand(String name, long atSeconds, String command)
boolean addFinishCommand(String name, String command)
boolean clearScheduledCommands(String name)

Executions

Optional<UUID>         startGlobal(String name)
List<UUID>             startRun(String name, Audience audience, RunMode mode)

List<TimerRunInfo>     getRuns()
List<TimerRunInfo>     getRunsOf(String name)
List<TimerRunInfo>     getRunsFor(UUID player)
Optional<TimerRunInfo> getRun(UUID runId)
Optional<TimerRunInfo> getPrimaryRun()

boolean pauseRun(UUID runId)
boolean resumeRun(UUID runId)
boolean stopRun(UUID runId)
boolean resetRun(UUID runId)
int     stopAllRuns()
boolean setRunAudience(UUID runId, Audience audience)

startRun returns one id per execution it created — one for RunMode.SHARED, one per player for RunMode.EACH.

getPrimaryRun is the oldest execution in flight. It exists for the cases that genuinely need a single answer, such as substituting into one line of text, and its pick is arbitrary but stable.

Audiences

Audience.global()
Audience.ofPlayers(Set<UUID> players)

Events

void onRunStart  (Consumer<TimerRunInfo> listener)
void onRunFinish (Consumer<TimerRunInfo> listener)
void onRunPause  (Consumer<TimerRunInfo> listener)
void onRunResume (Consumer<TimerRunInfo> listener)
void onRunTick   (Consumer<TimerRunInfo> listener)

Each fires once per execution, so a timer running for fifty people in each mode fires fifty times. TimerRunInfo.runId() says which.

onRunTick fires once a second per execution, not once a tick.

Extending it

void registerFinishCondition(String name, Supplier<Boolean> condition)
void unregisterFinishCondition(String name)

void registerTimerPlaceholder(String key, Function<Timer, String> resolver)

void setPermissionProvider(IPermissionProvider provider)

String getScoreboardObjectiveName()

A registered placeholder is available in timer commands as {key} — see Timer Commands for the built-in ones.

A permission provider is asked whether a player may run a command. It is not consulted for command blocks, the console, functions or RCON, which are always allowed. See LuckPerms Integration.

Drawing the counter yourself

ITimerRenderer replaces how the counter is drawn. Register it with TimerRendererRegistry, client-side.

On Minecraft 26.1 and later, render receives GuiGraphicsExtractor instead of GuiGraphics; the game removed the latter.


What changed in 5.0.0

The 4.x API was built on "the active timer". getActiveTimer(), stopActiveTimer(), pauseActiveTimer() and TimerInfo all assumed there was one timer with one clock. Concurrent executions make that unanswerable, so the API was rebuilt rather than extended.

Removed. These could only have answered with a half-truth:

4.x Now
getActiveTimer() getRuns(), or getRunsOf(name). If you truly need one answer, getPrimaryRun()
stopActiveTimer() stopRun(runId), or stopAllRuns()
pauseActiveTimer() pauseRun(runId) / resumeRun(runId). The 4.x method toggled; these do not, so you always know what you asked for
startTimer(name) → boolean startGlobal(name) → Optional<UUID>, which hands back the id you need afterwards
getTimer(name) → TimerInfo getDefinition(name) → TimerDefinition
getAllTimers() → Map getDefinitions() → List
getTimerTitles(name) getDefinition(name).titles()
getScheduledCommands(name) getDefinition(name).scheduledCommands()
getFinishCommands(name) getDefinition(name).finishCommands()
registerOnStart/Finish/Pause/Resume/Tick(Consumer<TimerInfo>) onRunStart/Finish/Pause/Resume/Tick(Consumer<TimerRunInfo>)
TimerInfo TimerDefinition and TimerRunInfo

4.x kept some of these working for a version as deprecated. 5.0.0 does not: none of them survive, and there is no compatibility layer.

Also changed. A command is a command and a pause, not a string: TimerDefinition reports finishCommands and scheduledCommands as TimedCommand.

And in 4.0.0, for the record: ITimerRenderer.render began receiving GuiGraphicsExtractor on 26.x, and custom permission providers stopped being consulted for non-player command sources.

Clone this wiki locally