Skip to content
On this page

Common

KattonAPI

top.katton.apicommon/src/main/kotlin/top/katton/api/KattonAPI.kt
Execute [block] only once for a given [key] under the current script owner namespace.

once

CommonFunction
kotlin
fun once(key: String, namespace: String? = null, block: () -> Unit): Boolean

Execute [block] only once for a given [key] under the current script owner namespace.

When script is reloaded, the markers won't be cleared, so the block won't execute again until the marker is reset with [resetOnce] or [clearOnce].

When called inside a script execution, the default namespace is that script's owner id; outside script execution, the default namespace is "global".

Returns

true if [block] was executed this time, false if it was already executed before.

resetOnce

CommonFunction
kotlin
fun resetOnce(key: String, namespace: String? = null): Boolean

Remove once-guard marker for [key] in the current script owner namespace (or [namespace]).

Returns

true if marker existed and was removed, false otherwise.

clearOnce

CommonFunction
kotlin
fun clearOnce(namespace: String? = null)

Clear all once-guard markers in the current script owner namespace (or [namespace]).

server

CommonProperty
kotlin
val server: MinecraftServer?

Current minecraft server instance. Maybe null during client-side execution.

Use this property when you need optional access to the server. For cases where the server must be available, use [requireServer] instead.

Returns

The current MinecraftServer instance, or null if not available

requireServer

CommonFunction
kotlin
fun requireServer(): MinecraftServer

Requires the Minecraft server instance to be available.

Use this function when the server must be present for the operation to succeed. Throws an error if the server is not available (e.g., during client-side execution or before the server has started).

Returns

The current MinecraftServer instance

Throws

ExceptionDescription
IllegalStateExceptionif the server is not available