Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a slue of new functions to interact with the realms API #40

Merged
merged 12 commits into from
Jan 12, 2024
22 changes: 22 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ declare module 'prismarine-realms' {
getRealmWorldDownload(realmId: string, slotId: string, backupId?: string | 'latest'): Promise<Download>
restoreRealmFromBackup(realmId: string, slotId: string, backupId: string): Promise<void>
changeRealmState(realmId: string, state: 'open' | 'close'): Promise<void>
getRealmSubscriptionInfo(realmId: string): Promise<void>
getRealmSubscriptionInfoDetailed(realmId: string): Promise<void>
changeRealmActiveSlot(realmId: string, slotId: number): Promise<void>
changeRealmNameAndDescription(realmId: string, name: string, description: string): Promise<void>
deleteRealm(realmId: string): Promise<void>

}

Expand All @@ -32,6 +37,18 @@ declare module 'prismarine-realms' {
acceptRealmInvitation(invitationId: string): Promise<void>
rejectRealmInvitation(invitationId: string): Promise<void>
acceptRealmInviteFromCode(realmInviteCode: string): Promise<void>
resetRealm(realmId: string): Promise<void>
changeRealmConfiguration(realmId: string, configuration: any): Promise<void>
removeRealmInvite(realmId: string, uuid: string): Promise<Realm>
opRealmPlayer(realmId: string, uuid: string): Promise<void>
deopRealmPlayer(realmId: string, uuid: string): Promise<void>
removeAllRealmPlayers(realmId: string): Promise<Realm>
banPlayerFromRealm(realmId: string, uuid: string): Promise<void>
unbanPlayerFromRealm(realmId: string, uuid: string): Promise<void>
removeRealmFromJoinedList(realmId: string): Promise<void>
changeForcedTexturePack(realmId: string, forced: boolean): Promise<Realm>
changeRealmDefaultPermission(realmId: string, permission: string): Promise<Realm>
changeRealmPlayerPermission(realmId: string, permission: string, uuid: string): Promise<void>
}

export class JavaRealmAPI extends RealmAPI {
Expand All @@ -43,8 +60,13 @@ declare module 'prismarine-realms' {
invitePlayer(uuid: string, name: string): Promise<Realm>
open(): Promise<void>
close(): Promise<void>
delete(): Promise<void>
getBackups(): Promise<Backup[]>
getWorldDownload(): Promise<Download>
getSubscriptionInfo(): Promise<void>
getSubscriptionInfoDetailed(): Promise<void>
changeActiveSlot(): Promise<void>
changeNameAndDescription(): Promise<void>
id: number
remoteSubscriptionId: string
owner: string | null
Expand Down
114 changes: 114 additions & 0 deletions src/bedrock/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,122 @@ module.exports = class BedrockRealmAPI extends RealmAPI {
return await this.rest.put(`/worlds/${realmId}/${state}`)
}

async deleteRealm (realmId) {
return await this.rest.delete(`/worlds/${realmId}`)
}

async getRealmWorldDownload (realmId, slotId, backupId = 'latest') {
const data = await this.rest.get(`/archive/download/world/${realmId}/${slotId}/${backupId}`) // if backupId = latest will get the world as it is now not the most recent backup
return new Download(this, data)
}

async getRealmSubscriptionInfo (realmId) {
return await this.rest.get(`/subscriptions/${realmId}`)
}

async getRealmSubscriptionInfoDetailed (realmId) {
return await this.rest.get(`/subscriptions/${realmId}/details`)
}

async changeRealmActiveSlot (realmId, slotId) {
return await this.rest.put(`/worlds/${realmId}/slot/${slotId}`)
}

async changeRealmNameAndDescription (realmId, name, description) {
return await this.rest.put(`/worlds/${realmId}`, {
body: {
name,
description
}
})
}

async resetRealm (realmId) {
return await this.rest.put(`/worlds/${realmId}/reset`)
}

// Reference https://github.com/PrismarineJS/prismarine-realms/issues/34 for configuration structure
async changeRealmConfiguration (realmId, configuration) {
return await this.rest.put(`/worlds/${realmId}/configuration`, {
body: configuration
})
}

async removeRealmInvite (realmId, uuid) {
IanTapply22 marked this conversation as resolved.
Show resolved Hide resolved
const data = await this.rest.put(`/invites/${realmId}/invite/update`, {
body: {
invites: {
[uuid]: 'REMOVE'
}
}
})
return new Realm(this, data)
}

async opRealmPlayer (realmId, uuid) {
return await this.rest.put(`/invites/${realmId}/invite/update`, {
body: {
invites: {
[uuid]: 'OP'
}
}
})
}

async deopRealmPlayer (realmId, uuid) {
return await this.rest.put(`/invites/${realmId}/invite/update`, {
body: {
invites: {
[uuid]: 'DEOP'
}
}
})
}

async removeAllRealmPlayers (realmId) {
const data = await this.rest.put(`/invites/${realmId}/invite/update`, {
body: {
invites: null
}
})
return new Realm(this, data)
IanTapply22 marked this conversation as resolved.
Show resolved Hide resolved
}

async banPlayerFromRealm (realmId, uuid) {
return await this.rest.post(`/worlds/${realmId}/blocklist/${uuid}`)
}

async unbanPlayerFromRealm (realmId, uuid) {
return await this.rest.delete(`/worlds/${realmId}/blocklist/${uuid}`)
}

async removeRealmFromJoinedList (realmId) {
return await this.rest.delete(`/invites/${realmId}`)
}

async changeForcedTexturePack (realmId, forced) {
IanTapply22 marked this conversation as resolved.
Show resolved Hide resolved
if (forced) {
return await this.rest.put(`/worlds/${realmId}/content/texturePacksRequired`)
} else {
return await this.rest.delete(`/worlds/${realmId}/content/texturePacksRequired`)
}
}

async changeRealmDefaultPermission (realmId, permission) {
const data = await this.rest.put(`/world/${realmId}/defaultPermission`, {
body: {
permission: permission.toUpperCase()
}
})
return new Realm(this, data)
}

async changeRealmPlayersPermission (realmId, permission, uuid) {
return await this.rest.put(`/world/${realmId}/userPermission`, {
body: {
permission: permission.toUpperCase(),
uuid
IanTapply22 marked this conversation as resolved.
Show resolved Hide resolved
}
})
}
}
25 changes: 25 additions & 0 deletions src/java/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,33 @@ module.exports = class JavaRealmAPI extends RealmAPI {
return await this.rest.put(`/worlds/${realmId}/${state}`)
}

async deleteRealm (realmId) {
return await this.rest.delete(`/worlds/${realmId}`)
}

async getRealmWorldDownload (realmId, slotId) {
const data = await this.rest.get(`/worlds/${realmId}/slot/${slotId}/download`)
return new Download(this, data)
}

async getRealmSubscriptionInfo (realmId) {
IanTapply22 marked this conversation as resolved.
Show resolved Hide resolved
return await this.rest.get(`/subscriptions/${realmId}`)
}

async getRealmSubscriptionInfoDetailed (realmId) {
return await this.rest.get(`/subscriptions/${realmId}/details`)
}

async changeRealmActiveSlot (realmId, slotId) {
return await this.rest.put(`/worlds/${realmId}/slot/${slotId}`)
}

async changeRealmNameAndDescription (realmId, name, description) {
return await this.rest.put(`/worlds/${realmId}`, {
body: {
name,
description
}
})
}
}
20 changes: 20 additions & 0 deletions src/structures/Realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,31 @@ module.exports = class Realm {
return this.#api.changeRealmState(this.id, 'close')
}

async delete () {
return this.#api.deleteRealm(this.id)
}

async getWorldDownload () {
return this.#api.getRealmWorldDownload(this.id, this.activeSlot, 'latest')
}

async getBackups () {
return this.#api.getRealmBackups(this.id, this.activeSlot)
}

async getSubscriptionInfo () {
return this.#api.getRealmSubscriptionInfo(this.id)
}

async getSubscriptionInfoDetailed () {
return this.#api.getRealmSubscriptionInfoDetailed(this.id)
}

async changeActiveSlot () {
return this.#api.changeRealmActiveSlot(this.id, this.activeSlot)
}

async changeNameAndDescription () {
return this.#api.changeRealmNameAndDescription(this.id, this.name, this.motd)
IanTapply22 marked this conversation as resolved.
Show resolved Hide resolved
}
}