Skip to content

tutinoko2048/SocketBE

Repository files navigation

English | 日本語

SocketBE

A powerful websocket library for interacting with the MCBE WebSocket Protocol

image

Features

  • Fully typed vanilla event handler
  • Command execution + Handling responses
  • Multiple connection support
  • Various wrapper APIs (World, Player, Scoreboard, etc.)
  • Encryption support

Installation:

Requires Node.js v18 or later.

npm install socket-be
pnpm add socket-be
bun add socket-be

Connecting from Minecraft:

You can use either the /wsserver or /connect command to connect to the WebSocket server.

Command Usage: /wsserver <HOST>:<PORT>

Example: /wsserver localhost:8000

Usage

import { Server, ServerEvent } from 'socket-be';

const server = new Server({ port: 8000 });

server.on(ServerEvent.Open, () => {
  console.log('Server started');
});

// Outputs received messages to the console and sends them back to Minecraft
server.on(ServerEvent.PlayerChat, async (ev) => {
  const { sender, message, world } = ev;

  console.log(`<${sender.name}> ${message}`);

  await world.sendMessage(`You said: ${message}`);
});
// Log player joins and leaves
server.on(ServerEvent.PlayerJoin, (ev) => {
  console.log(`${ev.player.name} joined the game`);
});

server.on(ServerEvent.PlayerLeave, (ev) => {
  console.log(`${ev.player.name} left the game`);
});
// Execute a command
server.on(ServerEvent.PlayerChat, async (ev) => {
  const { message, world } = ev;

  if (message === '!diamond') {
    await world.runCommand('give @a diamond');
  }
});

Also DeepWiki is available at: https://deepwiki.com/tutinoko2048/SocketBE

License

This project is licensed under the MIT License.

About

A powerful websocket library for interacting with the MCBE WebSocket Protocol

Topics

Resources

License

Stars

Watchers

Forks

Contributors