@minecraft/server-admin 1.0.0-beta.1.21.10-preview.23 → 1.0.0-beta.1.21.100-preview.20
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 +1 -1
- package/index.d.ts +144 -7
- package/package.json +3 -2
- package/.eslintrc.json +0 -23
- package/tests.ts +0 -142
- package/tsconfig.json +0 -20
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@minecraft/server-admin`
|
|
2
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.
|
|
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
4
|
|
|
5
5
|
## **NOTE: This version of this module is still in pre-release. It may change or it may be removed in future releases.**
|
|
6
6
|
|
package/index.d.ts
CHANGED
|
@@ -12,18 +12,89 @@
|
|
|
12
12
|
* Contains types related to administering a Bedrock Dedicated
|
|
13
13
|
* Server. These types allow for the configuration of variables
|
|
14
14
|
* and secrets in JSON files in the Bedrock Dedicated Server
|
|
15
|
-
* folder. These types cannot be used on Minecraft clients
|
|
15
|
+
* folder. These types cannot be used on Minecraft clients or
|
|
16
|
+
* within Minecraft Realms.
|
|
16
17
|
*
|
|
17
18
|
* Manifest Details
|
|
18
19
|
* ```json
|
|
19
20
|
* {
|
|
20
21
|
* "module_name": "@minecraft/server-admin",
|
|
21
|
-
* "version": "1.0.0-beta
|
|
22
|
+
* "version": "1.0.0-beta"
|
|
22
23
|
* }
|
|
23
24
|
* ```
|
|
24
25
|
*
|
|
25
26
|
*/
|
|
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
|
+
|
|
27
98
|
/**
|
|
28
99
|
* This represents a placeholder object that represents a
|
|
29
100
|
* secret string. The contents of that string are not available
|
|
@@ -61,8 +132,6 @@ export class SecretString {
|
|
|
61
132
|
*
|
|
62
133
|
* return http.request(req);
|
|
63
134
|
* }
|
|
64
|
-
*
|
|
65
|
-
* getPlayerProfile('dark navi');
|
|
66
135
|
* ```
|
|
67
136
|
*/
|
|
68
137
|
export class ServerSecrets {
|
|
@@ -82,6 +151,8 @@ export class ServerSecrets {
|
|
|
82
151
|
*
|
|
83
152
|
* This function can't be called in read-only mode.
|
|
84
153
|
*
|
|
154
|
+
* This function can be called in early-execution mode.
|
|
155
|
+
*
|
|
85
156
|
*/
|
|
86
157
|
get(name: string): SecretString | undefined;
|
|
87
158
|
}
|
|
@@ -114,8 +185,6 @@ export class ServerSecrets {
|
|
|
114
185
|
*
|
|
115
186
|
* return http.request(req);
|
|
116
187
|
* }
|
|
117
|
-
*
|
|
118
|
-
* getPlayerProfile('dark navi');
|
|
119
188
|
* ```
|
|
120
189
|
*/
|
|
121
190
|
export class ServerVariables {
|
|
@@ -133,10 +202,78 @@ export class ServerVariables {
|
|
|
133
202
|
*
|
|
134
203
|
* This function can't be called in read-only mode.
|
|
135
204
|
*
|
|
205
|
+
* This function can be called in early-execution mode.
|
|
206
|
+
*
|
|
136
207
|
*/
|
|
137
|
-
get(name: string):
|
|
208
|
+
get(name: string): unknown | undefined;
|
|
138
209
|
}
|
|
139
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;
|
|
140
277
|
/**
|
|
141
278
|
* @remarks
|
|
142
279
|
* A globally available object that returns a list of
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minecraft/server-admin",
|
|
3
|
-
"version": "1.0.0-beta.1.21.
|
|
3
|
+
"version": "1.0.0-beta.1.21.100-preview.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
}
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@minecraft/common": "^1.0.0"
|
|
16
|
+
"@minecraft/common": "^1.0.0",
|
|
17
|
+
"@minecraft/server": "^1.17.0 || ^2.0.0-rc.1.21.100-preview.20"
|
|
17
18
|
},
|
|
18
19
|
"license": "MIT"
|
|
19
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,142 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import * as mc from '@minecraft/server';
|
|
3
|
-
|
|
4
|
-
export async function getPlayerProfile(log: (message: string, status?: number) => void, targetLocation: mc.Vector3) {
|
|
5
|
-
const serverUrl = mcsa.variables.get('serverEndpoint');
|
|
6
|
-
|
|
7
|
-
const req = new mcnet.HttpRequest(serverUrl + 'getPlayerProfile');
|
|
8
|
-
|
|
9
|
-
req.body = JSON.stringify({
|
|
10
|
-
playerId: 'johndoe',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
req.method = mcnet.HttpRequestMethod.POST;
|
|
14
|
-
req.headers = [
|
|
15
|
-
new mcnet.HttpHeader('Content-Type', 'application/json'),
|
|
16
|
-
new mcnet.HttpHeader('auth', mcsa.secrets.get('authtoken')),
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
await mcnet.http.request(req);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default class SampleManager {
|
|
23
|
-
tickCount = 0;
|
|
24
|
-
|
|
25
|
-
_availableFuncs: {
|
|
26
|
-
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
pendingFuncs: Array<{
|
|
30
|
-
name: string;
|
|
31
|
-
func: (log: (message: string, status?: number) => void, location: mc.Vector3) => void;
|
|
32
|
-
location: mc.Vector3;
|
|
33
|
-
}> = [];
|
|
34
|
-
|
|
35
|
-
gameplayLogger(message: string, status?: number) {
|
|
36
|
-
if (status !== undefined && status > 0) {
|
|
37
|
-
message = 'SUCCESS: ' + message;
|
|
38
|
-
} else if (status !== undefined && status < 0) {
|
|
39
|
-
message = 'FAIL: ' + message;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.say(message);
|
|
43
|
-
}
|
|
44
|
-
say(message: string) {
|
|
45
|
-
mc.world.getDimension('overworld').runCommand('say ' + message);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
newChatMessage(chatEvent: mc.ChatEvent) {
|
|
49
|
-
const message = chatEvent.message.toLowerCase();
|
|
50
|
-
|
|
51
|
-
if (message.startsWith('howto') && chatEvent.sender) {
|
|
52
|
-
const nearbyBlock = chatEvent.sender.getBlockFromViewVector();
|
|
53
|
-
if (!nearbyBlock) {
|
|
54
|
-
this.gameplayLogger('Please look at the block where you want me to run this.');
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const nearbyBlockLoc = nearbyBlock.location;
|
|
59
|
-
const nearbyLoc: mc.Vector3 = { x: nearbyBlockLoc.x, y: nearbyBlockLoc.y + 1, z: nearbyBlockLoc.z };
|
|
60
|
-
|
|
61
|
-
const sampleId = message.substring(5).trim();
|
|
62
|
-
|
|
63
|
-
if (sampleId.length < 2) {
|
|
64
|
-
let availableFuncStr = 'Here is my list of available samples:';
|
|
65
|
-
|
|
66
|
-
for (const sampleFuncKey in this._availableFuncs) {
|
|
67
|
-
availableFuncStr += ' ' + sampleFuncKey;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
this.say(availableFuncStr);
|
|
71
|
-
} else {
|
|
72
|
-
for (const sampleFuncKey in this._availableFuncs) {
|
|
73
|
-
if (sampleFuncKey.toLowerCase() === sampleId) {
|
|
74
|
-
const sampleFunc = this._availableFuncs[sampleFuncKey];
|
|
75
|
-
|
|
76
|
-
this.runSample(sampleFuncKey + this.tickCount, sampleFunc, nearbyLoc);
|
|
77
|
-
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
this.say(`I couldn't find the sample '${sampleId}"'`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
runSample(
|
|
88
|
-
sampleId: string,
|
|
89
|
-
snippetFunctions: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>,
|
|
90
|
-
targetLocation: mc.Vector3,
|
|
91
|
-
) {
|
|
92
|
-
for (let i = snippetFunctions.length - 1; i >= 0; i--) {
|
|
93
|
-
this.pendingFuncs.push({ name: sampleId, func: snippetFunctions[i], location: targetLocation });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
worldTick() {
|
|
98
|
-
if (this.tickCount % 10 === 0) {
|
|
99
|
-
if (this.pendingFuncs.length > 0) {
|
|
100
|
-
const funcSet = this.pendingFuncs.pop();
|
|
101
|
-
|
|
102
|
-
if (funcSet) {
|
|
103
|
-
funcSet.func(this.gameplayLogger, funcSet.location);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
this.tickCount++;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
constructor() {
|
|
112
|
-
this._availableFuncs = {};
|
|
113
|
-
|
|
114
|
-
this.gameplayLogger = this.gameplayLogger.bind(this);
|
|
115
|
-
|
|
116
|
-
mc.world.events.tick.subscribe(this.worldTick.bind(this));
|
|
117
|
-
mc.world.events.chat.subscribe(this.newChatMessage.bind(this));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
registerSamples(sampleSet: {
|
|
121
|
-
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>;
|
|
122
|
-
}) {
|
|
123
|
-
for (const sampleKey in sampleSet) {
|
|
124
|
-
if (sampleKey.length > 1 && sampleSet[sampleKey]) {
|
|
125
|
-
this._availableFuncs[sampleKey] = sampleSet[sampleKey];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
import * as mcsa from '@minecraft/server-admin';
|
|
132
|
-
import * as mcnet from '@minecraft/server-net'; // keep in for net samples
|
|
133
|
-
|
|
134
|
-
const mojangServerAdminTestFuncs: {
|
|
135
|
-
[name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>;
|
|
136
|
-
} = {
|
|
137
|
-
getPlayerProfile: [getPlayerProfile],
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export function register(sampleManager: SampleManager) {
|
|
141
|
-
sampleManager.registerSamples(mojangServerAdminTestFuncs);
|
|
142
|
-
}
|
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
|
-
}
|