MWL是一个易于使用的Minecraft Websocket开发库
本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。
npm install meowslib
输出玩家聊天信息:
const MeoWS = require('meowslib');
const WSServer = MeoWS.WSServer;
const BuildSession = MeoWS.BuildSession;
let wss = new WSServer(23333);
wss.on('client', (session, request) => {
console.log(request.connection.remoteAddress + ' connected!');
session.tellraw('MeoWebsocket library v2.0.0 by CAIMEO.');
BuildSession.createAndBind(session);
session.on('onMessage',(msg, player)=>{
console.log(`[${player}]Message: `, msg);
});
});事件监听器(此处订阅了BlockPlaced事件):
wss.on('client', (session, request) => {
console.log(request.connection.remoteAddress + ' connected!');
session.tellraw('MeoWebsocket library v2.0.0 by CAIMEO.');
BuildSession.createAndBind(session);
session.subscribe("BlockPlaced", (json) => {
console.log("BlockPlaced:", json);
})
});port{Number} 服务器端口
socket{Session} 一般绑定WSServerSession
命令解析器
command{String} 用户命令options{Object} 规则 返回一个Object
当玩家发送消息时触发,传入信息内容(message)和发送者(Sender)
当玩家发送消息时触发,不同的是,它将传回json
发生错误时触发,传回错误信息
党玩家发送消息并被Parser解析完成时触发,传回object
向客户端发送命令
- command {String} 命令
- callback {Function} 回调函数,传入json
向客户端发送命令(Promise)
- command {String} 命令
订阅游戏事件
- event {String} 游戏事件
- callback {String}回调函数,传入json
取消订阅游戏事件
- event {String} 游戏事件
发送信息
- text {String} 要发送的消息
tellraw代码
- text {String} 要发送的消息
- color {String} 颜色代码