From 0a0ae4c89a67f89e4ba2a2da35bdeaf65f38d59d Mon Sep 17 00:00:00 2001 From: Owen Date: Sun, 28 Jul 2024 16:02:22 +0100 Subject: [PATCH] Update main.ts - Fix getServerInfo still relying on Nova data. - Remove Nova default export. --- src/main.ts | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/main.ts b/src/main.ts index 7e90556..b2c7bc6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,38 +6,28 @@ import Squaremap from './api/squaremap/Squaremap.js' import MCAPI from "mojang-lib" import { OAPIV2, OAPIV3 } from './OAPI.js' -import type { PlayersResponse, SquaremapPlayersResponse } from './types/index.js' export async function fetchServer(name = "play.earthmc.net") { const server = await MCAPI.servers.get(name) return { - max: server?.players?.max ?? 0, - online: server?.players?.online ?? 0, - serverOnline: !!server + isOnline: !!server, + players: { + max: server?.players?.max ?? 0, + online: server?.players?.online ?? 0 + } } } -export async function getServerInfo() { +export async function getServerInfo(aurora: { numOnline: number }) { try { const serverData = await fetchServer() - const novaData = await endpoint.playerData("nova") - const auroraData = await endpoint.playerData("aurora") - - const online = serverData.online - const novaCount = novaData.currentcount ?? 0 - const auroraCount = auroraData.players.length ?? 0 + const online = serverData.players.online - const serverInfo = { - ...serverData, - nova: novaCount, - aurora: auroraCount - } + const auroraCount = aurora.numOnline < 1 ? 0 : aurora.numOnline + const queue = online < 1 ? 0 : online - auroraCount - return { - queue: online < 1 ? 0 : online - auroraCount - novaCount, - ...serverInfo - } + return { queue, ...serverData } } catch (err: unknown) { throw new FetchError(`Error fetching server info!\n${err}`) } @@ -49,7 +39,6 @@ export class OfficialAPI { } export const Aurora = new Squaremap('aurora') -export const Nova = new Dynmap('nova') export { Dynmap, Squaremap,