PrismarineJS / mineflayer

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

Joining serverr: ERROR is not valid JSON #3363

Open SinanAkkoyun opened 6 months ago

SinanAkkoyun commented 6 months ago

Versions

Detailed description of a problem

When joining a server like GommeHD.net, following error sometimes occurs:

SyntaxError: "[object Object]" is not valid JSON
    at JSON.parse (<anonymous>)
    at Client.<anonymous> (/home/ai/.mc/ts-bot/node_modules/minecraft-protocol/src/client/versionChecking.js:6:21)
    at Client.emit (node:events:531:35)
    at Client.emit (node:domain:488:12)
    at emitPacket (/home/ai/.mc/ts-bot/node_modules/minecraft-protocol/src/client.js:83:12)
    at FullPacketParser.<anonymous> (/home/ai/.mc/ts-bot/node_modules/minecraft-protocol/src/client.js:112:9)
    at FullPacketParser.emit (node:events:519:28)
    at FullPacketParser.emit (node:domain:488:12)
    at addChunk (/home/ai/.mc/ts-bot/node_modules/protodef/node_modules/readable-stream/lib/_stream_readable.js:279:12)
    at readableAddChunk (/home/ai/.mc/ts-bot/node_modules/protodef/node_modules/readable-stream/lib/_stream_readable.js:262:11)

The server has a multi-version protocol which lets players from 1.8 to 1.20.4 play together.

What did you try yet?

Your current code

const bot = mineflayer.createBot({
  username,
  auth: 'microsoft',
  version: '1.20.4'
})

It's code independent

Expected behavior

Code should, if invalid JSON, catch that error and instead output string.

Additional context

/

overtimepog commented 6 months ago

try

const bot = mineflayer.createBot({
  host: 'server_ip',
  auth: 'microsoft',
  version: '1.20.2',
});

dont worry about the username, if you signed in correctly through microsoft itll know the username

nvm, I tried to move my bot to 1.20.3 and got the same error you did

SinanAkkoyun commented 6 months ago

I appriceate you trying it out too, it has nothing to do with the username. Chat messages, names etc inside that server must somehow be wrongly formatted because it's a multi version server (not a mineflayer error per-se I think) The solution would be: If JSON parsing fails (needs to be done for chat messages, entity names etc), try catch that and return a string instead of JSON

That's just a guess, before I PR anything I'd like to hear an opinion from someone who really knows whats going on