File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " mcutils-js-api" ,
3- "version" : " 2.0.25 " ,
3+ "version" : " 2.0.26 " ,
44 "module" : " dist/index.js" ,
55 "main" : " dist/index.js" ,
66 "types" : " dist/index.d.ts" ,
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type { CachedPlayer } from "./types/cache/cached-player";
77import type { CachedPlayerName } from "./types/cache/cached-player-name" ;
88import type { ServerPlatform } from "./types/server/server" ;
99import type { Cape } from "./types/player/cape/cape" ;
10+ import { ServerRegistryEntry } from "./types/server-registry/server-registry-entry" ;
1011
1112export class McUtilsAPI {
1213 private readonly endpoint : string ;
@@ -310,6 +311,22 @@ export class McUtilsAPI {
310311 error : ( await response . json ( ) ) as ErrorResponse ,
311312 } ;
312313 }
314+
315+ /**
316+ * Fetch the list of available server registry entries.
317+ *
318+ * @param query the query to search for (eg: aetheria)
319+ * @returns the list of server registry entries or the error (if one occurred)
320+ */
321+ async fetchServerRegistryEntries ( query : string ) : Promise < { entries ?: ServerRegistryEntry [ ] ; error ?: ErrorResponse } > {
322+ const response = await fetch ( `${ this . endpoint } /servers${ this . buildParams ( { query : query } ) } ` ) ;
323+ if ( response . ok ) {
324+ return { entries : ( await response . json ( ) ) as ServerRegistryEntry [ ] } ;
325+ }
326+ return {
327+ error : ( await response . json ( ) ) as ErrorResponse ,
328+ } ;
329+ }
313330}
314331
315332export default McUtilsAPI ;
Original file line number Diff line number Diff line change @@ -2,9 +2,6 @@ import McUtilsAPI from ".";
22
33const api = new McUtilsAPI ( ) ;
44
5- api . fetchJavaServer ( "aetheria.cc ") . then ( ( result ) => {
5+ api . fetchServerRegistryEntries ( "wild ") . then ( ( result ) => {
66 console . log ( result ) ;
7- } ) ;
8- api . fetchPlayer ( "ImFascinated" ) . then ( ( result ) => {
9- console . log ( result . player ?. skin ?. parts . FULLBODY_FRONT ) ;
107} ) ;
You can’t perform that action at this time.
0 commit comments