Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prismarine-chat

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prismarine-chat

Wrapper for a minecraft chat message

  • 1.7.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

prismarine-chat

NPM version Build Status Discord Gitter Irc Try it on gitpod

A parser for a minecraft chat message

Usage

const registry = require('prismarine-registry')('1.16')
const ChatMessage = require('prismarine-chat')(registry)

const msg = new ChatMessage({"text":"Example chat mesasge"})
console.log(msg.toString()) // Example chat message

API

ChatMessage(message,[displayWarning])

  • message - Can be either text or a minecraft chat JSON object
  • displayWarning - Display warnings if true, default to false
chat.toString([lang])

Flattens the message in to plain-text

  • lang - (optional) - Set a custom lang (defaults to mcData.language)
chat.toMotd([lang], parent)

Converts to motd format

  • lang - (optional) - Set a custom lang (defaults to mcData.language)
  • parent - Set a custom lang (defaults to mcData.language)
chat.getText(idx, [lang])

Returns a text part from the message

  • idx - Index of the part
  • lang - (optional) - Set a custom lang (defaults to mcData.language)
chat.toAnsi([lang])

Converts to ansi format

  • lang - (optional) - Set a custom lang (defaults to mcData.language)
chat.length()

Returns the count of text extras and child ChatMessages Does not count recursively in to the children

chat.append(ChatMessage)

Appends another ChatMessage or a string

chat.clone()

Returns a clone of the ChatMessage

const registry = require('prismarine-registry')('1.16')
const { MessageBuilder } = require('prismarine-chat')(registry)

const msg = new MessageBuilder().setText('Example chat mesasge')
console.log(JSON.stringify(msg)) // The string as a message component

static ChatMessage.fromNotch(msg)

Returns a prismarine-chat representation of the message recieved from the 'chat' packet, example shown here

static ChatMessage.fromNetwork(messageType, messageParameters)

(1.19+) Loads a chat message sent by server that needs to be formatted on client side.

MessageBuilder()

setBold (val: boolean) : this
setItalic (val: boolean) : this
setUnderlined (val: boolean) : this
setStrikethrough (val: boolean) : this
setObfuscated (val: boolean) : this
setColor (val: string) : this
setText (val: string) : this

check code for examples (and explanations) from here on

setFont (val: string) : this
setTranslate (val: string) : this
setInsertion (val: string) : this
setKeybind (val: string) : this
setScore (name: string, objective: string) : this
setClickEvent (action: string, value: object) : this
setHoverEvent (action: string, data: object, type?: 'contents'|'value') : this
addExtra (...val: MessageBuilder | string) : this
addWith (...val: MessageBuilder | string) : this
resetFormatting () : void

sets every one of the formatting options to false and sets text to reset type

toJSON () : object

builder.toJSON() is the same thing as JSON.stringify(builder)

toString () : string

runs JSON.stringify() on this

static MessageBuilder.fromString(str, {colorSeparator = '&'}) : MessageBuilder

convert string with color codes like &4Hello&cWorld to a MessageBuilder object

Keywords

FAQs

Package last updated on 01 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc