PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

JSON.parse crash in chat.js due to packet.senderName being undefined #2837

Closed Redbandithero closed 1 year ago

Redbandithero commented 1 year ago

Versions

Detailed description of a problem

SyntaxError: Unexpected token u in JSON at position 0 On line 135 of chat.js in \node_modules\mineflayer\lib\plugins\chat.js packet.senderName is parsed into JSON unsuccessfully, this is due to packet.senderName being "undefined".

I am not currently using any chat methods in my index.js but the bot crashes immediately after anyone chats on the server.

What did you try yet?

I have tried modifying the packet.senderName to contain curly brackets at the beginning and end while also using the real sender's username provided by "const sender = bot.uuidToUsername[packet.senderUuid]" on line 129 of chat.js.

Your current code


const mineflayer = require('mineflayer')

const bot = mineflayer.createBot({
    host: '***',
    port: 25565,
    username: 'ServerBot'
})

Expected behavior

The bot is expected to have no response to chat messages.

Additional context

I have tried running the bot on multiple different versions of node and different machines with no success.

image_2022-11-21_160604950

Ingame Example: https://streamable.com/og9byr

Redbandithero commented 1 year ago

Just tested putting in a predetermined input for the problem and it made it work slightly, enough to atleast get to the other problem which is the very next line of chat.js.

The first problem can be fixed (to my knowledge) by just using that new variable and removing the JSON.parse. The second instance of the problem doesn't appear to have any alternative variables. image

Redbandithero commented 1 year ago

... doesn't appear to have any alternative variables.

Current solution is to just replace it with a empty string, solves the crash but means the bot cannot read chat at all. If anyone has a better solution (which is very likely), then please tell me as I would like the bot to have access to chat.

amoraschi commented 1 year ago

1.19.2 isn't supported yet

extremeheat commented 1 year ago

2797