npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mcwss

v2.1.1

Published

Minecraft Bedrock Websocket Server Framework Base For Modern JavaScript

Downloads

59

Readme

Mcwss npm package wakatime

The project is refactory version for version of three years (2021) ago base on TypeScript.

A simple Minecraft Bedrock Edition websocket server framework, help developer to setup websocket server faster for Minecraft or your self package depend on it.Its core Mcwss base a events emiter and provide many of events which can be listened.In addition,it provides Client instance object to interact with every clent.

🧊 Usage

What? You donot know how to install Node.js program? Are you kidding me? Please find Google Search to help you.

Base on program cli to start:

mcwss

For C(~~Z~~)hinese(English understanding hard population):

mcwss --lang zh_CN

Start your Minecraft Bedrock Edition and input commands:

/wsserver ws://localhost:1
# or:
/connect ws://localhost:1

Test a few:

*/help
*/helph

Options

  • --port [num] Set websocket server port
  • --mode [type] Set logger level, debug or build
  • --lang [locale] Set view language, en_US, ja_JP, zh_TW, zh_CN
  • -v, --version Display version number
  • -h, --help Display this message

Example:

mcwss --port 2333 --mode debug --lang ja_JP

built-in commands

  • */help Show Mcwss command help
  • */connect Show WebSocket connection time
  • */about Show about information§r
  • */clears Clear chat content§r
  • */func <path> Execute mcfunction on server§r
  • */helph Show hidden command help§r",

Game hidden Command:

  • ./closewebsocket Close websocket connection§r
  • ./gettopsolidblock <x> <y> <z> Get top solid block coordinates§r
  • ./querytarget <selector> Get precise float coordinates of entity§r
  • ./agent Mascot§r
  • ./enableencryption Unknown§r
  • ./closechat Close chat§r
  • ./geteduclientinfo Get version info§r
  • ./getlocalplayername Return player name§r

🎯 Events

Lifecycle Events:

  • ready
  • dispose
  • error
  • connection
  • message
  • close

Minecraft Events:

  • block_broken
  • block_placed
  • end_of_day
  • entity_spawned
  • item_acquired
  • item_crafted
  • item_destroyed
  • item_smelted
  • item_used
  • jukebox_used
  • mob_interacted
  • mob_killed
  • player_bounced
  • player_died
  • player_message
  • player_teleported
  • player_transform
  • player_travelled
  • unknown_minecraft_event
  • command_response

🚀 Class

Mcwss

  • start(): void Start a websocket server
  • stop(): void Stop a websocket server

Extends Events:

  • emit<T extends keyof EventsList>(type: T, ...data: [...Parameters<EventsList[T]>]): void Emit a event
  • parallel<T extends keyof EventsList>(type: T, ...data: [...Parameters<EventsList[T]>]): Promise<void> Emit a event asynchronous
  • on<T extends keyof EventsList>(type: T, callback: EventsList[T]): void Listen a event
  • once<T extends keyof EventsList>(type: T, callback: EventsList[T]): void Listen a event once
  • off<T extends keyof EventsList>(type: T, callback: EventsList[T]): void Cancel to listen a event
  • offAll<T extends keyof EventsList>(type: T): void Cancel to listen all events

Client

  • req: IncomingMessage Client websocket object
  • sessionId: number Connection identify at Mcwss
  • sessionDate: Date Connection setup time
  • send(data: SendPacket): void Send a packet to client
  • close(): void Close connection with client
  • subscribe(event: MinecraftEvents): void Subscribe a minecraft event
  • unsubscribe(event: MinecraftEvents): void Unsubscribe a minecraft event
  • run(cmd: string | string[]): void Run a or many of command to client
  • chat(message: string): void Send a normal message to client (Base for /say)
  • chatf(message: string, color?: TextColor, sender?: string, target: CommandTarget = CommandTarget.SELF): void Send a advanced message to client (Base for /tellraw)
  • func(file: string): void Run a .mcfunction file to client
const enum TextColor {
  GREEN = '§a',
  RED = '§c',
  BLUE = '§b',
  YELLOW = '§e'
}

const enum CommandTarget {
  ALL = '@a',
  SELF = '@s',
  RANDOM = '@r',
  EVERY = '@e',
  NEAR = '@p'
}

🧩 Internationalization

Supports languages:

🌰 Example

Setup your self program or package base on Mcwss, refer to src/utils/line.ts for more information.

import Mcwss from 'mcwss';
import { log, error } from 'console';

const mcwss = new Mcwss({ port: 2333 });

/* events register */
mcwss.on('ready', () => log(`WebSocketServer started at ws://localehost:${port} `));

mcwss.on('dispose', () => log('WebSocketServer stopped'));

mcwss.on('error', (data) =>
  error(data.client ? `[Client:${data.client.sessionId}]` : '[Server]', data.error.name, data.error.message)
);

mcwss.on('connection', (data) =>
  log(`[Client:${data.client.sessionId}]`, 'new connection from', data.client.req.socket.remoteAddress)
);

mcwss.on('close', (data) => {
  if (data.raw) {
    log(`[Client:${data.raw.client.sessionId}]`, 'Closing in progress code:', data.raw.code);
    return;
  }
  log('WebSocketServer is closeing...');
});

mcwss.on('block_broken', (data) => {
  const { block, player, tool } = data.body;
  /* ... */
});

mcwss.on('end_of_day', (data) => {
  const { player } = data.body;
  /* ... */
});

/* ... */

mcwss.start();

📜 License

Comply with The GNU General Public License v3.0 open-source license.