[将minecraft与使用node.js或html的网站连接

问题描述 投票:0回答:1

我想输入类似www.myserverip.com/reward/(任何昵称)而在(任何昵称)中输入昵称的玩家获得了《我的世界》 1钻石,有人对此有想法吗?

编辑我的网站

但是我不知道,如何向Minecraft发送url

html node.js minecraft
1个回答
0
投票

我不熟悉Minecraft服务器的修改版本,但是我确实知道一种使用nodejs与Minecraft服务器进行交互的方法。

ScriptServer程序包允许您运行Minecraft服务器并阅读聊天记录,以及执行命令。

设置相对简单,只需记住在server.properties文件中设置这些属性:

enable-rcon=true
rcon.port=12345
rcon.password=password

示例代码:

const ScriptServer = require('scriptserver');

const server = new ScriptServer({
  core: {
    jar: 'minecraft_server.jar', //the jarfile of the server
    args: ['-Xmx2G'], //arguments for RAM usage, etc.
    rcon: {
      port: '12345',
      password: 'password'
    }
  }
});
server.start();

接下来,您需要使用Express之类的设置网站/ API>

const express = require("express");
const app = express();

app.get("reward/*",(req,res)=>{
  giveReward(req);
  res.send();
});

app.listen(/* Some port number here */)

函数giveReward接受请求并尝试给玩家一个钻石。代码可能看起来像这样:

function giveReward(request){
  //assuming that the path looks like "/reward/username"
  const username = request.path.split("/")[2];
  server.send(`give ${username} diamond`);
}

您可能需要调整代码以适合您的确切问题,但这应该有助于您了解如何做事。

© www.soinside.com 2019 - 2024. All rights reserved.