mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-05-18 20:33:28 +02:00
Show player list when connected to a server
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
module.exports = function(socket) {
|
||||
|
||||
var interval;
|
||||
|
||||
// send the player list as soon as the bot spawns
|
||||
socket.mcbot.on('spawn', function() {
|
||||
socket.emit('bot:players', socket.mcbot.players);
|
||||
|
||||
// update the client with the player list every 5 seconds
|
||||
interval = setInterval(function() {
|
||||
if (socket.mcbot && socket.mcbot.entity) {
|
||||
socket.emit('bot:players', socket.mcbot.players);
|
||||
} else {
|
||||
console.error('leaked interval!');
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
});
|
||||
|
||||
socket.mcbot.on('end', function() {
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', function() {
|
||||
if (interval) {
|
||||
clearInterval(interval);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
@@ -4,6 +4,7 @@ module.exports = function(socket) {
|
||||
require('./events/login')(socket);
|
||||
require('./events/spawn')(socket);
|
||||
require('./events/message')(socket);
|
||||
require('./events/players')(socket);
|
||||
// require('./events/chat')(socket);
|
||||
require('./events/end')(socket);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user