NetworkJS
一个强大的 KubeJS 插件,为你的 Minecraft 服务器脚本提供互联网连接和 Discord 集成支持。
注意:这是我的第一个 Java 模组!我还在学习中,非常欢迎反馈和贡献。 :D
功能
- HTTP/FETCH 支持 - 从你的 KubeJS 脚本中发起 HTTP 请求
- Discord Bot 集成 - 发送消息、嵌入内容,并监听 Discord 事件
- 服务器工具 - 向玩家发送彩色消息并获取服务器信息
- 易于集成 - 通过全局函数和类访问方式与 KubeJS 无缝协作
安装
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 或功能请求提交问题
- 提交包含改进的拉取请求
- 分享对代码结构的反馈
- 帮助完善文档
支持
- 为 bug 提交 issue
- 查看 KubeJS Wiki 以获取通用的 KubeJS 帮助
由 ME 用 <3 制作!
你是这个资源的作者?登录后可认领此资源。
相似资源
Woot Revived
pharuxtan
一个用于收集生物掉落物的多区块模组。
生物科技
349
玉Jade ?
Snownee
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
实用前置
247
物品管理器Just Enough Items (JEI)
mezz
查看物品与配方
前置实用
229
Xaero的小地图
thexaero
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
冒险交通
196
KubeJS
Lat
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
前置实用
181
AAA Particles
ChloePrime
适用于 MC 1.18+ 的 Effekseer 加载器
前置装饰
173
评论 0
登录后参与评分
还没有评论,来抢沙发吧