From 8e4e95597a319ab2054f592350d2c387058b5f46 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Tue, 15 Oct 2024 10:35:32 -0600 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20minecraft?= =?UTF-8?q?=20server=20status=20widgets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/widgets.md | 40 ++++ src/components/Widgets/MinecraftStatus.vue | 258 +++++++++++++++++++++ src/components/Widgets/WidgetBase.vue | 1 + src/utils/defaults.js | 4 + 4 files changed, 303 insertions(+) create mode 100644 src/components/Widgets/MinecraftStatus.vue diff --git a/docs/widgets.md b/docs/widgets.md index ac03ad54..b3c7fed3 100644 --- a/docs/widgets.md +++ b/docs/widgets.md @@ -40,6 +40,7 @@ Dashy has support for displaying dynamic content in the form of widgets. There a - [Mvg Connection](#mvg-connection) - [Custom search](#custom-search) - [Rescuetime overview](#rescuetime-overview) + - [Minecraft Server](#minecraft-server) - **[Self-Hosted Services Widgets](#self-hosted-services-widgets)** - [System Info](#system-info) - [Cron Monitoring](#cron-monitoring-health-checks) @@ -1378,6 +1379,45 @@ Show an overview of how you have spent your time for the current day. --- +### Minecraft Server + +Show minecraft server status + +

+ +#### Options + +**Field** | **Type** | **Required** | **Description** +--- | --- | --- | --- +**`title`** | `string` | _Optional_ | Display title for server uses server address if not set. +**`server`** | `string` | Required | Server hostname or ip(:port) will use srv records. +**`bedrock`** | `boolean` | _Optional_ | If server is a bedrock edition server. (default false) +**`showMods`** | `boolean` | _Optional_ | Display mod list if available +**`showPlayers`** | `boolean` | _Optional_ | Display player list if available +**`showPlugins`** | `boolean` | _Optional_ | Display plugin list if available + +#### Example + +```yaml + - type: minecraft-status + options: + title: Venity Network + server: play.venitymc.com + bedrock: true + showMods: true + showPlayers: true + showPlugins: true +``` +#### Info + +- **CORS**: 🟢 Enabled +- **Auth**: 🟢 Not Required +- **Price**: 🟢 Free +- **Host**: [Minecraft Server Status](https://mcsrvstat.us/) +- **Privacy**: _See [Minecraft Server Status FAQ](https://mcsrvstat.us/faq)_ + +--- + ## Self-Hosted Services Widgets diff --git a/src/components/Widgets/MinecraftStatus.vue b/src/components/Widgets/MinecraftStatus.vue new file mode 100644 index 00000000..18cfc6d5 --- /dev/null +++ b/src/components/Widgets/MinecraftStatus.vue @@ -0,0 +1,258 @@ + + + + + + diff --git a/src/components/Widgets/WidgetBase.vue b/src/components/Widgets/WidgetBase.vue index c4d4220f..b2e57caa 100644 --- a/src/components/Widgets/WidgetBase.vue +++ b/src/components/Widgets/WidgetBase.vue @@ -86,6 +86,7 @@ const COMPAT = { iframe: 'IframeWidget', image: 'ImageWidget', joke: 'Jokes', + 'minecraft-status': 'MinecraftStatus', 'mullvad-status': 'MullvadStatus', mvg: 'Mvg', linkding: 'Linkding', diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 88b5757d..787c440b 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -240,6 +240,10 @@ module.exports = { holidays: 'https://kayaposoft.com/enrico/json/v2.0/?action=getHolidaysForDateRange', jokes: 'https://v2.jokeapi.dev/joke/', news: 'https://api.currentsapi.services/v1/latest-news', + minecraftPlayerIcon: 'https://mc-heads.net/avatar/', + minecraftPlayerLink: 'https://minecraftuuid.com/?search=', + minecraftServerLink: 'https://mcsrvstat.us/server/', + minecraftStatus: 'https://api.mcsrvstat.us/', mullvad: 'https://am.i.mullvad.net/json', mvg: 'https://www.mvg.de/api/fib/v2/', publicIp: 'https://ipapi.co/json', From e96a8e1f6c430bb8513d22bb9b8b8c883a6f2168 Mon Sep 17 00:00:00 2001 From: Taylor Jones Date: Tue, 15 Oct 2024 10:55:11 -0600 Subject: [PATCH 2/2] Fix linting for MinecraftStatus.vue --- src/components/Widgets/MinecraftStatus.vue | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/components/Widgets/MinecraftStatus.vue b/src/components/Widgets/MinecraftStatus.vue index 18cfc6d5..fc20f96d 100644 --- a/src/components/Widgets/MinecraftStatus.vue +++ b/src/components/Widgets/MinecraftStatus.vue @@ -55,7 +55,7 @@ import StatusIndicator from '@/components/LinkItems/StatusIndicator.vue'; export default { mixins: [WidgetMixin], components: { - StatusIndicator + StatusIndicator, }, data() { return { @@ -78,23 +78,23 @@ export default { }, computed: { title() { - return this.options.title || this.options.server || this.error("options.server not set"); + return this.options.title || this.options.server || this.error('options.server not set'); }, alt() { - return this.title + return this.title; }, icon() { - return `https://api.mcsrvstat.us/icon/${this.server}` + return `https://api.mcsrvstat.us/icon/${this.server}`; }, server() { - return this.options.server || this.error("options.server not set"); + return this.options.server || this.error('options.server not set'); }, bedrock() { return this.options.bedrock === true; }, statusTooltip() { if (!this.status) { - return "Loading..."; + return 'Loading...'; } if (!this.online) { return `${this.server} Offline`; @@ -111,11 +111,11 @@ export default { return this.options.showPlugins && this.plugins.length > 0; }, endpoint() { - return `${widgetApiEndpoints.minecraftStatus}${this.bedrock?'bedrock/':''}3/${this.server}`; + return `${widgetApiEndpoints.minecraftStatus}${this.bedrock ? 'bedrock/' : ''}3/${this.server}`; }, serverLinkEndpoint() { return `${widgetApiEndpoints.minecraftServerLink}${this.server}`; - } + }, }, methods: { playerIconEndpoint(uuid) { @@ -126,7 +126,7 @@ export default { }, /* Make GET request to McSrvStat.US API endpoint */ fetchData() { - this.startLoading() + this.startLoading(); fetch(this.endpoint) .then(response => { if (!response.ok) { @@ -146,26 +146,26 @@ export default { }, /* Assign data variables to the returned data */ processData(data) { - this.online = data.online - this.ip = data.ip - this.port = data.port - this.hostname = data.hostname + this.online = data.online; + this.ip = data.ip; + this.port = data.port; + this.hostname = data.hostname; if (this.online) { - this.version = data.version - this.iconData = data.icon - this.software = data.software - this.gamemode = data.gamemode - this.motd = data.motd.clean || [] - this.players = data.players.list || [] - this.onlinePlayers = data.players.online - this.maxPlayers = data.players.max - this.mods = data.mods || [] - this.plugins = data.plugins || [] + this.version = data.version; + this.iconData = data.icon; + this.software = data.software; + this.gamemode = data.gamemode; + this.motd = data.motd.clean || []; + this.players = data.players.list || []; + this.onlinePlayers = data.players.online; + this.maxPlayers = data.players.max; + this.mods = data.mods || []; + this.plugins = data.plugins || []; } - this.status = true + this.status = true; }, update() { - this.fetchData() + this.fetchData(); }, }, };