Skip to content

Commit

Permalink
Add support for MCBE Preview Realms (#44)
Browse files Browse the repository at this point in the history
* Add support for MCBE Preview Realms

* Fix CI

* wait no
  • Loading branch information
MrDiamond64 authored Jan 14, 2024
1 parent 866ce6a commit a602ed3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ npm install prismarine-realms

### RealmAPI

#### .from(authflow: Authflow, platform: 'bedrock' | 'java')
#### .from(authflow: Authflow, platform: 'bedrock' | 'java', options: Options)

Takes an **Authflow** instance from [prismarine-auth](https://github.com/PrismarineJS/prismarine-auth), you can see the documentation for this [here.](https://github.com/PrismarineJS/prismarine-auth#authflow)

Expand Down
7 changes: 6 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
- [writeToDirectory](#writeToDirectory)
- [getBuffer](#getBuffer)

## Options
Used for `RealmAPI.from()`
| Param | Type | Description |
| --------------- | -------------------- | --------------------------------------------------------------------- |
| usePreview | `Boolean` | If the Preview Realms API should be used (Only bedrock) |
---

## Constructor
Expand All @@ -70,7 +75,7 @@ const { RealmAPI } = require('prismarine-realms')

const authflow = new Authflow()

const api = RealmAPI.from(authflow, 'bedrock' | 'java')
const api = RealmAPI.from(authflow, 'bedrock' | 'java', options)
```
---

Expand Down
10 changes: 8 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
import { Authflow } from "prismarine-auth";

declare module 'prismarine-realms' {
export class Options {
skipAuth?: Boolean
maxRetries?: Number
usePreview?: Boolean // Bedrock only
}

export class RealmAPI {
/**
* Creates a new RealmAPI instance, which handles and authenticates calls to the Realms API
* @param authflow An Authflow instance from [prismarine-auth](https://github.com/PrismarineJS/prismarine-auth).
* @param platform Which platforms API to access
*/
constructor(authflow: Authflow, platform: 'bedrock' | 'java')
constructor(authflow: Authflow, platform: 'bedrock' | 'java', options?: Options)

static from(authflow: Authflow, platform: 'bedrock' | 'java'): BedrockRealmAPI | JavaRealmAPI
static from(authflow: Authflow, platform: 'bedrock' | 'java', options?: Options): BedrockRealmAPI | JavaRealmAPI

getRealms(): Promise<Realm[]>
getRealm(realmId: string): Promise<Realm>
Expand Down
7 changes: 7 additions & 0 deletions src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ module.exports = class Rest {
'User-Agent': this.userAgent
}

// Minecraft Bedrock has two types of realms: Regular and Preview
// Regular realms can be only be accessed by the normal MCBE client, and Preview realms can only be accessed by the Preview (Beta) MCBE Client
// These versions have completely different worlds attached
if (this.options.usePreview && this.platform === 'bedrock') {
headers['is-prerelease'] = true
}

if (!this.options.skipAuth) {
const [key, value] = await this.getAuth()
headers[key] = value
Expand Down

0 comments on commit a602ed3

Please sign in to comment.