@minecraft/server-admin 1.0.0-beta.1.21.20-preview.21 → 1.0.0-beta.1.21.3-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 +1 -1
- package/index.d.ts +6 -3
- package/package.json +1 -1
- package/tests.ts +142 -0
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.
|
|
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,14 +12,13 @@
|
|
|
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
|
|
16
|
-
* within Minecraft Realms.
|
|
15
|
+
* folder. These types cannot be used on Minecraft clients.
|
|
17
16
|
*
|
|
18
17
|
* Manifest Details
|
|
19
18
|
* ```json
|
|
20
19
|
* {
|
|
21
20
|
* "module_name": "@minecraft/server-admin",
|
|
22
|
-
* "version": "1.0.0-beta"
|
|
21
|
+
* "version": "1.0.0-beta.1.21.3-stable"
|
|
23
22
|
* }
|
|
24
23
|
* ```
|
|
25
24
|
*
|
|
@@ -62,6 +61,8 @@ export class SecretString {
|
|
|
62
61
|
*
|
|
63
62
|
* return http.request(req);
|
|
64
63
|
* }
|
|
64
|
+
*
|
|
65
|
+
* getPlayerProfile('dark navi');
|
|
65
66
|
* ```
|
|
66
67
|
*/
|
|
67
68
|
export class ServerSecrets {
|
|
@@ -113,6 +114,8 @@ export class ServerSecrets {
|
|
|
113
114
|
*
|
|
114
115
|
* return http.request(req);
|
|
115
116
|
* }
|
|
117
|
+
*
|
|
118
|
+
* getPlayerProfile('dark navi');
|
|
116
119
|
* ```
|
|
117
120
|
*/
|
|
118
121
|
export class ServerVariables {
|
package/package.json
CHANGED
package/tests.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
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
|
+
}
|