- type: custom-api title: Crafty Controller — Minecraft Server cache: 5s allow-insecure: true url: ${CRAFTY_URL}/api/v2/servers/${CRAFTY_SERVER_ID}/stats headers: Authorization: Bearer ${CRAFTY_API_TOKEN} Accept: application/json template: | {{ $displayMOTD := true }} {{ $is_running := .JSON.Bool "data.running" }} {{ $online_players := .JSON.Int "data.online" | formatNumber }} {{ $max_players := .JSON.Int "data.max" | formatNumber }} {{ $name := .JSON.String "data.world_name" }} {{ $size := .JSON.String "data.world_size" }} {{ $version := .JSON.String "data.version" }} {{ $icon := .JSON.String "data.icon" }} {{ $server_ip := .JSON.String "data.server_id.server_ip" }} {{ $server_port := .JSON.String "data.server_id.server_port" }} {{ $motd := .JSON.String "data.desc" }} {{ $server_addr := "" }} {{ if and ($is_running) (eq $server_ip "127.0.0.1") }} {{ $server_addr = printf "%s:%s" (replaceMatches "https?://" "" "${CRAFTY_URL}") $server_port }} {{ else if $is_running }} {{ $server_addr = printf "%s:%s" $server_ip $server_port }} {{ end }} {{ $starting := false }} {{ if and ($is_running) (eq $max_players "0") (eq $version "False") }} {{ $starting = true }} {{ end }} {{ $updating := .JSON.Bool "data.updating" }} {{ $importing := .JSON.Bool "data.importing" }} {{ $crashed := .JSON.Bool "data.crashed" }}
{{ if eq $icon "" }} Server icon {{ else }} Server icon {{ end }}
{{ $name }} {{ if and ($is_running) (not $starting) (not (eq $server_addr "")) }}
{{ $server_addr }}
{{ end }}
{{ if and ($is_running) (not $starting) }} {{ if and (not (eq $motd "")) ($displayMOTD) }}
{{ replaceMatches "§." "" $motd }}
{{ end }}
{{ $version }} - {{ $online_players }}/{{ $max_players }} players - {{ $size }}
{{ else if $starting }}
Server is starting up..
{{ else if $importing }}
Server is being imported..
{{ else if $updating }}
Server is being updated..
{{ else if $crashed }}
Server has crashed!
{{ else }}
Server is offline
{{ end }}