Fix chat echo sample (#233)

* Fix chat echo sample

The `client.options.username` reference is optional for online connections.  Referencing it here when it is null will not filter out the echo text, causing an infinite loop.

* Update client.js
This commit is contained in:
Jonathan Nagy 2022-06-28 11:49:54 +10:00 committed by GitHub
commit 7263714562
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View file

@ -50,7 +50,7 @@ const client = bedrock.createClient({
})
client.on('text', (packet) => { // Listen for chat messages and echo them back.
if (packet.source_name != client.options.username) {
if (packet.source_name != client.username) {
client.queue('text', {
type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '',
message: `${packet.source_name} said: ${packet.message} on ${new Date().toLocaleString()}`

View file

@ -8,10 +8,10 @@ const client = bedrock.createClient({
})
client.on('text', (packet) => { // Listen for chat messages and echo them back.
if (packet.source_name != client.options.username) {
if (packet.source_name != client.username) {
client.queue('text', {
type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '',
message: `${packet.source_name} said: ${packet.message} on ${new Date().toLocaleString()}`
})
}
})
})