node-minecraft-protocol/examples/client_echo/client_echo.js

20 lines
576 B
JavaScript
Raw Normal View History

2015-03-26 11:25:36 -04:00
var mc = require('../../')
, states = mc.protocol.states
2013-01-02 03:30:33 -05:00
var client = mc.createClient({
username: process.env.MC_USERNAME,
password: process.env.MC_PASSWORD,
});
client.on('connect', function() {
2013-07-09 02:11:09 -04:00
console.info('connected');
2013-01-02 03:30:33 -05:00
});
2014-01-14 00:56:56 -05:00
client.on('chat', function(packet) {
2013-07-09 02:11:09 -04:00
var jsonMsg = JSON.parse(packet.message);
if (jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
var username = jsonMsg.with[0];
var msg = jsonMsg.with[1];
2013-07-09 02:11:09 -04:00
if (username === client.username) return;
client.write('chat', {message: msg});
2013-07-09 02:11:09 -04:00
}
2015-03-26 11:25:36 -04:00
});