This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
ez.d.ts
386 lines (340 loc) · 10.6 KB
/
ez.d.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
declare interface Long {
"64bit_low": number,
"64bit_high": number,
}
declare interface VanillaEntity {
__type__: "entity";
id: number;
__unique_id__: Long;
__identifier__: string;
}
declare interface Entity {
readonly entityName: string;
nameTag: string;
pos: ScriptPosition;
readonly valid: boolean;
readonly vanilla: VanillaEntity;
kill(): void;
}
declare interface PlayerEntry {
readonly xuid: string;
readonly uuid: string;
readonly name: string;
/** IP and port info */
readonly address: string;
/** Detect if player is still exists in server */
readonly alive: boolean;
/** A object shared between all instances */
readonly aux: object;
/** Get vanilla entity object */
readonly vanilla: VanillaEntity;
readonly entity: Entity;
/** Get offline player entry */
getOffline(): OfflinePlayerEntry;
toString(): string;
}
declare interface OfflinePlayerEntry {
readonly xuid: string;
readonly uuid: string;
readonly name: string;
/** Get online player entry if the player is online, or you will get null */
getOnline(): PlayerEntry | null;
toString(): string;
}
declare module "ez:entity" {
export function fromVanilla(vanilla: VanillaEntity): PlayerEntry | null;
}
declare module "ez:player" {
export function getPlayerByXUID(xuid: string): PlayerEntry | null;
export function getPlayerByUUID(uuid: string): PlayerEntry | null;
export function getPlayerByNAME(name: string): PlayerEntry | null;
export function getPlayerFromVanilla(vanilla: VanillaEntity): PlayerEntry | null;
export function getOfflinePlayerByXUID(xuid: string): OfflinePlayerEntry | null;
export function getOfflinePlayerByUUID(uuid: string): OfflinePlayerEntry | null;
export function getOfflinePlayerByNAME(name: string): OfflinePlayerEntry | null;
export function getPlayerList(): PlayerEntry[];
/**
* Called when player joined
* @param cb Callback
*/
export function onPlayerJoined(cb: (entry: PlayerEntry) => void): void;
/**
* Called when player initialized
* @param cb Callback
*/
export function onPlayerInitialized(cb: (entry: PlayerEntry) => void): void;
/**
* Called before player left
* @param cb Callback
*/
export function onPlayerLeft(cb: (entry: PlayerEntry) => void): void;
}
declare module "ez:basic-anti-cheat" {
export function onDetected(
cb: (entry: { name: string; target: PlayerEntry }) => void
): void;
}
declare module "ez:blacklist" {
export function addByXUID(xuid: string, reason: string, op: string): void;
export function addByUUID(uuid: string, reason: string, op: string): void;
export function addByNAME(name: string, reason: string, op: string): void;
export function removeByXUID(xuid: string): void;
export function removeByUUID(uuid: string): void;
export function removeByNAME(name: string): void;
}
declare module "ez:chat" {
export function onChat(cb: (sender: string, content: string) => void): void;
export function sendBroadcast(sender: string, content: string): void;
export function sendAnnounce(content: string): void;
export function send(target: PlayerEntry, content: string): void;
}
declare interface ScriptPosition {
x: number;
y: number;
z: number;
}
declare interface CommandOrigin {
type: number;
entity: Entity;
player?: PlayerEntry;
name: string;
dimension: number;
permission: number;
worldBuilder: number;
blockpos: ScriptPosition;
worldpos: ScriptPosition;
}
type CommandParameterTypeName =
| "bool"
| "int"
| "float"
| "string"
| "json"
| "enum"
| "players"
| "entities";
type CommandParameterTypeMap<Name extends CommandParameterTypeName> =
Name extends "bool" ? boolean :
Name extends "int" ? number :
Name extends "float" ? number :
Name extends "string" ? string :
Name extends "json" ? Record<string, any> :
Name extends "enum" ? number :
Name extends "entities" ? Entity[] :
Name extends "players" ? PlayerEntry[] :
never;
declare interface CommandParameterDefinition {
name: string;
type: CommandParameterTypeName;
optional: boolean;
enum?: string;
}
type CommandParameterMap<Defs extends CommandParameterDefinition[]> = {
[key in keyof Defs]: Defs[key] extends CommandParameterDefinition
? CommandParameterTypeMap<Defs[key]["type"]>
: never;
};
type CommandHandlerResult = string | string[] | undefined;
declare module "ez:command" {
/**
* Execute server command
* @param data command
*/
export function executeCommand(
data: string
): { statusMessage: string;[key: string]: any };
/**
* Set command handler for special `/!` command
* @param handler handler function
*/
export function setSlashCommandHandler(handler: (this: CommandOrigin, input: string) => string): void;
/**
* Register custom command
* @param name command name
* @param desc command description
* @param permission permission level 0 = everyone 1 = op/commandblock 2 = op 4 = console
*/
export function registerCommand(name: string, desc: string, permission: 0 | 1 | 2 | 3 | 4 | 5 | 6): void;
/**
* Register custom alias for command (max aliases per command: 1)
* @param name original command name
* @param altname new command name
*/
export function registerAlias(name: string, altname: string): void
/**
* Register custom command handler
* @param name command name
* @param defs command parameter definitions
* @param handler command handler
*/
export function registerOverride<Defs extends CommandParameterDefinition[]>(
name: string,
defs: Defs,
handler: (this: CommandOrigin, ...args: CommandParameterMap<Defs>) => CommandHandlerResult
): void;
/**
* Add command enum
* @param name enum name
* @param value enum values
*/
export function addEnum(name: string, value: string[]): void
}
declare interface ItemStack {
readonly raw_name: string;
readonly name: string;
readonly hover_name: string;
readonly custom_hover_name: boolean;
readonly id: number;
readonly aux: number;
readonly count: number;
readonly max_count: number;
readonly enchanted: boolean;
readonly enchants: EnchantmentInstance[];
dump(): ArrayBuffer;
equals(stack: ItemStack): boolean;
toString(): string;
}
declare interface EnchantmentInstance {
type: number;
level: number;
name(): string;
toString(): string;
}
declare module "ez:inventory" {
export function getOffHandItem(player: PlayerEntry): ItemStack;
export function getEquipmentItems(
player: PlayerEntry
): [ItemStack, ItemStack, ItemStack, ItemStack];
// prettier-ignore
export function getInventoryItems(
player: PlayerEntry
): [
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
];
// prettier-ignore
export function getEnderChestItems(
player: PlayerEntry
): [
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack, ItemStack,
];
}
declare module "ez:utils" {
export function delay(time: number): Promise<void>;
}
declare interface BossBar {
/**
* Detect if the bossbar still valid
* It will be invalid after player left or having been destoryed
*/
valid(): boolean;
updateText(text: string): void;
updatePercent(percent: number): void;
show(): void;
hide(): void;
destory(): void;
}
declare module "ez:bossbar" {
export function create(
player: PlayerEntry,
text: string,
percent: number
): BossBar;
}
declare type Sqlite3BindType =
| number
| null
| undefined
| string
| ArrayBuffer
| ArrayBufferView;
declare type Sqlite3ColumnType = number | null | string | ArrayBuffer;
declare interface Sqlite3Statement {
reset(): void;
clearBindings(): void;
bind(index: number | string, value: Sqlite3BindType): void;
bindAll(obj: Array<Sqlite3BindType>): void;
bindAll(obj: Record<string, Sqlite3BindType>): void;
exec(): void;
execWith(obj: Array<Sqlite3BindType>): void;
execWith(obj: Record<string, Sqlite3BindType>): void;
forEach(fn: (...columns: Array<Sqlite3ColumnType>) => boolean | void): void;
forEachWith(
obj: Array<Sqlite3BindType>,
fn: (...columns: Array<Sqlite3ColumnType>) => boolean | void
): void;
forEachWith(
obj: Record<string, Sqlite3BindType>,
fn: (...columns: Array<Sqlite3ColumnType>) => boolean | void
): void;
}
declare interface Sqlite3Database {
exec(sql: string): void;
prepare(sql: string): Sqlite3Statement;
}
declare module "ez:sqlite3" {
export function open(filename: string): Sqlite3Database;
}
declare interface FakeScoreboard {
init(target: PlayerEntry, name: string, is_asc: boolean): void;
deinit(target: PlayerEntry): void;
set(target: PlayerEntry, id: number, name: string, score: number): void;
remove(target: PlayerEntry, id: number): void;
}
declare module "ez:scoreboard" {
export const sidebar: FakeScoreboard;
export const list: FakeScoreboard;
}
declare module "ez:economy" {
export function getBalance(player: PlayerEntry): number;
export function updateBalance(
player: PlayerEntry,
value: number,
reason: string
): void;
}
declare module "ez:network-stats" {
export function getNetworkStats(
player: PlayerEntry
): {
ping: number;
avgping: number;
packetloss: number;
avgpacketloss: number;
};
}
declare module "ez:formui" {
/**
* Send form to player
* @param player target player
* @param request form content
* @param resp callback
*/
export function send(player: PlayerEntry, request: object, resp: (fn: object) => void): void;
}
/// Encode text in utf-8
declare interface TextEncoder {
new();
encode(text: string): Uint8Array
}
/// Decode text in utf-8
declare interface TextDecoder {
new();
decode(text: string): Uint8Array
}
declare interface HttpResponse {
status: number;
statusText: string;
headers: Record<string, string>;
data: ArrayBuffer;
}
declare function HttpRequest(
method: "GET" | "POST" | "HEAD" | "PUT" | "PATCH" | "DELETE",
url: string,
init: { headers: Record<string, string>, body: ArrayBuffer }
): Promise<HttpResponse>;