-
Notifications
You must be signed in to change notification settings - Fork 0
/
transferserver.ts
57 lines (52 loc) · 2.38 KB
/
transferserver.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
/// <reference types="minecraft-scripting-types-server" />
/*
* * * * * * * * * * *
* BDSX2 SCRIPT - transferserver.ts *
* by randmmouse/madeofstown *
* * * * * * * * * * * * * * * * * *
* USE/FUNCTION: *
* * Transfer players to other servers! *
* * Place inside ./scripts/ folder *
* * To use the /transferserver command in game: *
* * ADD "import './transferserver';" TO ./scripts/index.ts *
* * * * * * * * * * * * * * * * * *
* REQUIRED CUSTOM SCRIPTS: *
* * - playerlist.ts *
* * * * * * * * * *
*/
import { command, NetworkIdentifier } from "bdsx";
import { connectionList } from "./playerlist";
import { TransferPacket } from "bdsx/bds/packets";
//Hook and Process the Command '/transferserver <address> <port>'
command.hook.on((command, originName)=>{
if (command.startsWith('/transferserver')) {
var splitcmd = command.split(' ')
if (originName === 'Server') {
var originNetId = connectionList.nXNet.get(splitcmd[1]);
var address = splitcmd[2];
var port = parseInt(splitcmd[3], 10);
transferServer(originNetId, address, port);
} else if (originName === 'Script Engine') {
var originNetId = connectionList.nXNet.get(splitcmd[1]);
var address = splitcmd[2];
var port = parseInt(splitcmd[3], 10);
transferServer(originNetId, address, port);
} else {
var originNetId = connectionList.nXNet.get(originName);
var address = splitcmd[1]
var port = parseInt(splitcmd[2], 10);
transferServer(originNetId, address, port);
}
console.log(command, originName, address, port);
return 0;
}
});
// Transfer Server Function
export function transferServer(networkIdentifier:NetworkIdentifier, address:string, port:number):void {
if ( Number.isInteger(port) != true ) port = 19132;
let transferPacket = TransferPacket.create();
transferPacket.address = address;
transferPacket.port = port;
transferPacket.sendTo(networkIdentifier, 0);
transferPacket.dispose();
}