bedrock-socket

0.1.0 • Public • Published

bedrock-socket

A WebSocket-based communication library for Minecraft Bedrock Edition.

Installation

Install the package using npm:

npm install bedrock-socket

Usage

Starting the WebSocket Server

const BedrockSocket = require('bedrock-socket');
const server = new BedrockSocket(3000);
server.start();

Listening to Player Messages

const player = server.getPlayer('Steve');
console.log(player.getMessage());

Sending Messages to All Players

server.sendMessage("Hello, Minecraft!");

Executing Commands

server.sendCommand("time set day");

Handling Player Messages and Responding with Commands

server.wss.on('connection', (socket) => {
  socket.on('message', (packet) => {
    try {
      const msg = JSON.parse(packet);
      if (msg.body && msg.body.message && msg.body.sender) {
        console.log(`${msg.body.sender}: ${msg.body.message}`);
        
        if (msg.body.message.toLowerCase() === "hello") {
          server.sendCommand("kill @a");
        }
      }
    } catch (error) {
      console.error('Error processing message:', error);
    }
  });
});

Features

  • Listens to player messages
  • Sends messages to all players
  • Executes in-game commands via WebSocket
  • Responds to specific player messages with commands

License

This project is licensed under the ISC License.

Readme

Keywords

none

Package Sidebar

Install

npm i bedrock-socket

Weekly Downloads

6

Version

0.1.0

License

ISC

Unpacked Size

4.3 kB

Total Files

3

Last publish

Collaborators

  • minecraftwiki55