@minecraft/server-admin 1.0.0-beta.00001b50 → 1.0.0-beta.1.12.111-stable

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # `@minecraft/server-admin`
2
-
3
- Contains types related to administering a Bedrock Dedicated Server. These types allow for the configuration of variables and secrets in JSON files in the Bedrock Dedicated Server folder. These types cannot be used on Minecraft clients.
4
-
5
- ## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
6
-
7
- See full documentation for this module here:
8
-
9
- https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/@minecraft/server-admin/@minecraft/server-admin
1
+ # `@minecraft/server-admin`
2
+
3
+ Contains types related to administering a Bedrock Dedicated Server. These types allow for the configuration of variables and secrets in JSON files in the Bedrock Dedicated Server folder. These types cannot be used on Minecraft clients or within Minecraft Realms.
4
+
5
+ ## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
6
+
7
+ See full documentation for this module here:
8
+
9
+ https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-admin/minecraft-server-admin
package/index.d.ts CHANGED
@@ -1,81 +1,290 @@
1
- // Type definitions for Minecraft Bedrock Edition script APIs
2
- // Project: https://docs.microsoft.com/minecraft/creator/
3
- // Definitions by: Jake Shirley <https://github.com/JakeShirley>
4
- // Mike Ammerlaan <https://github.com/mammerla>
5
-
6
- /* *****************************************************************************
7
- Copyright (c) Microsoft Corporation.
8
- ***************************************************************************** */
9
- /**
10
- * @packageDocumentation
11
- * Contains types related to administering a Bedrock Dedicated
12
- * Server. These types allow for the configuration of variables
13
- * and secrets in JSON files in the Bedrock Dedicated Server
14
- * folder. These types cannot be used on Minecraft clients.
15
- *
16
- * Manifest Details
17
- * ```json
18
- * {
19
- * "module_name": "@minecraft/server-admin",
20
- * "version": "1.0.0-beta.00001b50"
21
- * }
22
- * ```
23
- *
24
- */
25
- /**
26
- * This represents a placeholder object that represents a
27
- * secret string. The contents of that string are not available
28
- * to script; this object is just a placeholder.
29
- */
30
- // tslint:disable-next-line:no-unnecessary-class
31
- export class SecretString {
32
- constructor(value: string);
33
- }
34
- /**
35
- * A collection of server secrets defined in dedicated server
36
- * configuration.
37
- */
38
- export class ServerSecrets {
39
- /**
40
- * A list of available, configured server secrets.
41
- */
42
- readonly names: string[];
43
- /**
44
- * @remarks
45
- * Returns a SecretString that is a placeholder for a secret
46
- * configured in a JSON file. In certain objects, like an
47
- * HttpHeader, this Secret is resolved at the time of execution
48
- * but is not made available to the script environment.
49
- * @param name
50
- */
51
- get(name: string): SecretString;
52
- protected constructor();
53
- }
54
- /**
55
- * A collection of server variables defined in dedicated server
56
- * configuration.
57
- */
58
- export class ServerVariables {
59
- /**
60
- * A list of available, configured server variables.
61
- */
62
- readonly names: string[];
63
- /**
64
- * @remarks
65
- * Returns the value of variable that has been configured in a
66
- * dedicated server configuration JSON file.
67
- * @param name
68
- */
69
- get(name: string): any;
70
- protected constructor();
71
- }
72
- /**
73
- * A globally available object that returns a list of
74
- * dedicated-server configured secrets.
75
- */
76
- export const secrets: ServerSecrets;
77
- /**
78
- * A globally available object that returns a list of
79
- * dedicated-server configured variables.
80
- */
81
- export const variables: ServerVariables;
1
+ // Type definitions for Minecraft Bedrock Edition script APIs
2
+ // Project: https://docs.microsoft.com/minecraft/creator/
3
+ // Definitions by: Jake Shirley <https://github.com/JakeShirley>
4
+ // Mike Ammerlaan <https://github.com/mammerla>
5
+
6
+ /* *****************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+ ***************************************************************************** */
9
+ /**
10
+ * @beta
11
+ * @packageDocumentation
12
+ * Contains types related to administering a Bedrock Dedicated
13
+ * Server. These types allow for the configuration of variables
14
+ * and secrets in JSON files in the Bedrock Dedicated Server
15
+ * folder. These types cannot be used on Minecraft clients or
16
+ * within Minecraft Realms.
17
+ *
18
+ * Manifest Details
19
+ * ```json
20
+ * {
21
+ * "module_name": "@minecraft/server-admin",
22
+ * "version": "1.0.0-beta"
23
+ * }
24
+ * ```
25
+ *
26
+ */
27
+ import * as minecraftcommon from '@minecraft/common';
28
+ import * as minecraftserver from '@minecraft/server';
29
+ export class AdminBeforeEvents {
30
+ private constructor();
31
+ /**
32
+ * @remarks
33
+ * This event is fired before a player joins the world. Unlike
34
+ * other before events, this event is a before event that you
35
+ * can delay several ticks by not resolving the promise
36
+ * returned in the subscribe function. If the promise is
37
+ * rejected, the client is rejected.
38
+ *
39
+ */
40
+ readonly asyncPlayerJoin: AsyncPlayerJoinBeforeEventSignal;
41
+ }
42
+
43
+ /**
44
+ * The data available before a player joins the world.
45
+ */
46
+ export class AsyncPlayerJoinBeforeEvent {
47
+ private constructor();
48
+ /**
49
+ * @remarks
50
+ * The player's name
51
+ *
52
+ */
53
+ readonly name: string;
54
+ /**
55
+ * @remarks
56
+ * An identifier that can be used to identify a player across
57
+ * sessions.
58
+ *
59
+ */
60
+ readonly persistentId: string;
61
+ /**
62
+ * @remarks
63
+ * Call this to disconnect a player. They will be allowed to
64
+ * try to join again.
65
+ *
66
+ * @throws This function can throw errors.
67
+ *
68
+ * {@link DisconnectedError}
69
+ */
70
+ disconnect(reason?: string): void;
71
+ /**
72
+ * @remarks
73
+ * Will return true if the player is still waiting to join the
74
+ * world. If they disconnect then it will return false.
75
+ *
76
+ */
77
+ isValid(): boolean;
78
+ }
79
+
80
+ export class AsyncPlayerJoinBeforeEventSignal {
81
+ private constructor();
82
+ /**
83
+ * @remarks
84
+ * Add a callback that's ran before a player joins the world.
85
+ * This callback returns a promise and the player won't join
86
+ * until that promise is resolved. If the promise is not
87
+ * resolved within a reasonable time, the player joining will
88
+ * be rejected. If the player joining leaves/disconnects, then
89
+ * the event data's isValid will return false.
90
+ *
91
+ */
92
+ subscribe(
93
+ callback: (arg0: AsyncPlayerJoinBeforeEvent) => Promise<void>,
94
+ ): (arg0: AsyncPlayerJoinBeforeEvent) => Promise<void>;
95
+ unsubscribe(callback: (arg0: AsyncPlayerJoinBeforeEvent) => Promise<void>): boolean;
96
+ }
97
+
98
+ /**
99
+ * This represents a placeholder object that represents a
100
+ * secret string. The contents of that string are not available
101
+ * to script; this object is just a placeholder.
102
+ */
103
+ export class SecretString {
104
+ constructor(value: string);
105
+ }
106
+
107
+ /**
108
+ * A collection of server secrets defined in dedicated server
109
+ * configuration.
110
+ * @example getPlayerProfile.ts
111
+ * ```typescript
112
+ * import { variables, secrets } from "@minecraft/server-admin";
113
+ * import { http, HttpRequest, HttpRequestMethod, HttpHeader, HttpResponse } from "@minecraft/server-net";
114
+ *
115
+ * const serverUrl = variables.get('serverEndpoint');
116
+ *
117
+ * function getPlayerProfile(playerId: string): Promise<HttpResponse> {
118
+ * const req = new HttpRequest(serverUrl + 'getPlayerProfile');
119
+ *
120
+ * req.body = JSON.stringify({
121
+ * playerId,
122
+ * });
123
+ *
124
+ * const authTokenSec = secrets.get('authtoken');
125
+ *
126
+ * if (!authTokenSec) {
127
+ * throw new Error('authtoken secret not defined.');
128
+ * }
129
+ *
130
+ * req.method = HttpRequestMethod.Post;
131
+ * req.headers = [new HttpHeader('Content-Type', 'application/json'), new HttpHeader('auth', authTokenSec)];
132
+ *
133
+ * return http.request(req);
134
+ * }
135
+ * ```
136
+ */
137
+ export class ServerSecrets {
138
+ private constructor();
139
+ /**
140
+ * @remarks
141
+ * A list of available, configured server secrets.
142
+ *
143
+ */
144
+ readonly names: string[];
145
+ /**
146
+ * @remarks
147
+ * Returns a SecretString that is a placeholder for a secret
148
+ * configured in a JSON file. In certain objects, like an
149
+ * HttpHeader, this Secret is resolved at the time of execution
150
+ * but is not made available to the script environment.
151
+ *
152
+ * This function can't be called in read-only mode.
153
+ *
154
+ * This function can be called in early-execution mode.
155
+ *
156
+ */
157
+ get(name: string): SecretString | undefined;
158
+ }
159
+
160
+ /**
161
+ * A collection of server variables defined in dedicated server
162
+ * configuration.
163
+ * @example getPlayerProfile.ts
164
+ * ```typescript
165
+ * import { variables, secrets } from "@minecraft/server-admin";
166
+ * import { http, HttpRequest, HttpRequestMethod, HttpHeader, HttpResponse } from "@minecraft/server-net";
167
+ *
168
+ * const serverUrl = variables.get('serverEndpoint');
169
+ *
170
+ * function getPlayerProfile(playerId: string): Promise<HttpResponse> {
171
+ * const req = new HttpRequest(serverUrl + 'getPlayerProfile');
172
+ *
173
+ * req.body = JSON.stringify({
174
+ * playerId,
175
+ * });
176
+ *
177
+ * const authTokenSec = secrets.get('authtoken');
178
+ *
179
+ * if (!authTokenSec) {
180
+ * throw new Error('authtoken secret not defined.');
181
+ * }
182
+ *
183
+ * req.method = HttpRequestMethod.Post;
184
+ * req.headers = [new HttpHeader('Content-Type', 'application/json'), new HttpHeader('auth', authTokenSec)];
185
+ *
186
+ * return http.request(req);
187
+ * }
188
+ * ```
189
+ */
190
+ export class ServerVariables {
191
+ private constructor();
192
+ /**
193
+ * @remarks
194
+ * A list of available, configured server variables.
195
+ *
196
+ */
197
+ readonly names: string[];
198
+ /**
199
+ * @remarks
200
+ * Returns the value of variable that has been configured in a
201
+ * dedicated server configuration JSON file.
202
+ *
203
+ * This function can't be called in read-only mode.
204
+ *
205
+ * This function can be called in early-execution mode.
206
+ *
207
+ */
208
+ get(name: string): unknown | undefined;
209
+ }
210
+
211
+ /**
212
+ * Options when transferring a player to a server that supports
213
+ * direct host/port connections.
214
+ */
215
+ export interface TransferPlayerIpPortOptions {
216
+ /**
217
+ * @remarks
218
+ * Hostname of the destination server.
219
+ *
220
+ */
221
+ hostname: string;
222
+ /**
223
+ * @remarks
224
+ * Port of the destination server.
225
+ *
226
+ */
227
+ port: number;
228
+ }
229
+
230
+ /**
231
+ * Options when transferring a player to a server that supports
232
+ * NetherNet connections.
233
+ */
234
+ export interface TransferPlayerNetherNetOptions {
235
+ /**
236
+ * @remarks
237
+ * NetherNet ID of the destination server.
238
+ *
239
+ */
240
+ netherNetId: string;
241
+ }
242
+
243
+ /**
244
+ * An error that is thrown when trying to interact with a join
245
+ * event and the player is disconnected.
246
+ */
247
+ // @ts-ignore Class inheritance allowed for native defined classes
248
+ export class DisconnectedError extends Error {
249
+ private constructor();
250
+ /**
251
+ * @remarks
252
+ * The id of the player that was disconnected.
253
+ *
254
+ * This property can be read in early-execution mode.
255
+ *
256
+ */
257
+ id: string;
258
+ }
259
+
260
+ /**
261
+ * @remarks
262
+ * Transfer player to another server.
263
+ *
264
+ * This function can't be called in read-only mode.
265
+ *
266
+ * @param player
267
+ * Player to transfer.
268
+ * @param options
269
+ * Options for where to send the player.
270
+ * @throws This function can throw errors.
271
+ */
272
+ export function transferPlayer(
273
+ player: minecraftserver.Player,
274
+ options: TransferPlayerIpPortOptions | TransferPlayerNetherNetOptions,
275
+ ): void;
276
+ export const beforeEvents: AdminBeforeEvents;
277
+ /**
278
+ * @remarks
279
+ * A globally available object that returns a list of
280
+ * dedicated-server configured secrets.
281
+ *
282
+ */
283
+ export const secrets: ServerSecrets;
284
+ /**
285
+ * @remarks
286
+ * A globally available object that returns a list of
287
+ * dedicated-server configured variables.
288
+ *
289
+ */
290
+ export const variables: ServerVariables;
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
- {
2
- "name": "@minecraft/server-admin",
3
- "version": "1.0.0-beta.00001b50",
4
- "description": "",
5
- "contributors": [
6
- {
7
- "name": "Jake Shirley",
8
- "email": "jake@xbox.com"
9
- },
10
- {
11
- "name": "Mike Ammerlaan",
12
- "email": "mikeam@microsoft.com"
13
- }
14
- ],
15
- "license": "MIT"
1
+ {
2
+ "name": "@minecraft/server-admin",
3
+ "version": "1.0.0-beta.1.12.111-stable",
4
+ "description": "",
5
+ "contributors": [
6
+ {
7
+ "name": "Jake Shirley",
8
+ "email": "jake@xbox.com"
9
+ },
10
+ {
11
+ "name": "Mike Ammerlaan",
12
+ "email": "mikeam@microsoft.com"
13
+ }
14
+ ],
15
+ "peerDependencies": {
16
+ "@minecraft/common": "^1.0.0",
17
+ "@minecraft/server": "^1.17.0 || ^2.0.0"
18
+ },
19
+ "license": "MIT"
16
20
  }
package/.eslintrc.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2021": true
5
- },
6
- "extends": [
7
- "eslint:recommended",
8
- "plugin:@typescript-eslint/recommended"
9
- ],
10
- "overrides": [
11
- ],
12
- "parser": "@typescript-eslint/parser",
13
- "parserOptions": {
14
- "ecmaVersion": "latest",
15
- "sourceType": "module"
16
- },
17
- "plugins": [
18
- "@typescript-eslint"
19
- ],
20
- "rules": {
21
- "@typescript-eslint/no-explicit-any": "off"
22
- }
23
- }
package/tests.ts DELETED
@@ -1,3 +0,0 @@
1
- import * as serverAdmin from '@minecraft/server-admin';
2
-
3
- serverAdmin.secrets.get('authtoken');
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "lib": ["es6"],
5
- "target": "es6",
6
- "forceConsistentCasingInFileNames": true,
7
- "noEmit": true,
8
- "noImplicitAny": true,
9
- "noImplicitThis": true,
10
- "strictFunctionTypes": true,
11
- "strictNullChecks": true,
12
- "baseUrl": "../",
13
- "typeRoots": ["../"],
14
- "types": []
15
- },
16
- "files": [
17
- "index.d.ts",
18
- "tests.ts"
19
- ]
20
- }