1.0.0 • Published 2 years ago

@minecraft-js/chat v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Chat

GitHub Workflow Status GitHub npm (scoped)

Parse and serialize Minecraft chat messages. Provides builders to make it easy to do.

Documentation

Installation

Install the package:

$ npm install @minecraft-js/chat

And then import it in your JavaScript/TypeScript file

const chat = require('@minecraft-js/chat').default; // CommonJS

import * as chat from '@minecraft-js/chat'; // ES6

Build a message

const component = new chat.StringComponentBuilder();
component
.setText('Hello World') // Set the text to 'Hello World'
.setColor(chat.MinecraftColor.RED) // Set the color to red
.setBold(true); // Set the bold flag to true
// And so on, all fields are handled by the builder

Parse a message

const message = '{"translate":"chat.type.text","with":[{"text":"Herobrine","clickEvent":{"action":"suggest_command","value":"/msg Herobrine "},"hoverEvent":{"action":"show_entity","value":"{id:f84c6a79-0a4e-45e0-879b-cd49ebd4c4e2,name:Herobrine}"},"insertion":"Herobrine"},{"text":"I don\'t exist"}]}'
const parsed = chat.ComponentBuilder.parse(message);

console.log(parsed.component.translate); // chat.type.text
parsed.setTranslate('chat.whatever');
console.log(parsed.component.translate); // chat.whatever

Everything is typed and documented as well. (Most of the documentation is a copy paste from Wiki.vg