NetworkJS

模组

· 作者 snowylol_

一个强大的 KubeJS 插件,为您的 Minecraft 服务器脚本启用互联网连接和 Discord 集成。

0 本站下载 0 关注 更新于 1 年前

最新 1.1.0 · 1.21.8 · NeoForge

一键开服(送7天)

NetworkJS

一个强大的 KubeJS 插件,为你的 Minecraft 服务器脚本提供互联网连接和 Discord 集成支持。

注意:这是我的第一个 Java 模组!我还在学习中,非常欢迎反馈和贡献。 :D

功能

  • HTTP/FETCH 支持 - 从你的 KubeJS 脚本中发起 HTTP 请求
  • Discord Bot 集成 - 发送消息、嵌入内容,并监听 Discord 事件
  • 服务器工具 - 向玩家发送彩色消息并获取服务器信息
  • 易于集成 - 通过全局函数和类访问方式与 KubeJS 无缝协作

安装

  1. 从 发布页面 下载最新的 jar 文件
  2. 将 jar 文件放入 mods 文件夹
  3. 确保已安装 KubeJS
  4. 重启服务器

API 参考

全局函数

// HTTP 请求 - 现在可作为全局函数使用!
fetch('https://api.example.com/data')
fetchAsync('https://api.example.com/data', { 
    method: 'POST', 
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ key: 'value' })
})

全局类

DiscordBot - Discord 集成

const config = {
    token: "your-bot-token",
    guild: "your-guild-id", 
    channels: {
        chat: "channel-id",
        announcements: "channel-id"
    },
    sanitizeMessages: true
};

const bot = new DiscordBot(config);

// 发送消息
bot.sendMessage("chat", "Hello from Minecraft!");

// 发送嵌入内容
bot.sendEmbed("announcements", {
    title: "Server Status",
    description: "Server is online!",
    color: 0x00ff00
});

// 监听 Discord 消息
bot.onMessage(function(discordMessage) {
    console.log("Message from " + discordMessage.getAuthor() + ": " + discordMessage.getContent());
});

// 设置机器人活动状态
bot.setActivity("Minecraft Server Online");

Server - Minecraft 服务器工具

// 向所有玩家发送彩色消息
Server.sendRawMessage("&aWelcome to the server!");

// 向特定玩家发送消息
Server.sendRawMessageToPlayer("PlayerName", "&bHello there!");

// 获取服务器信息
const playerCount = Server.getPlayerCount();
const playerNames = Server.getPlayerNames(); // 返回字符串数组

FetchBinding - HTTP 请求(旧版)

// 你仍然可以使用基于类的方式
const response = FetchBinding.fetch("https://api.example.com");
console.log("Status:", response.getStatus());
console.log("Response:", response.text());

// 带选项的请求
const options = new FetchOptions("POST", {"Content-Type": "application/json"}, '{"data": "value"}');
const response = FetchBinding.fetch("https://api.example.com", options);

// 异步请求
const futureResponse = FetchBinding.fetchAsync("https://api.example.com");

完整的 API 导出

以下类和函数在你的 KubeJS 脚本中全局可用:

导出项 类型 描述
fetch() 函数 发起 HTTP 请求(全局函数)
fetchAsync() 函数 发起异步 HTTP 请求(全局函数)
DiscordBot 类 Discord 机器人功能
Server 类 服务器工具
FetchBinding 类 HTTP 请求工具(旧版)
FetchOptions 类 HTTP 请求选项
FetchResponse 类 HTTP 响应对象

示例用法

Discord-Minecraft 桥接

const discordConfig = {
    token: "your-bot-token",
    guild: "your-guild-id",
    channels: { chat: "chat-channel-id" }
};

const bot = new DiscordBot(discordConfig);

// 将 Discord 消息中继到 Minecraft
bot.onMessage(function(msg) {
    if (msg.isFromConfiguredChannel() && !msg.isBot()) {
        Server.sendRawMessage(`&7[Discord] &f${msg.getAuthor()}: ${msg.getContent()}`);
    }
});

// 将 Minecraft 聊天中继到 Discord
PlayerEvents.chat(event => {
    const playerName = event.player.name.getString();
    const message = event.message;
    bot.sendMessage("chat", `**${playerName}**: ${message}`);
});

服务器状态 API

// 使用 fetch 创建简单的 API 端点
ServerEvents.loaded(event => {
    const statusData = {
        online: true,
        players: Server.getPlayerCount(),
        playerList: Server.getPlayerNames()
    };
    
    // 发送到你的状态 API
    fetchAsync('https://your-api.com/server-status', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(statusData)
    });
});

要求

  • Minecraft 1.21.1
  • NeoForge 21.1.200+
  • KubeJS 2101.7.1+

构建

git clone https://github.com/SSnowly/NetworkJS.git
cd NetworkJS
./gradlew build

构建后的 jar 文件位于 build/libs/networkjs-1.21.1-{version}.jar

许可证

本项目采用 MIT 许可证授权 - 详情请参阅 LICENSE 文件。

贡献

作为一名新的 Java 开发者,我一直在寻求改进!欢迎:

  • 为 bug 或功能请求提交问题
  • 提交包含改进的拉取请求
  • 分享对代码结构的反馈
  • 帮助完善文档

支持


由 ME 用 <3 制作!

你是这个资源的作者?登录后可认领此资源。

评论 0

0.0
暂无评分
5 星
0
4 星
0
3 星
0
2 星
0
1 星
0
我的评分

登录后参与评分

还没有评论,来抢沙发吧

评论配图

相似资源