Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89fdf3619d | ||
|
|
0d6c911126 | ||
|
|
c9dd8a83b9 | ||
|
|
e1ab8ec1fe | ||
|
|
8c52e5f1bd | ||
|
|
8881af586b | ||
|
|
367962d45b | ||
|
|
41638e8037 | ||
|
|
38a21684a1 | ||
|
|
c89837c01a | ||
|
|
b8c865d198 | ||
|
|
1365083586 | ||
|
|
96769efdbb | ||
|
|
09c2392b99 |
No files matched your search
@@ -2,6 +2,55 @@
|
|||||||
|
|
||||||
本文件记录 Iridium 的重要变更。
|
本文件记录 Iridium 的重要变更。
|
||||||
|
|
||||||
|
## [26.9.13] - 2026-09-13
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- 首次启动自动生成带中文注释的 `config/iridium.json`
|
||||||
|
- 配置文件支持 `//` 行注释
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- 提交信息改为中文
|
||||||
|
- 清理历史 Release,仅保留当前版本
|
||||||
|
|
||||||
|
## [26.9.8] - 2026-09-13
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `!!share`:去掉「点击复制完整数据」,仅保留物品名 + 悬停预览(与 ShowIt 风格一致)
|
||||||
|
|
||||||
|
## [26.9.7] - 2026-09-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `!!share`:无 NBT 改名时,正文 fallback 改为 ID 美化名(如 `Time Twister Wireless`),不再直接显示 `kubejs:...`;语言键命中则显示正式本地化名
|
||||||
|
|
||||||
|
## [26.9.6] - 2026-09-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `!!share`:默认物品名改为客户端 `translate` 组件(如 `block.ae2.fluix_covered_cable`),本地化显示正式名;仅有 NBT 自定义名时仍显示改名
|
||||||
|
- `!!share`:提示音在玩家位置播放,避免 "sound is too far away"
|
||||||
|
|
||||||
|
## [26.9.5] - 2026-09-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `!!hat`(1.17+):改用副手缓冲做真正交换,避免复杂 NBT 重建失败导致原头盔消失;副手非空时拒绝并提示
|
||||||
|
- `!!share`:展示名优先取 `custom_name` / `display.Name` / translate,不再只显示物品 ID
|
||||||
|
|
||||||
|
## [26.9.4] - 2026-09-13
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- 操作日志:`!!share` / `!!hat` / `!!head` / `!!c` 成功时写入 MCDR 控制台(`[Iridium] ...`)
|
||||||
|
|
||||||
|
## [26.9.3] - 2026-09-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- `!!share` / `!!hat` / `!!head`:`info.version` 若为字符串时比较崩溃(`Cannot compare Version and str`)
|
||||||
|
- `!!c`:命令回调少绑定 `server` 导致 `do_calc() missing ... context`
|
||||||
|
|
||||||
|
## [26.9.2] - 2026-09-13
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- 语言文件 YAML 解析失败(值中含 `:` 未加引号导致 `mapping values are not allowed`)
|
||||||
|
- 进服事件名错误:`PLAYER_JOIN` → `PLAYER_JOINED`(否则插件 on_load 失败)
|
||||||
|
|
||||||
## [26.9.1] - 2026-09-13
|
## [26.9.1] - 2026-09-13
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ MCDReforged 插件:物品展示 / 戴头 / 获取头颅 / 游戏内计算器 /
|
|||||||
|
|
||||||
| | |
|
| | |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 版本 | **26.9.1** |
|
| 版本 | **26.9.13** |
|
||||||
| 作者 | 云镜之端/SKYMirror |
|
| 作者 | 云镜之端/SKYMirror |
|
||||||
| 许可 | 保留所有权益(All Rights Reserved) |
|
| 许可 | 保留所有权益(All Rights Reserved) |
|
||||||
| 前置 | MCDReforged `>= 2.6.0` |
|
| 前置 | MCDReforged `>= 2.6.0` |
|
||||||
@@ -15,7 +15,7 @@ MCDReforged 插件:物品展示 / 戴头 / 获取头颅 / 游戏内计算器 /
|
|||||||
|
|
||||||
| 功能 | 说明 |
|
| 功能 | 说明 |
|
||||||
|------|------|
|
|------|------|
|
||||||
| `!!share` | 展示主手物品:悬停看完整 NBT/组件,1.16+ 可点击复制,可选提示音 |
|
| `!!share` | 展示主手物品:聊天栏显示物品名,悬停查看完整数据 |
|
||||||
| `!!hat` | 主手与头部装备互换 |
|
| `!!hat` | 主手与头部装备互换 |
|
||||||
| `!!head [player]` | 给自己或指定玩家 **1 个** 头颅;有冷却 |
|
| `!!head [player]` | 给自己或指定玩家 **1 个** 头颅;有冷却 |
|
||||||
| `!!c <表达式>` | 四则运算 + 括号:`+ - * / // % ** ^` |
|
| `!!c <表达式>` | 四则运算 + 括号:`+ - * / // % ** ^` |
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
# 提交到 MCDReforged 官方插件库
|
||||||
|
|
||||||
|
官方库:https://github.com/MCDReforged/PluginCatalogue
|
||||||
|
贡献指南:https://github.com/MCDReforged/PluginCatalogue/blob/master/CONTRIBUTING_zh_cn.md
|
||||||
|
|
||||||
|
## 当前进度
|
||||||
|
|
||||||
|
仓库:https://github.com/HzSKYMirror/Iridium
|
||||||
|
|
||||||
|
| 步骤 | 状态 |
|
||||||
|
|------|------|
|
||||||
|
| 公开 GitHub 仓库 | 已创建(当前可能仍为空,需推送) |
|
||||||
|
| `plugin_info.json` | 已写好(`catalogue/plugin_info.json`) |
|
||||||
|
| GitHub Release + `.mcdr` 附件 | **待完成** |
|
||||||
|
| 官方库 PR | **待完成** |
|
||||||
|
|
||||||
|
## 硬性前提
|
||||||
|
|
||||||
|
1. **公开 GitHub 仓库**(官方脚本只认 GitHub,不认 git.skymirror.top)
|
||||||
|
2. **GitHub Release 标签正确,附件为 `.mcdr`**
|
||||||
|
建议 Tag:`v26.9.1`;附件:`Iridium.mcdr`
|
||||||
|
3. **根目录有 `README.md`**(已有)
|
||||||
|
4. **许可**:官方强烈建议 OSI 开源许可;专有许可可提但审阅更慢,且提交即授权社区从 GitHub Releases 下载使用
|
||||||
|
5. **一个 PR 只加一个插件**
|
||||||
|
|
||||||
|
## 提交步骤
|
||||||
|
|
||||||
|
### 1. 推送源码到 GitHub
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /Users/l3126596029/Code/MCDR_plg/Iridium
|
||||||
|
git remote add github https://github.com/HzSKYMirror/Iridium.git
|
||||||
|
git push -u github main
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. 在 GitHub 发 Release
|
||||||
|
|
||||||
|
- Tag:`v26.9.1`
|
||||||
|
- 附件:本地执行 `./pack.sh` 得到的 `Iridium.mcdr`
|
||||||
|
|
||||||
|
### 3. 向官方库提 PR
|
||||||
|
|
||||||
|
1. Fork https://github.com/MCDReforged/PluginCatalogue
|
||||||
|
2. 新建文件:`plugins/iridium/plugin_info.json`
|
||||||
|
内容直接使用本仓库 `catalogue/plugin_info.json`
|
||||||
|
3. 向 `MCDReforged/PluginCatalogue` 的 `master` 发起 Pull Request
|
||||||
|
|
||||||
|
### PR 标题
|
||||||
|
|
||||||
|
```text
|
||||||
|
Add plugin: iridium
|
||||||
|
```
|
||||||
|
|
||||||
|
### PR 描述
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
## Plugin
|
||||||
|
|
||||||
|
- ID: `iridium`
|
||||||
|
- Name: Iridium
|
||||||
|
- Repository: https://github.com/HzSKYMirror/Iridium
|
||||||
|
- Release: https://github.com/HzSKYMirror/Iridium/releases/tag/v26.9.1
|
||||||
|
- Labels: `tool`
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
物品展示(!!share)、戴头(!!hat)、获取玩家头颅(!!head)、
|
||||||
|
游戏内计算器(!!c)、进服 MOTD 与命令提示。
|
||||||
|
|
||||||
|
面向 Minecraft 1.7.10+,按版本分支;需要 MCDR >= 2.6.0。
|
||||||
|
打包插件为 `.mcdr`,Release 已附带成品。
|
||||||
|
|
||||||
|
## Checklist
|
||||||
|
|
||||||
|
- [x] Packaged plugin (.mcdr) with a release
|
||||||
|
- [x] README.md in repository root
|
||||||
|
- [x] plugin_id consistent (`iridium`)
|
||||||
|
- [x] One plugin per PR
|
||||||
|
```
|
||||||
|
|
||||||
|
## 可选优化
|
||||||
|
|
||||||
|
| 项 | 建议 |
|
||||||
|
|----|------|
|
||||||
|
| 许可 | 改为 MIT / Apache-2.0 更易过审 |
|
||||||
|
| 英文 README | 可另加 `README_en.md` 并写入 introduction |
|
||||||
|
| label | `tool`(官方标签:information / tool / management / api / handler) |
|
||||||
|
|
||||||
|
## 本地校验(可选)
|
||||||
|
|
||||||
|
官方脚本需 Python >= 3.11:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd PluginCatalogue/scripts
|
||||||
|
pip3 install -r requirements.txt
|
||||||
|
python3 main.py check --help
|
||||||
|
```
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"id": "iridium",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "云镜之端/SKYMirror",
|
||||||
|
"link": "https://github.com/HzSKYMirror"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"repository": "https://github.com/HzSKYMirror/Iridium",
|
||||||
|
"branch": "main",
|
||||||
|
"related_path": ".",
|
||||||
|
"labels": ["tool"],
|
||||||
|
"introduction": {
|
||||||
|
"zh_cn": "README.md",
|
||||||
|
"en_us": "README.md"
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-6
@@ -10,16 +10,12 @@ import iridium.hat as hat
|
|||||||
import iridium.head as head
|
import iridium.head as head
|
||||||
import iridium.join_tip as join_tip
|
import iridium.join_tip as join_tip
|
||||||
import iridium.share as share
|
import iridium.share as share
|
||||||
from iridium.config import CONFIG_FILE, Config, apply_config
|
from iridium.config import Config, apply_config, load_config
|
||||||
from iridium.version_util import tr
|
from iridium.version_util import tr
|
||||||
|
|
||||||
|
|
||||||
def on_load(server: PluginServerInterface, prev_module) -> None:
|
def on_load(server: PluginServerInterface, prev_module) -> None:
|
||||||
loaded = server.load_config_simple(
|
loaded = load_config(server)
|
||||||
CONFIG_FILE,
|
|
||||||
target_class=Config,
|
|
||||||
in_data_folder=False,
|
|
||||||
)
|
|
||||||
apply_config(loaded)
|
apply_config(loaded)
|
||||||
server.logger.info(tr("loaded"))
|
server.logger.info(tr("loaded"))
|
||||||
|
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ def do_calc(server: PluginServerInterface, src: CommandSource, context: dict) ->
|
|||||||
return
|
return
|
||||||
|
|
||||||
out = _format_result(result)
|
out = _format_result(result)
|
||||||
|
who = src.get_info().player if src.is_player else "console"
|
||||||
|
server.logger.info(f"[Iridium] !!c: {who} {expression} = {out}")
|
||||||
# Private reply to avoid flooding public chat
|
# Private reply to avoid flooding public chat
|
||||||
src.reply(
|
src.reply(
|
||||||
RTextList(
|
RTextList(
|
||||||
@@ -106,7 +108,7 @@ def do_calc(server: PluginServerInterface, src: CommandSource, context: dict) ->
|
|||||||
def register(server: PluginServerInterface) -> None:
|
def register(server: PluginServerInterface) -> None:
|
||||||
builder = SimpleCommandBuilder()
|
builder = SimpleCommandBuilder()
|
||||||
builder.command("!!c", lambda src: src.reply(RText(tr("calc_usage"), RColor.yellow)))
|
builder.command("!!c", lambda src: src.reply(RText(tr("calc_usage"), RColor.yellow)))
|
||||||
builder.command("!!c <expression>", do_calc)
|
builder.command("!!c <expression>", lambda src, ctx: do_calc(server, src, ctx))
|
||||||
builder.arg("expression", GreedyText)
|
builder.arg("expression", GreedyText)
|
||||||
builder.register(server)
|
builder.register(server)
|
||||||
server.register_help_message("!!c <expression>", tr("calc_help"))
|
server.register_help_message("!!c <expression>", tr("calc_help"))
|
||||||
+102
-1
@@ -1,4 +1,7 @@
|
|||||||
from typing import List
|
import json
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
from mcdreforged.api.all import *
|
from mcdreforged.api.all import *
|
||||||
|
|
||||||
@@ -39,6 +42,51 @@ class Config(Serializable):
|
|||||||
|
|
||||||
CONFIG_FILE = "config/iridium.json"
|
CONFIG_FILE = "config/iridium.json"
|
||||||
|
|
||||||
|
# 首次生成时写入带注释的 JSON(MCDR 本身不写注释)
|
||||||
|
DEFAULT_CONFIG_TEXT = """{
|
||||||
|
// 使用 !!share / !!hat / !!head / !!c 所需的最低权限等级
|
||||||
|
// 0=控制台 1=普通玩家 2=OP/管理员
|
||||||
|
"permission": 1,
|
||||||
|
|
||||||
|
// !!head 冷却时间(秒),0 表示不限制
|
||||||
|
"head_cooldown_seconds": 60,
|
||||||
|
|
||||||
|
// !!hat 冷却时间(秒),0 表示不限制
|
||||||
|
"hat_cooldown_seconds": 3,
|
||||||
|
|
||||||
|
// !!share 是否播放提示音
|
||||||
|
"share_sound": true,
|
||||||
|
|
||||||
|
// 强制指定 Minecraft 版本(如 "1.12.2"、"1.20.1")
|
||||||
|
// 留空则自动检测;检测失败时可手动填写
|
||||||
|
"force_version": "",
|
||||||
|
|
||||||
|
// 玩家进服时是否提示可用命令
|
||||||
|
"join_tip": true,
|
||||||
|
|
||||||
|
// 进服消息延迟(秒),0 为立即发送
|
||||||
|
"join_tip_delay_seconds": 1.5,
|
||||||
|
|
||||||
|
// 是否发送进服 MOTD(开服天数 + 自定义文案)
|
||||||
|
"motd_enabled": true,
|
||||||
|
|
||||||
|
// 开服日期,格式 YYYY-MM-DD(当天算第 1 天)
|
||||||
|
// 留空则不显示开服天数
|
||||||
|
"motd_start_day": "",
|
||||||
|
|
||||||
|
// MOTD 文本行
|
||||||
|
// 占位符: {player} 玩家名 {days} 开服天数 {online} 在线人数
|
||||||
|
// 链接: {link:显示文字|https://url} 或 {link:https://url}
|
||||||
|
// 颜色: 支持原版 § 颜色代码
|
||||||
|
"motd_lines": [
|
||||||
|
"§6欢迎 §e{player}§6 加入服务器!",
|
||||||
|
"§7服务器已开服 §b{days}§7 天",
|
||||||
|
"§7官网: {link:§b点击打开官网|https://www.skymirror.top}",
|
||||||
|
"§7QQ群: §f985402607"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
# 模块级单例;on_load 时原地更新字段,避免各模块持有过期引用
|
# 模块级单例;on_load 时原地更新字段,避免各模块持有过期引用
|
||||||
config = Config()
|
config = Config()
|
||||||
|
|
||||||
@@ -54,3 +102,56 @@ def apply_config(new_cfg: Config) -> None:
|
|||||||
config.motd_enabled = new_cfg.motd_enabled
|
config.motd_enabled = new_cfg.motd_enabled
|
||||||
config.motd_start_day = new_cfg.motd_start_day
|
config.motd_start_day = new_cfg.motd_start_day
|
||||||
config.motd_lines = list(new_cfg.motd_lines)
|
config.motd_lines = list(new_cfg.motd_lines)
|
||||||
|
|
||||||
|
|
||||||
|
def _strip_json_comments(text: str) -> str:
|
||||||
|
"""Remove // line comments outside of strings."""
|
||||||
|
out = []
|
||||||
|
i = 0
|
||||||
|
n = len(text)
|
||||||
|
in_string = False
|
||||||
|
while i < n:
|
||||||
|
c = text[i]
|
||||||
|
if in_string:
|
||||||
|
out.append(c)
|
||||||
|
if c == "\\" and i + 1 < n:
|
||||||
|
out.append(text[i + 1])
|
||||||
|
i += 2
|
||||||
|
continue
|
||||||
|
if c == '"':
|
||||||
|
in_string = False
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
if c == '"':
|
||||||
|
in_string = True
|
||||||
|
out.append(c)
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
if c == "/" and i + 1 < n and text[i + 1] == "/":
|
||||||
|
while i < n and text[i] != "\n":
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
out.append(c)
|
||||||
|
i += 1
|
||||||
|
return "".join(out)
|
||||||
|
|
||||||
|
|
||||||
|
def _config_path(server: PluginServerInterface) -> Path:
|
||||||
|
wd = Path(server.get_mcdr_config()["working_directory"])
|
||||||
|
return wd / CONFIG_FILE
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(server: PluginServerInterface) -> Config:
|
||||||
|
"""Load config/iridium.json; create a commented default on first run."""
|
||||||
|
path = _config_path(server)
|
||||||
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
if not path.exists():
|
||||||
|
path.write_text(DEFAULT_CONFIG_TEXT, encoding="utf-8")
|
||||||
|
server.logger.info(f"已生成配置文件: {CONFIG_FILE}")
|
||||||
|
raw = path.read_text(encoding="utf-8")
|
||||||
|
try:
|
||||||
|
data = json.loads(_strip_json_comments(raw))
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
server.logger.error(f"配置文件 JSON 解析失败,使用默认值: {e}")
|
||||||
|
return Config()
|
||||||
|
return Config.deserialize(data)
|
||||||
+44
-31
@@ -258,52 +258,64 @@ def _extract_item_payload(payload: str, version: Version) -> Optional[str]:
|
|||||||
|
|
||||||
|
|
||||||
def _do_swap(server: PluginServerInterface, src: CommandSource, player: str, version: Version) -> bool:
|
def _do_swap(server: PluginServerInterface, src: CommandSource, player: str, version: Version) -> bool:
|
||||||
if not is_at_least(version, "1.13"):
|
name = sanitize_name(player)
|
||||||
# Single entitydata dump contains both SelectedItem and head Inventory slot
|
head_slot = _head_slot(version)
|
||||||
dump = rcon_query(server, _entitydata_query(player))
|
hand_slot = _hand_slot(version, 0)
|
||||||
if dump is None:
|
|
||||||
src.reply(RText(tr("hat_query_failed"), RColor.red))
|
# 1.17+: true swap via offhand buffer — no need to rebuild item NBT
|
||||||
return False
|
if is_at_least(version, "1.17"):
|
||||||
hotbar_index = _extract_selected_slot(dump)
|
|
||||||
hand = _extract_item_payload(dump, version)
|
|
||||||
if hand is None or _is_air(hand):
|
|
||||||
src.reply(RText(tr("hand_is_empty"), RColor.red))
|
|
||||||
return False
|
|
||||||
head = _extract_head_item(dump, version)
|
|
||||||
else:
|
|
||||||
hand_raw = rcon_query(server, _selected_query(player, version))
|
hand_raw = rcon_query(server, _selected_query(player, version))
|
||||||
if hand_raw is None:
|
if hand_raw is None:
|
||||||
src.reply(RText(tr("hat_query_failed"), RColor.red))
|
src.reply(RText(tr("hat_query_failed"), RColor.red))
|
||||||
return False
|
return False
|
||||||
hotbar_index = 0
|
|
||||||
hand = _extract_item_payload(hand_raw, version)
|
hand = _extract_item_payload(hand_raw, version)
|
||||||
if hand is None or _is_air(hand):
|
if hand is None or _is_air(hand):
|
||||||
src.reply(RText(tr("hand_is_empty"), RColor.red))
|
src.reply(RText(tr("hand_is_empty"), RColor.red))
|
||||||
return False
|
return False
|
||||||
head = None
|
|
||||||
head_raw = rcon_query(server, _head_query(player, version))
|
|
||||||
if head_raw is not None:
|
|
||||||
head = _extract_head_item(head_raw, version)
|
|
||||||
|
|
||||||
head_slot = _head_slot(version)
|
off_raw = rcon_query(server, f"data get entity {name} weapon.offhand")
|
||||||
hand_slot = _hand_slot(version, hotbar_index)
|
off = None
|
||||||
name = sanitize_name(player)
|
if off_raw is not None:
|
||||||
|
off = _extract_item_payload(off_raw, version)
|
||||||
|
if off and not _is_air(off):
|
||||||
|
src.reply(RText(tr("hat_offhand_busy"), RColor.red))
|
||||||
|
return False
|
||||||
|
|
||||||
if is_at_least(version, "1.17"):
|
# 1) save head -> offhand 2) hand -> head 3) offhand -> hand 4) clear offhand
|
||||||
|
safe_execute(
|
||||||
|
server,
|
||||||
|
f"item replace entity {name} weapon.offhand from entity {name} {head_slot}",
|
||||||
|
)
|
||||||
safe_execute(
|
safe_execute(
|
||||||
server,
|
server,
|
||||||
f"item replace entity {name} {head_slot} from entity {name} weapon.mainhand",
|
f"item replace entity {name} {head_slot} from entity {name} weapon.mainhand",
|
||||||
)
|
)
|
||||||
if head and not _is_air(head):
|
safe_execute(
|
||||||
safe_execute(server, _replace_with(player, hand_slot, head, version))
|
server,
|
||||||
else:
|
f"item replace entity {name} weapon.mainhand from entity {name} weapon.offhand",
|
||||||
safe_execute(server, f"item replace entity {name} {hand_slot} with air")
|
)
|
||||||
|
safe_execute(server, f"item replace entity {name} weapon.offhand with air")
|
||||||
|
src.reply(RText(tr("hat_success"), RColor.green))
|
||||||
|
return True
|
||||||
|
|
||||||
|
# 1.8–1.16: rebuild via parsed SNBT
|
||||||
|
dump = rcon_query(server, _entitydata_query(player))
|
||||||
|
if dump is None:
|
||||||
|
src.reply(RText(tr("hat_query_failed"), RColor.red))
|
||||||
|
return False
|
||||||
|
hotbar_index = _extract_selected_slot(dump)
|
||||||
|
hand_slot = _hand_slot(version, hotbar_index)
|
||||||
|
hand = _extract_item_payload(dump, version)
|
||||||
|
if hand is None or _is_air(hand):
|
||||||
|
src.reply(RText(tr("hand_is_empty"), RColor.red))
|
||||||
|
return False
|
||||||
|
head = _extract_head_item(dump, version)
|
||||||
|
|
||||||
|
safe_execute(server, _replace_with(player, head_slot, hand, version))
|
||||||
|
if head and not _is_air(head):
|
||||||
|
safe_execute(server, _replace_with(player, hand_slot, head, version))
|
||||||
else:
|
else:
|
||||||
safe_execute(server, _replace_with(player, head_slot, hand, version))
|
safe_execute(server, _replace_with(player, hand_slot, "minecraft:air", version))
|
||||||
if head and not _is_air(head):
|
|
||||||
safe_execute(server, _replace_with(player, hand_slot, head, version))
|
|
||||||
else:
|
|
||||||
safe_execute(server, _replace_with(player, hand_slot, "minecraft:air", version))
|
|
||||||
|
|
||||||
src.reply(RText(tr("hat_success"), RColor.green))
|
src.reply(RText(tr("hat_success"), RColor.green))
|
||||||
return True
|
return True
|
||||||
@@ -329,6 +341,7 @@ def do_hat(server: PluginServerInterface, src: CommandSource) -> None:
|
|||||||
|
|
||||||
if _do_swap(server, src, player, version):
|
if _do_swap(server, src, player, version):
|
||||||
mark_cooldown(player, "hat")
|
mark_cooldown(player, "hat")
|
||||||
|
server.logger.info(f"[Iridium] !!hat: {player} swapped hand/head gear")
|
||||||
|
|
||||||
|
|
||||||
def register(server: PluginServerInterface) -> None:
|
def register(server: PluginServerInterface) -> None:
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ def do_head(server: PluginServerInterface, src: CommandSource, context: dict) ->
|
|||||||
|
|
||||||
safe_execute(server, _give_head_command(player, safe_target, version))
|
safe_execute(server, _give_head_command(player, safe_target, version))
|
||||||
mark_cooldown(player, "head")
|
mark_cooldown(player, "head")
|
||||||
|
server.logger.info(f"[Iridium] !!head: {player} -> head of {safe_target}")
|
||||||
src.reply(RText(tr("head_success", safe_target), RColor.green))
|
src.reply(RText(tr("head_success", safe_target), RColor.green))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -239,4 +239,5 @@ def on_player_joined(server: PluginServerInterface, player: str, info: Info) ->
|
|||||||
|
|
||||||
|
|
||||||
def register(server: PluginServerInterface) -> None:
|
def register(server: PluginServerInterface) -> None:
|
||||||
server.register_event_listener(MCDRPluginEvents.PLAYER_JOIN, on_player_joined)
|
# MCDR event name is PLAYER_JOINED (not PLAYER_JOIN)
|
||||||
|
server.register_event_listener(MCDRPluginEvents.PLAYER_JOINED, on_player_joined)
|
||||||
+80
-35
@@ -44,10 +44,15 @@ def _query_command(player: str, version: Version) -> str:
|
|||||||
return f"entitydata {name} {{}}"
|
return f"entitydata {name} {{}}"
|
||||||
|
|
||||||
|
|
||||||
def _sound_command(version: Version) -> str:
|
def _sound_command(player: str, version: Version) -> str:
|
||||||
|
name = sanitize_name(player)
|
||||||
|
# Play at the player so @a nearby can hear; default command origin is often too far
|
||||||
if is_at_least(version, "1.9"):
|
if is_at_least(version, "1.9"):
|
||||||
return "playsound minecraft:entity.arrow.hit_player master @a"
|
return (
|
||||||
return "playsound random.successful_hit @a"
|
f"execute at {name} run playsound minecraft:entity.arrow.hit_player "
|
||||||
|
f"master @a ~ ~ ~ 64 1"
|
||||||
|
)
|
||||||
|
return f"execute at {name} run playsound random.successful_hit @a ~ ~ ~ 64 1"
|
||||||
|
|
||||||
|
|
||||||
def _is_air(snbt: Optional[str]) -> bool:
|
def _is_air(snbt: Optional[str]) -> bool:
|
||||||
@@ -63,46 +68,82 @@ def _json_str(value: str) -> str:
|
|||||||
return json.dumps(value, ensure_ascii=False)[1:-1]
|
return json.dumps(value, ensure_ascii=False)[1:-1]
|
||||||
|
|
||||||
|
|
||||||
|
def _item_id(item_snbt: str) -> str:
|
||||||
|
m = re.search(r'id\s*:\s*"([^"]+)"', item_snbt)
|
||||||
|
return m.group(1) if m else "?"
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_custom_name(item_snbt: str) -> Optional[str]:
|
||||||
|
"""Only names stored in NBT (player rename / anvil). Registry names are not here."""
|
||||||
|
m = re.search(r'"text"\s*:\s*"([^"]+)"', item_snbt)
|
||||||
|
if m and m.group(1).strip():
|
||||||
|
return _strip_mc_codes(m.group(1).strip())
|
||||||
|
m = re.search(r'["\']?(?:Name|custom_name)["\']?\s*:\s*"([^"]+)"', item_snbt)
|
||||||
|
if m and m.group(1).strip():
|
||||||
|
return _strip_mc_codes(m.group(1).strip())
|
||||||
|
m = re.search(r"['\"]?(?:Name|custom_name)['\"]?\s*:\s*'([^']+)'", item_snbt)
|
||||||
|
if m and m.group(1).strip():
|
||||||
|
return _strip_mc_codes(m.group(1).strip())
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _humanize_id(item_id: str) -> str:
|
||||||
|
"""kubejs:time_twister_wireless -> Time Twister Wireless"""
|
||||||
|
path = item_id.split(":", 1)[-1]
|
||||||
|
parts = [p for p in path.replace("-", "_").split("_") if p]
|
||||||
|
if not parts:
|
||||||
|
return item_id
|
||||||
|
return " ".join(p[:1].upper() + p[1:] for p in parts)
|
||||||
|
|
||||||
|
|
||||||
|
def _translate_key(item_id: str) -> str:
|
||||||
|
"""Guess client language key from item id (best-effort)."""
|
||||||
|
if ":" not in item_id:
|
||||||
|
return f"item.minecraft.{item_id}"
|
||||||
|
ns, path = item_id.split(":", 1)
|
||||||
|
if ns == "minecraft":
|
||||||
|
return f"item.minecraft.{path}"
|
||||||
|
return f"item.{ns}.{path}"
|
||||||
|
|
||||||
|
|
||||||
|
def _display_json(item_snbt: str) -> str:
|
||||||
|
"""JSON text component: custom name if any, else client translate + humanized fallback."""
|
||||||
|
custom = _extract_custom_name(item_snbt)
|
||||||
|
if custom:
|
||||||
|
return '{"text":"' + _json_str(custom) + '"}'
|
||||||
|
item_id = _item_id(item_snbt)
|
||||||
|
key = _translate_key(item_id)
|
||||||
|
pretty = _humanize_id(item_id)
|
||||||
|
return (
|
||||||
|
'{"translate":"' + _json_str(key) + '","fallback":"' + _json_str(pretty) + '"}'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _strip_mc_codes(text: str) -> str:
|
||||||
|
return re.sub(r"§[0-9a-fk-orA-FK-OR]", "", text)
|
||||||
|
|
||||||
|
|
||||||
def _build_tellraw(player: str, item_snbt: str, version: Version) -> str:
|
def _build_tellraw(player: str, item_snbt: str, version: Version) -> str:
|
||||||
# Truncate pathological NBT (huge books etc.) so the command stays valid
|
# Truncate pathological NBT (huge books etc.) so the command stays valid
|
||||||
if len(item_snbt) > MAX_SNBT_LEN:
|
if len(item_snbt) > MAX_SNBT_LEN:
|
||||||
item_snbt = item_snbt[:MAX_SNBT_LEN] + "..."
|
item_snbt = item_snbt[:MAX_SNBT_LEN] + "..."
|
||||||
snbt = _json_str(item_snbt)
|
|
||||||
player_js = _json_str(sanitize_name(player) or player)
|
|
||||||
|
|
||||||
if is_at_least(version, "1.21.5"):
|
if is_at_least(version, "1.21.5"):
|
||||||
hover = '{"action":"show_item","contents":"' + snbt + '"}'
|
hover = {"action": "show_item", "contents": item_snbt}
|
||||||
else:
|
else:
|
||||||
hover = '{"action":"show_item","value":"' + snbt + '"}'
|
hover = {"action": "show_item", "value": item_snbt}
|
||||||
|
|
||||||
if is_at_least(version, "1.16"):
|
display = json.loads(_display_json(item_snbt))
|
||||||
click = '{"action":"copy_to_clipboard","value":"' + snbt + '"}'
|
display["color"] = "aqua"
|
||||||
click_label = _json_str(tr("click_copy"))
|
display["hoverEvent"] = hover
|
||||||
else:
|
|
||||||
# pre-1.16 has no copy_to_clipboard; suggest the version-appropriate query cmd
|
|
||||||
safe_player = sanitize_name(player)
|
|
||||||
if is_at_least(version, "1.13"):
|
|
||||||
suggest = f"/data get entity {safe_player} SelectedItem"
|
|
||||||
else:
|
|
||||||
suggest = f"/entitydata {safe_player} {{}}"
|
|
||||||
click = '{"action":"suggest_command","value":"' + _json_str(suggest) + '"}'
|
|
||||||
click_label = _json_str(tr("click_suggest"))
|
|
||||||
|
|
||||||
id_match = re.search(r'id\s*:\s*"([^"]+)"', item_snbt)
|
payload = [
|
||||||
item_id = id_match.group(1) if id_match else "?"
|
{"text": "[Iridium] ", "color": "gray"},
|
||||||
name_match = re.search(r'"text"\s*:\s*"([^"]+)"', item_snbt)
|
{"text": sanitize_name(player) or player, "color": "yellow"},
|
||||||
display = name_match.group(1) if name_match else item_id
|
{"text": f" {tr('share_showing')} "},
|
||||||
display_js = _json_str(display)
|
display,
|
||||||
|
]
|
||||||
json_text = (
|
return "tellraw @a " + json.dumps(payload, ensure_ascii=False, separators=(",", ":"))
|
||||||
'[{"text":"[Iridium] ","color":"gray"},'
|
|
||||||
'{"text":"' + player_js + '","color":"yellow"},'
|
|
||||||
'{"text":" ' + _json_str(tr("share_showing")) + ' "},'
|
|
||||||
'{"text":"' + display_js + '","color":"aqua","hoverEvent":' + hover + "},"
|
|
||||||
'{"text":" [' + click_label + ']","color":"aqua","bold":true,'
|
|
||||||
'"underlined":true,"hoverEvent":' + hover + ',"clickEvent":' + click + "}]"
|
|
||||||
)
|
|
||||||
return f"tellraw @a {json_text}"
|
|
||||||
|
|
||||||
|
|
||||||
def _send_share(
|
def _send_share(
|
||||||
@@ -117,7 +158,11 @@ def _send_share(
|
|||||||
return False
|
return False
|
||||||
safe_execute(server, _build_tellraw(player, item_snbt, version))
|
safe_execute(server, _build_tellraw(player, item_snbt, version))
|
||||||
if config.share_sound:
|
if config.share_sound:
|
||||||
safe_execute(server, _sound_command(version))
|
safe_execute(server, _sound_command(player, version))
|
||||||
|
server.logger.info(
|
||||||
|
f"[Iridium] !!share: {player} shared item id={_item_id(item_snbt)} "
|
||||||
|
f"({len(item_snbt)} chars)"
|
||||||
|
)
|
||||||
src.reply(RText(tr("share_done"), RColor.green))
|
src.reply(RText(tr("share_done"), RColor.green))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
+23
-8
@@ -26,17 +26,28 @@ def tr(key: str, *args) -> str:
|
|||||||
return si.tr(f"iridium.{key}", *args)
|
return si.tr(f"iridium.{key}", *args)
|
||||||
|
|
||||||
|
|
||||||
|
def _as_version(value) -> Optional[Version]:
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
if isinstance(value, Version):
|
||||||
|
return value
|
||||||
|
try:
|
||||||
|
return Version(str(value))
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_mc_version(server: PluginServerInterface) -> Optional[Version]:
|
def get_mc_version(server: PluginServerInterface) -> Optional[Version]:
|
||||||
"""Return the detected Minecraft server version, or None."""
|
"""Return the detected Minecraft server version, or None."""
|
||||||
if config.force_version:
|
if config.force_version:
|
||||||
try:
|
forced = _as_version(config.force_version)
|
||||||
return Version(config.force_version)
|
if forced is not None:
|
||||||
except Exception:
|
return forced
|
||||||
server.logger.warning(tr("bad_force_version", config.force_version))
|
server.logger.warning(tr("bad_force_version", config.force_version))
|
||||||
info = server.get_server_information()
|
info = server.get_server_information()
|
||||||
if info is None or info.version is None:
|
if info is None:
|
||||||
return None
|
return None
|
||||||
return info.version
|
return _as_version(info.version)
|
||||||
|
|
||||||
|
|
||||||
def require_version(server: PluginServerInterface, src: CommandSource) -> Optional[Version]:
|
def require_version(server: PluginServerInterface, src: CommandSource) -> Optional[Version]:
|
||||||
@@ -46,5 +57,9 @@ def require_version(server: PluginServerInterface, src: CommandSource) -> Option
|
|||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
def is_at_least(version: Version, target: str) -> bool:
|
def is_at_least(version, target: str) -> bool:
|
||||||
return version >= Version(target)
|
left = _as_version(version)
|
||||||
|
right = _as_version(target)
|
||||||
|
if left is None or right is None:
|
||||||
|
return False
|
||||||
|
return left >= right
|
||||||
+33
-32
@@ -1,32 +1,33 @@
|
|||||||
iridium.loaded: Iridium loaded
|
iridium.loaded: 'Iridium loaded'
|
||||||
iridium.unloaded: Iridium unloaded
|
iridium.unloaded: 'Iridium unloaded'
|
||||||
iridium.version_mode: Version detection mode: {0}
|
iridium.version_mode: 'Version detection mode: {0}'
|
||||||
iridium.bad_force_version: Invalid force_version in config: {0}
|
iridium.bad_force_version: 'Invalid force_version in config: {0}'
|
||||||
iridium.version_unknown: Unable to detect Minecraft version. Wait for VersionDetector, or set force_version in config
|
iridium.version_unknown: 'Unable to detect Minecraft version. Wait for VersionDetector, or set force_version in config'
|
||||||
iridium.player_only: This command can only be used by a player in-game
|
iridium.player_only: 'This command can only be used by a player in-game'
|
||||||
iridium.required_permission: Insufficient permission, requires level {0}
|
iridium.required_permission: 'Insufficient permission, requires level {0}'
|
||||||
iridium.on_cooldown: Cooldown, wait {0}s
|
iridium.on_cooldown: 'Cooldown, wait {0}s'
|
||||||
iridium.hand_is_empty: No usable item in hand
|
iridium.hand_is_empty: 'No usable item in hand'
|
||||||
iridium.share_help: Show the item in your main hand (hover to view)
|
iridium.share_help: 'Show the item in your main hand (hover to view)'
|
||||||
iridium.share_done: Item shared to chat
|
iridium.share_done: 'Item shared to chat'
|
||||||
iridium.share_unsupported_version: Version {0} cannot read held item (needs Minecraft 1.8+)
|
iridium.share_unsupported_version: 'Version {0} cannot read held item (needs Minecraft 1.8+)'
|
||||||
iridium.share_timeout: Timed out reading held item, try again later
|
iridium.share_timeout: 'Timed out reading held item, try again later'
|
||||||
iridium.click_copy: click to copy data
|
iridium.click_copy: 'click to copy data'
|
||||||
iridium.click_suggest: click for data command
|
iridium.click_suggest: 'click for data command'
|
||||||
iridium.share_showing: is showing
|
iridium.share_showing: 'is showing'
|
||||||
iridium.hat_help: Swap the item in your hand with your head slot
|
iridium.hat_help: 'Swap the item in your hand with your head slot'
|
||||||
iridium.hat_success: Swapped hand item with head equipment
|
iridium.hat_success: 'Swapped hand item with head equipment'
|
||||||
iridium.hat_unsupported_version: Version {0} does not support !!hat (needs Minecraft 1.8+)
|
iridium.hat_unsupported_version: 'Version {0} does not support !!hat (needs Minecraft 1.8+)'
|
||||||
iridium.hat_need_rcon: !!hat requires RCON enabled to read and swap item data
|
iridium.hat_need_rcon: '!!hat requires RCON enabled to read and swap item data'
|
||||||
iridium.hat_query_failed: Failed to query player item data
|
iridium.hat_query_failed: 'Failed to query player item data'
|
||||||
iridium.head_help: Get one player head (optional player name, cooldown {0}s)
|
iridium.hat_offhand_busy: 'Off-hand is occupied; clear it before using !!hat'
|
||||||
iridium.head_help_short: Get one player head (optional player name)
|
iridium.head_help: 'Get one player head (optional player name, cooldown {0}s)'
|
||||||
iridium.head_success: You received a head of {0}
|
iridium.head_help_short: 'Get one player head (optional player name)'
|
||||||
iridium.calc_help: Evaluate an expression, e.g. !!c 1+2*(3-1)
|
iridium.head_success: 'You received a head of {0}'
|
||||||
iridium.calc_usage: Usage: !!c <expression>, e.g. !!c 1+2*(3-1)
|
iridium.calc_help: 'Evaluate an expression, e.g. !!c 1+2*(3-1)'
|
||||||
iridium.calc_error: Cannot calculate {0}: {1}
|
iridium.calc_usage: 'Usage: !!c <expression>, e.g. !!c 1+2*(3-1)'
|
||||||
iridium.calc_div_zero: Division by zero
|
iridium.calc_error: 'Cannot calculate {0}: {1}'
|
||||||
iridium.join_tip_header: Iridium is enabled. Available commands: (click to fill chat)
|
iridium.calc_div_zero: 'Division by zero'
|
||||||
iridium.join_tip_click: click to fill chat
|
iridium.join_tip_header: 'Iridium is enabled. Available commands: (click to fill chat)'
|
||||||
iridium.motd_header: Server Info
|
iridium.join_tip_click: 'click to fill chat'
|
||||||
iridium.motd_days: Day {0} since server start
|
iridium.motd_header: 'Server Info'
|
||||||
|
iridium.motd_days: 'Day {0} since server start'
|
||||||
+33
-32
@@ -1,32 +1,33 @@
|
|||||||
iridium.loaded: Iridium 已加载
|
iridium.loaded: 'Iridium 已加载'
|
||||||
iridium.unloaded: Iridium 已卸载
|
iridium.unloaded: 'Iridium 已卸载'
|
||||||
iridium.version_mode: 版本检测模式: {0}
|
iridium.version_mode: '版本检测模式: {0}'
|
||||||
iridium.bad_force_version: 配置 force_version 无效: {0}
|
iridium.bad_force_version: '配置 force_version 无效: {0}'
|
||||||
iridium.version_unknown: 无法检测 Minecraft 版本,请等待服务器完成 VersionDetector,或在配置中设置 force_version
|
iridium.version_unknown: '无法检测 Minecraft 版本,请等待服务器完成 VersionDetector,或在配置中设置 force_version'
|
||||||
iridium.player_only: 该命令只能由玩家在游戏内使用
|
iridium.player_only: '该命令只能由玩家在游戏内使用'
|
||||||
iridium.required_permission: 权限不足,需要权限等级 {0}
|
iridium.required_permission: '权限不足,需要权限等级 {0}'
|
||||||
iridium.on_cooldown: 冷却中,请再等待 {0} 秒
|
iridium.on_cooldown: '冷却中,请再等待 {0} 秒'
|
||||||
iridium.hand_is_empty: 手上没有可处理的物品
|
iridium.hand_is_empty: '手上没有可处理的物品'
|
||||||
iridium.share_help: 展示手上物品的完整信息(悬停查看)
|
iridium.share_help: '展示手上物品的完整信息(悬停查看)'
|
||||||
iridium.share_done: 已在聊天栏展示物品
|
iridium.share_done: '已在聊天栏展示物品'
|
||||||
iridium.share_unsupported_version: 当前版本 {0} 无法读取手持物品(需要 Minecraft 1.8+)
|
iridium.share_unsupported_version: '当前版本 {0} 无法读取手持物品(需要 Minecraft 1.8+)'
|
||||||
iridium.share_timeout: 读取手持物品超时,请稍后再试
|
iridium.share_timeout: '读取手持物品超时,请稍后再试'
|
||||||
iridium.click_copy: 点击复制完整数据
|
iridium.click_copy: '点击复制完整数据'
|
||||||
iridium.click_suggest: 点击获取完整数据命令
|
iridium.click_suggest: '点击获取完整数据命令'
|
||||||
iridium.share_showing: 正在展示
|
iridium.share_showing: '正在展示'
|
||||||
iridium.hat_help: 将手上物品与头部装备互换
|
iridium.hat_help: '将手上物品与头部装备互换'
|
||||||
iridium.hat_success: 已交换手上物品与头部装备
|
iridium.hat_success: '已交换手上物品与头部装备'
|
||||||
iridium.hat_unsupported_version: 当前版本 {0} 不支持 !!hat(需要 Minecraft 1.8+)
|
iridium.hat_unsupported_version: '当前版本 {0} 不支持 !!hat(需要 Minecraft 1.8+)'
|
||||||
iridium.hat_need_rcon: !!hat 需要启用 RCON 才能读取并交换物品数据
|
iridium.hat_need_rcon: '!!hat 需要启用 RCON 才能读取并交换物品数据'
|
||||||
iridium.hat_query_failed: 读取玩家物品数据失败
|
iridium.hat_query_failed: '读取玩家物品数据失败'
|
||||||
iridium.head_help: 获取一个玩家头颅(可指定玩家名,冷却 {0} 秒)
|
iridium.hat_offhand_busy: '副手有物品,无法安全交换;请先清空副手再使用 !!hat'
|
||||||
iridium.head_help_short: 获取一个玩家头颅(可指定玩家名)
|
iridium.head_help: '获取一个玩家头颅(可指定玩家名,冷却 {0} 秒)'
|
||||||
iridium.head_success: 已给予你 {0} 的头颅
|
iridium.head_help_short: '获取一个玩家头颅(可指定玩家名)'
|
||||||
iridium.calc_help: 计算表达式,例如 !!c 1+2*(3-1)
|
iridium.head_success: '已给予你 {0} 的头颅'
|
||||||
iridium.calc_usage: 用法: !!c <表达式>,例如 !!c 1+2*(3-1)
|
iridium.calc_help: '计算表达式,例如 !!c 1+2*(3-1)'
|
||||||
iridium.calc_error: 无法计算 {0}: {1}
|
iridium.calc_usage: '用法: !!c <表达式>,例如 !!c 1+2*(3-1)'
|
||||||
iridium.calc_div_zero: 除数不能为 0
|
iridium.calc_error: '无法计算 {0}: {1}'
|
||||||
iridium.join_tip_header: 本服已启用 Iridium,可用命令:(点击命令可填入聊天框)
|
iridium.calc_div_zero: '除数不能为 0'
|
||||||
iridium.join_tip_click: 点击填入聊天栏
|
iridium.join_tip_header: '本服已启用 Iridium,可用命令:(点击命令可填入聊天框)'
|
||||||
iridium.motd_header: 服务器信息
|
iridium.join_tip_click: '点击填入聊天栏'
|
||||||
iridium.motd_days: 开服第 {0} 天
|
iridium.motd_header: '服务器信息'
|
||||||
|
iridium.motd_days: '开服第 {0} 天'
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"id": "iridium",
|
"id": "iridium",
|
||||||
"version": "26.9.1",
|
"version": "26.9.13",
|
||||||
"name": "Iridium",
|
"name": "Iridium",
|
||||||
"description": {
|
"description": {
|
||||||
"zh_cn": "物品展示 / 戴头 / 获取头颅 / 游戏内计算器 / 进服 MOTD",
|
"zh_cn": "物品展示 / 戴头 / 获取头颅 / 游戏内计算器 / 进服 MOTD",
|
||||||
|
|||||||
@@ -227,6 +227,18 @@ def test_sanitize_name_and_cmd():
|
|||||||
assert sanitize_cmd("a\r\nb") == "a b"
|
assert sanitize_cmd("a\r\nb") == "a b"
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_at_least_accepts_str():
|
||||||
|
from mcdreforged.api.all import Version
|
||||||
|
|
||||||
|
from iridium.version_util import is_at_least
|
||||||
|
|
||||||
|
assert is_at_least(Version("1.20.1"), "1.8") is True
|
||||||
|
assert is_at_least("1.20.1", "1.8") is True
|
||||||
|
assert is_at_least("1.7.10", "1.13") is False
|
||||||
|
assert is_at_least("1.12.2", "1.13") is False
|
||||||
|
assert is_at_least("not-a-version", "1.8") is False
|
||||||
|
|
||||||
|
|
||||||
def test_share_query_sanitizes_player():
|
def test_share_query_sanitizes_player():
|
||||||
from mcdreforged.api.all import Version
|
from mcdreforged.api.all import Version
|
||||||
|
|
||||||
@@ -239,6 +251,34 @@ def test_share_query_sanitizes_player():
|
|||||||
assert "Badname" in tr
|
assert "Badname" in tr
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_display_name():
|
||||||
|
from iridium.share import _display_json, _humanize_id, _item_id, _translate_key
|
||||||
|
|
||||||
|
assert _item_id('{id:"minecraft:stone",Count:1b}') == "minecraft:stone"
|
||||||
|
assert _translate_key("minecraft:diamond") == "item.minecraft.diamond"
|
||||||
|
assert _translate_key("kubejs:time_twister_wireless") == "item.kubejs.time_twister_wireless"
|
||||||
|
assert _humanize_id("kubejs:time_twister_wireless") == "Time Twister Wireless"
|
||||||
|
assert _humanize_id("minecraft:fluix_covered_cable") == "Fluix Covered Cable"
|
||||||
|
assert '"text"' in _display_json('{id:"minecraft:diamond",tag:{display:{Name:"Shiny"}}}')
|
||||||
|
disp = _display_json('{id:"kubejs:time_twister_wireless",Count:1b}')
|
||||||
|
assert '"translate"' in disp
|
||||||
|
assert "Time Twister Wireless" in disp
|
||||||
|
assert "fallback" in disp
|
||||||
|
assert "kubejs:time_twister_wireless" not in disp
|
||||||
|
|
||||||
|
|
||||||
|
def test_strip_json_comments():
|
||||||
|
import json
|
||||||
|
|
||||||
|
from iridium.config import DEFAULT_CONFIG_TEXT, _strip_json_comments
|
||||||
|
|
||||||
|
parsed = json.loads(_strip_json_comments(DEFAULT_CONFIG_TEXT))
|
||||||
|
assert parsed["permission"] == 1
|
||||||
|
assert "skymirror.top" in parsed["motd_lines"][2]
|
||||||
|
# comment-looking text inside string is kept
|
||||||
|
assert json.loads(_strip_json_comments('{"a": "http://x"}'))["a"] == "http://x"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_") and callable(v)]
|
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_") and callable(v)]
|
||||||
failed = 0
|
failed = 0
|
||||||
|
|||||||
Reference in new issue
Block a user