forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
48 lines (46 loc) · 1.43 KB
/
index.ts
File metadata and controls
48 lines (46 loc) · 1.43 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
38
39
40
41
42
43
44
45
46
47
48
// Script example for ScriptAPI
// Author: Jayly <https://github.com/JaylyDev>
// Project: https://github.com/JaylyDev/ScriptAPI
import * as mc from "@minecraft/server";
import { getGamemode } from "get-gamemode/index";
import { ActionFormData, MessageFormData, ModalFormData} from "@minecraft/server-ui";
type FormResult = <formType extends ModalFormData | MessageFormData | ActionFormData, formResponse extends Awaited<ReturnType<formType["show"]>>>(form: formType, callback: (response: formResponse) => void) => void;
interface PlayerExtra extends mc.Player {
/**
* Get player GameMode
*/
getGameMode(): string;
/**
* Kick the player from the server
*/
kick(reason: string): void;
/**
* Get player score from an objective
*/
getScore(objectiveId: string): number;
/**
* Show UI forms
*/
showForm: FormResult;
}
export default function Player(player: mc.Player): PlayerExtra {
return Object.assign(
{
getGameMode() {
return getGamemode(player);
},
kick(reason: string) {
player.runCommand(`kick "${player.name}" ${reason}`);
},
getScore(objectiveId: string) {
return mc.world.scoreboard
.getObjective(objectiveId)
.getScore(player.scoreboardIdentity);
},
showForm(form: ModalFormData | MessageFormData | ActionFormData, callback: (response: any) => void) {
form.show(player).then(callback);
},
},
player
);
}