Skip to content

Commit b36a399

Browse files
authored
Merge pull request #203 from MartyX98/main
Update README for Crafty Controller widget
2 parents 45dcac3 + fc178d5 commit b36a399

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

registry/widgets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@
148148
"description": "show the status of Minecraft server managed by Crafty Controller",
149149
"author": "MartyX98",
150150
"directory": "crafty-controller-minecraft-server",
151-
"readme_hash": "2e3854d9fc413e2845ed474f41185322953cd8ab",
151+
"readme_hash": "60a54ba1497f60f0031c84313e5cdc178bb1042d",
152152
"time_added": "2025-08-16T18:10:24.2213Z",
153-
"time_updated": "2025-09-25T04:55:13.926064823Z"
153+
"time_updated": "2025-11-04T21:32:36.750473688Z"
154154
},
155155
{
156156
"title": "Cryptopanic News",

widgets/crafty-controller-minecraft-server/README.md

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,49 @@
99
#### When server is running:
1010
![Server running preview](./Preview_online.png)
1111

12-
Displays server's custom icon, inferred IP, MOTD message and some statistics. The display of MOTD can be disabled in the beginning of the template in the user settings section, and the widget will look like this:
12+
Displays server's custom icon, inferred IP, MOTD message and some statistics. The display of MOTD can be disabled in the options section of the template, and the widget will look like this:
1313

1414
![Server running with disabled MOTD preview](./Preview_online_disabledMOTD.png)
1515

1616
## Yaml
1717
```yaml
1818
- type: custom-api
19-
title: Crafty Controller Minecraft Server
19+
title: Crafty Controller - Minecraft Server
2020
cache: 5s
21+
options:
22+
base-url: ${CRAFTY_URL}
23+
api-key: ${CRAFTY_API_TOKEN}
24+
server-id: ${CRAFTY_SERVER_ID}
25+
display-MOTD: true
2126
allow-insecure: true
22-
url: ${CRAFTY_URL}/api/v2/servers/${CRAFTY_SERVER_ID}/stats
23-
headers:
24-
Authorization: Bearer ${CRAFTY_API_TOKEN}
25-
Accept: application/json
2627
template: |
27-
<!-- USER SETTINGS SECTION -->
28-
29-
<!-- Change true to false if you wish to not display the MOTD -->
30-
{{ $displayMOTD := true }}
31-
32-
<!-- END OF USER SETTINGS SECTION -->
33-
34-
{{ $is_running := .JSON.Bool "data.running" }}
35-
{{ $online_players := .JSON.Int "data.online" | formatNumber }}
36-
{{ $max_players := .JSON.Int "data.max" | formatNumber }}
37-
{{ $name := .JSON.String "data.world_name" }}
38-
{{ $size := .JSON.String "data.world_size" }}
39-
{{ $version := .JSON.String "data.version" }}
40-
{{ $icon := .JSON.String "data.icon" }}
41-
{{ $server_ip := .JSON.String "data.server_id.server_ip" }}
42-
{{ $server_port := .JSON.String "data.server_id.server_port" }}
43-
{{ $motd := .JSON.String "data.desc" }}
28+
{{/* Required config options */}}
29+
{{ $baseURL := .Options.StringOr "base-url" "" }}
30+
{{ $apiKey := .Options.StringOr "api-key" "" }}
31+
{{ $serverID := .Options.StringOr "server-id" "" }}
32+
33+
{{/* Optional config options */}}
34+
{{ $displayMOTD := .Options.BoolOr "display-MOTD" true }}
35+
36+
{{ $serverStats := newRequest (print $baseURL "/api/v2/servers/" $serverID "/stats")
37+
| withHeader "Authorization" (print "Bearer " $apiKey)
38+
| withHeader "Accept" "application/json"
39+
| getResponse }}
40+
41+
{{ $is_running := $serverStats.JSON.Bool "data.running" }}
42+
{{ $online_players := $serverStats.JSON.Int "data.online" | formatNumber }}
43+
{{ $max_players := $serverStats.JSON.Int "data.max" | formatNumber }}
44+
{{ $name := $serverStats.JSON.String "data.world_name" }}
45+
{{ $size := $serverStats.JSON.String "data.world_size" }}
46+
{{ $version := $serverStats.JSON.String "data.version" }}
47+
{{ $icon := $serverStats.JSON.String "data.icon" }}
48+
{{ $server_ip := $serverStats.JSON.String "data.server_id.server_ip" }}
49+
{{ $server_port := $serverStats.JSON.String "data.server_id.server_port" }}
50+
{{ $motd := $serverStats.JSON.String "data.desc" }}
4451
4552
{{ $server_addr := "" }}
4653
{{ if and ($is_running) (eq $server_ip "127.0.0.1") }}
47-
{{ $server_addr = printf "%s:%s" (replaceMatches "https?://" "" "${CRAFTY_URL}") $server_port }}
54+
{{ $server_addr = printf "%s:%s" (replaceMatches "https?://" "" $baseURL) $server_port }}
4855
{{ else if $is_running }}
4956
{{ $server_addr = printf "%s:%s" $server_ip $server_port }}
5057
{{ end }}
@@ -55,9 +62,9 @@ Displays server's custom icon, inferred IP, MOTD message and some statistics. Th
5562
{{ end }}
5663
5764
<!-- I couldn't find documentation describing the "waiting_start" state or the other booleans below. Implementation might not be correct. -->
58-
{{ $updating := .JSON.Bool "data.updating" }}
59-
{{ $importing := .JSON.Bool "data.importing" }}
60-
{{ $crashed := .JSON.Bool "data.crashed" }}
65+
{{ $updating := $serverStats.JSON.Bool "data.updating" }}
66+
{{ $importing := $serverStats.JSON.Bool "data.importing" }}
67+
{{ $crashed := $serverStats.JSON.Bool "data.crashed" }}
6168
6269
<div style="display:flex; align-items:center; gap:12px;">
6370
<!-- Server Icon -->
@@ -80,7 +87,7 @@ Displays server's custom icon, inferred IP, MOTD message and some statistics. Th
8087
{{ if and ($is_running) (not $starting) (not (eq $server_addr "")) }}
8188
<div style="font-size:0.9em; color:var(--color-secondary);">
8289
<span class="size-h6 color-secondary">
83-
{{ $server_addr }}
90+
- {{ $server_addr }}
8491
</span>
8592
</div>
8693
{{ end }}
@@ -90,7 +97,7 @@ Displays server's custom icon, inferred IP, MOTD message and some statistics. Th
9097
{{ if and ($is_running) (not $starting) }}
9198
{{ if and (not (eq $motd "")) ($displayMOTD) }}
9299
<div style="font-size:0.9em; color:var(--color-secondary);">
93-
{{ replaceMatches "§." "" $motd }}
100+
{{ replaceMatches "§." "" $motd }}
94101
</div>
95102
{{ end }}
96103
@@ -117,8 +124,8 @@ Displays server's custom icon, inferred IP, MOTD message and some statistics. Th
117124
## Environment variables
118125
- `CRAFTY_URL` - the URL or [IP]:[Port] to your Crafty Controller instance.
119126
- `CRAFTY_SERVER_ID` - ID of the minecraft server you want to display info about. You can find it in the URL of the server details in Crafty Controller's dashboard. (Ex.; `https://[CRAFTY_URL]/panel/server_detail?id=[CRAFTY_SERVER_ID]`)
120-
- `CRAFTY_API_TOKEN` - Your crafty API token. Requires `TERMINAL`, `CONFIG` and `PLAYERS` permissions.
127+
- `CRAFTY_API_TOKEN` - Your crafty API token. Requires `Full Access` permission.
121128

122129
## 🍻 Cheers
123130

124-
* Author of [minecraft-server//github.com/MartyX98/community-widgets/blob/main/widgets/minecraft-server/README.md) community widget from which I took a lot of inspiration.
131+
* @not-first as the author of [minecraft-server](/widgets/minecraft-server/README.md) community widget from which I took a lot of inspiration.

0 commit comments

Comments
 (0)