-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
154 lines (142 loc) · 3.39 KB
/
main.js
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
const mc = require('minecraft-protocol')
const config = require('./config.js')
const Display = require('./display.js')
const display = config.commandInterface ? new Display() : { log: console.log }
display.log(`Initializing server...`)
const server = mc.createServer({
'online-mode': false,
encryption: true,
host: config.host,
port: config.port,
version: config.version
})
if (config.commandInterface) {
display.userInputCallback = function commandHandler (command) {
switch (command) {
case 'list':
let clients = Object.values(server.clients)
.map(element => element.username)
const clientsLength = clients.length
if (clientsLength === 0) clients = 'None'
else clients = clients.join(', ')
display.log(`Clients connected (${clientsLength}): ${clients}`)
break
case 'end':
case 'stop':
case 'close':
display.log('Stopping the server')
process.exit(0)
default:
display.log(`Unknown command ${command}`)
break
}
}
}
display.log(`Server listening on ${config.host}:${config.port}!`)
server.on('error', (err) => display.log(`Error: ${err}`))
const the_end = {
piglin_safe: {
type: 'byte',
value: 0
},
natural: {
type: 'byte',
value: 0
},
ambient_light: {
type: 'float',
value: 0
},
infiniburn: {
type: 'string',
value: 'minecraft:infiniburn_end'
},
respawn_anchor_works: {
type: 'byte',
value: 0
},
has_skylight: {
type: 'byte',
value: 0
},
bed_works: {
type: 'byte',
value: 0
},
has_raids: {
type: 'byte',
value: 1
},
name: {
type: 'string',
value: 'minecraft:the_end'
},
logical_height: {
type: 'int',
value: 256
},
shrunk: {
type: 'byte',
value: 0
},
ultrawarm: {
type: 'byte',
value: 0
},
has_ceiling: {
type: 'byte',
value: 0
},
fixed_time: {
type: 'int',
value: 6000
}
}
server.on('login', client => {
display.log(`${client.username} joined the server!`)
client.registerChannel('minecraft:brand', ['string', []])
client.write('login', {
entityId: client.id,
levelType: 'flat',
gameMode: 3,
previousGameMode: 255,
worldNames: ['minecraft:the_end'],
dimensionCodec: {name: '', type:'compound', value: {dimension: {type: 'list', value: {type: 'compound', value: [the_end]}}}},
dimension: 'minecraft:the_end',
worldName: 'minecraft:the_end',
difficulty: 2,
hashedSeed: [0, 0],
maxPlayers: server.maxPlayers,
reducedDebugInfo: true,
enableRespawnScreen: true
})
client.writeChannel('minecraft:brand', 'PabloPerezRodriguez/minecraft-limbo-lobby')
client.write('position', {
x: 0,
y: 0,
z: 0,
yaw: 0,
pitch: 0,
flags: 0x00
})
if (config.join_messages) {
for (const message of config.join_messages) {
client.write('chat', {
message: JSON.stringify(message),
position: message.position,
sender: '0'
})
}
}
if (config.boss_bar) {
client.write('boss_bar', {
entityUUID: 0,
action: 0,
title: JSON.stringify(config.boss_bar.title),
health: config.boss_bar.health == null ? 1 : config.boss_bar.health,
color: config.boss_bar.color == null ? 2 : config.boss_bar.color,
division: config.boss_bar.division == null ? 0 : config.boss_bar.division,
flags: 0x00
})
}
})