-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
41 lines (37 loc) · 1.29 KB
/
utils.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
import { EnchantUtils, EnchantmentNames } from "bdsx/bds/enchants";
import { ItemStack } from "bdsx/bds/inventory";
import { command } from "bdsx/command";
import { CxxString, int32_t } from "bdsx/nativetype";
type ItemDesc = {
item: string,
amount?: number,
data?: number,
name?: string,
lore?: string[],
enchantment?: {
enchant: EnchantmentNames,
level: number,
isUnsafe: boolean
}
}
export function createCItemStack(item: ItemDesc) {
const i = ItemStack.constructWith(item.item, item.amount, item.data);
if (item.name !== undefined) i.setCustomName(item.name);
if (item.lore !== undefined) i.setCustomLore(item.lore);
if (item.enchantment !== undefined) {
if (item.enchantment.level > 32767) item.enchantment.level = 32767;
if (item.enchantment.level < -32767) item.enchantment.level = -32767;
EnchantUtils.applyEnchant(i, item.enchantment.enchant, item.enchantment.level, item.enchantment.isUnsafe);
}
return i;
}
command.register("transferserver", "Transfer servers").overload(
(params, origin, output) => {
const actor = origin.getEntity();
if (actor?.isPlayer()) actor.transferServer(params.address, params.port);
},
{
address: CxxString,
port: int32_t,
},
);