Okay, so, I'm having trouble sending players strings combined with variables. For example, this line of code:
client.write("chat", { message: ("Username:"+data.data[0]["name"].toString())})
This data variable is a JSON object. Printing out
"Username:"+data.data[0]["name"].toString()
Works without an error, but when I try send it to the client, the client disconnects with this error message:
Internal Exception: io.netty.handler.codec.DecoderException:
com.google.gson.JsonSyntaxException:
com.google.gson.stream.MalformedJsonException: Use
JsonReader.setLenient(true) to accept malformed JSON at line 1 column 10
BTW, I'm using npm minecraft-protocol javascript
I just checked the documentation and the sent message doesn't correspond to the format that should be used.
The json should NOT be in json direclty, but should be stringified. So, such as the usage said, you should use something like that:
var msg = {
translate: 'chat.type.announcement',
"with": [
'Username',
data.data[0]["name"]
]
};
client.write("chat", { message: JSON.stringify(msg), position: 0, sender: '0' });