- i've decided to make a wrapper for the Minecraft Bedrock WSS API
- in javascript
- this is still a very early version of it, though
let api = require('mcwss-api')
api.start(8080, '127.0.0.1', {
logCmdErrors: false, // log command syntax errors
logCmdOutput: false, // log command output
logMsgErrors: false, // log errors from the client
logSeriousErrors: true, // log serious errors (they'd likely be JSON parse errors)
logOther: false // log other stuff
})
try {
api.wss.on('connection', (ws, req) => {
api.subscribe(ws, 'PlayerMessage') // listen for PlayerMessage events
api.on(ws, 'PlayerMessage', msg => {
console.log(msg) // logs any PlayerMessage event that goes through
})
});
} catch (err) {
console.log(`error: ${err}`) // log any errors that occur
}
- runs a minecraft command
api.runCommand(ws, command)
- starts the WSS
api.start(port, host, opts)
- stops the WSS
api.stop()
- listen for a specific event type
api.subscribe(ws, eventType)
- stop listening for a specific event type
api.unsubscribe(ws, eventType)
- the WSS itself
- the wrapper options
- these are all of the events that worked when i tested them
- you can figure out the JSON, i'm too lazy to write that
- most of these only work for whatever client is connected to the wss (the host in most cases), so maybe test it first before you get too excited
- the obvious one, fires every time a message sends
- this only works with messages from other players, if you are the host
- this fires whenever the player moves
- as far as i know, exact same thing as PlayerTravelled, not sure what the difference is
- this fires whenever the player teleports (via /tp)
- this fires whenever the player dies
- this fires whenever the player bounces on a slime block, bed, or any bounceable block
- this fires whenever you spawn smth with a spawn egg
- this fires whenever you use an item, or place it's block
- this fires whenever you pick up an item
- this fires whenever you grab a cooked item out of a furnace
- this fires whenever you craft something
- this fires whenever you place a block
- this fires whenever you break a block
- this fires whenever you kill a mob
- this fires whenever you interact with a mob (unless it has no interact function)