forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.js
More file actions
37 lines (37 loc) · 1.12 KB
/
tests.js
File metadata and controls
37 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { world } from "@minecraft/server";
import { RequestMethod, REST } from "./index";
const rest = new REST('demo'); // id is demo, lower case
(async () => {
await rest.request('/players', { method: RequestMethod.POST }); // create a route
// save data for all players into a table
for (const player of world.getAllPlayers()) {
await rest.request('/players', {
method: RequestMethod.PUT,
key: player.name,
value: player.id
});
}
;
})().catch(console.error);
world.afterEvents.chatSend.subscribe((event) => {
/**
* Get player id from REST
*/
const playerId = rest.request('/players', {
method: RequestMethod.GET,
key: event.sender.name
});
if (playerId !== event.sender.id)
event.sender.kill();
rest.request('/players', {
method: RequestMethod.PATCH,
key: event.sender.name,
value: event.sender.id
});
event.sender.sendMessage('Player ID: ' + playerId);
// remove property
rest.request('/players', {
method: RequestMethod.DELETE,
key: event.sender.name
});
});