mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-06-03 19:58:27 +02:00
More performant way of defining event listeners
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
module.exports = (socket) => {
|
||||
|
||||
socket.on('chat', (data) => {
|
||||
function onChat(data) {
|
||||
if (socket.mcbot && socket.mcbot.entity) {
|
||||
socket.mcbot.chat(data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('chat', onChat);
|
||||
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import events from '../../bot';
|
||||
|
||||
module.exports = (socket) => {
|
||||
|
||||
socket.on('server:connect', (data) => {
|
||||
function onConnection(data) {
|
||||
|
||||
// log activity to console
|
||||
console.log(`connecting > ${data.hostname}:${data.port} - ${data.username}`);
|
||||
@@ -36,6 +36,8 @@ module.exports = (socket) => {
|
||||
// bind bot events
|
||||
events(socket);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('server:connect', onConnection);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
module.exports = (socket) => {
|
||||
|
||||
|
||||
socket.on('disconnect', () => {
|
||||
function onDisconnection() {
|
||||
if (socket.mcbot) {
|
||||
socket.mcbot.end();
|
||||
delete socket.mcbot;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
socket.on('bot:disconnect', () => {
|
||||
if (socket.mcbot) {
|
||||
socket.mcbot.end();
|
||||
delete socket.mcbot;
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('disconnect', onDisconnection);
|
||||
socket.on('bot:disconnect', onDisconnection);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
module.exports = (socket) => {
|
||||
|
||||
socket.on('players', () => {
|
||||
function onPlayers() {
|
||||
if (socket.mcbot && socket.mcbot.players) {
|
||||
socket.emit('bot:players', socket.mcbot.players);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('players', onPlayers);
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user