bedrock-websocket-js
v3.1.0
Published
A WebSocket server for Minecraft Bedrock Edition, offering fully typed event handling, real-time player and game interactions, and seamless integration for JavaScript projects.
Maintainers
Readme
Bedrock WebSocket SDK
A high-performance Node.js SDK for real-time Minecraft: Bedrock Edition integration. Connect, track, and interact with your Minecraft world in real-time through WebSocket events.
🚀 Quick Start
Installation
npm install bedrock-websocket-jsBasic Setup (5 lines of code)
const { BedrockWebSocket } = require('bedrock-websocket-js');
const server = new BedrockWebSocket({ port: 8080 });
server.on('PlayerEvent:PlayerMessage', (player, message) => {
console.log(`💬 ${player.name}: ${message}`);
});Terminal output
[INFO]: WebSocket server started on port 8080
[INFO]: Players database initialized
[INFO]: Intervals started:
Heartbeat: 5m 0s,
Sync: 1m 0s
[INFO]: 🟢 BEDROCK WEBSOCKET SERVER - OPERATIONAL
├─ Players: 0 online, 1 tracked
├─ Max Clients: 50 allowed
├─ Events: 12 monitored
├─ Heap Memory: 7MB used
└─ Status: Ready for Minecraft connectionsConnect Minecraft
/connect ws://localhost:8080Cheats must be enabled • Requires operator permissions or by using PurePerms plugin
⚡ Real-Time Events Made Simple
Track Player Movements
server.on('PlayerEvent:PlayerTravelled', (player, vehicle, metadata) => {
console.log(`📍 ${player.name} moved ${metadata.metersTravelled}m`);
// Automatically tracks player position in cache
});Monitor Player Actions
server.on('PlayerEvent:BlockPlaced', (player, block, tool) => {
console.log(`${player.name} placed ${block.name}`);
});
server.on('PlayerEvent:ItemAcquired', (player, item) => {
console.log(`${player.name} got ${item.count}x ${item.name}`);
});Combat & Survival Events
server.on('PlayerEvent:MobKilled', (player, victim, weapon) => {
console.log(`${player.name} killed ${victim.type} with ${weapon.name}`);
});
server.on('PlayerEvent:PlayerDied', (player, killer) => {
console.log(`${player.name} died to ${killer?.type || 'unknown'}`);
});🎯 Powerful Features
Instant Player Location Lookup
// Find players within 50 blocks (O(1) performance)
const nearby = server.CoordCache.getPlayersInRadius(
{ x: 100, y: 64, z: 200 },
50,
'Overworld'
);
console.log(`Nearby players: ${nearby.map(p => p.username).join(', ')}`);Send Commands to Players
// Send to specific player
server.commands.sendToPlayer('minecraft-Id', 'say Hello from code!');
// Broadcast to all players
server.commands.broadcastCommand('time set day');Real Player Tracking
// Always know who's online
const onlinePlayers = server.players.getOnlinePlayers();
console.log(`Online: ${onlinePlayers.map(p => p.name).join(', ')}`);Spatial Queries
// Find players in specific square area
const spawnPlayers = server.CoordCache.getPlayersInSquare(
{ x: 0, y: 64, z: 0 }, // Center point
100, // 100x100 block area
'Overworld' // Dimension
);
// Find players within 50 blocks of a point (circular area)
const nearbyPlayers = server.CoordCache.getPlayersInRadius(
{ x: 100, y: 64, z: 200 }, // Center point
50, // Radius in blocks
'Overworld' // Dimension
);Built for Performance
- O(1) Spatial Queries: Find players instantly with chunk-based indexing
- Memory Efficient: Object pooling prevents garbage collection pressure
- Production Ready: Handles 500+ concurrent players smoothly
🛠️ Configuration
const server = new BedrockWebSocket({
port: 8080, // WebSocket port
maxClients: 100, // Maximum connections
heartbeatInterval: 300000, // 5-minute health checks
databasePath: './players.db' // Player data storage
});🎮 Use Cases
- Live Player Dashboards: Real-time player tracking and analytics
- Automated Moderation: React to player actions instantly
- Mini-game Servers: Build custom game mechanics
- Stream Overlays: Show live game data on streams
🔗 Connect Instantly
- Install:
npm install bedrock-websocket-js - Code: Copy the examples above
- Connect: Use
/connect ws://<ip>:8080in Minecraft - Build: Create amazing real-time features!
Perfect for: Server owners • Plugin developers • Educators • Streamers • Minecraft enthusiasts
No TypeScript required • Works with any Node.js project • MIT Licensed
Built with ❤️ for the Minecraft community
