diff --git a/CHANGELOG.md b/CHANGELOG.md index ff2dc75..3f91843 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ 本文件记录 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 diff --git a/README.md b/README.md index 9d80d1b..06cc65b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ MCDReforged 插件:物品展示 / 戴头 / 获取头颅 / 游戏内计算器 / | | | |---|---| -| 版本 | **26.9.2** | +| 版本 | **26.9.3** | | 作者 | 云镜之端/SKYMirror | | 许可 | 保留所有权益(All Rights Reserved) | | 前置 | MCDReforged `>= 2.6.0` | diff --git a/iridium/calculator.py b/iridium/calculator.py index 5fd1e94..167b5bc 100644 --- a/iridium/calculator.py +++ b/iridium/calculator.py @@ -106,7 +106,7 @@ def do_calc(server: PluginServerInterface, src: CommandSource, context: dict) -> def register(server: PluginServerInterface) -> None: builder = SimpleCommandBuilder() builder.command("!!c", lambda src: src.reply(RText(tr("calc_usage"), RColor.yellow))) - builder.command("!!c ", do_calc) + builder.command("!!c ", lambda src, ctx: do_calc(server, src, ctx)) builder.arg("expression", GreedyText) builder.register(server) server.register_help_message("!!c ", tr("calc_help")) diff --git a/iridium/version_util.py b/iridium/version_util.py index f7d7b39..1c5eed8 100644 --- a/iridium/version_util.py +++ b/iridium/version_util.py @@ -26,17 +26,28 @@ def tr(key: str, *args) -> str: 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]: """Return the detected Minecraft server version, or None.""" if config.force_version: - try: - return Version(config.force_version) - except Exception: - server.logger.warning(tr("bad_force_version", config.force_version)) + forced = _as_version(config.force_version) + if forced is not None: + return forced + server.logger.warning(tr("bad_force_version", config.force_version)) info = server.get_server_information() - if info is None or info.version is None: + if info is None: return None - return info.version + return _as_version(info.version) def require_version(server: PluginServerInterface, src: CommandSource) -> Optional[Version]: @@ -46,5 +57,9 @@ def require_version(server: PluginServerInterface, src: CommandSource) -> Option return version -def is_at_least(version: Version, target: str) -> bool: - return version >= Version(target) +def is_at_least(version, target: str) -> bool: + left = _as_version(version) + right = _as_version(target) + if left is None or right is None: + return False + return left >= right diff --git a/mcdreforged.plugin.json b/mcdreforged.plugin.json index 9973afd..f46a735 100644 --- a/mcdreforged.plugin.json +++ b/mcdreforged.plugin.json @@ -1,6 +1,6 @@ { "id": "iridium", - "version": "26.9.2", + "version": "26.9.3", "name": "Iridium", "description": { "zh_cn": "物品展示 / 戴头 / 获取头颅 / 游戏内计算器 / 进服 MOTD", diff --git a/tests/test_pure.py b/tests/test_pure.py index 6bd28c6..a09e945 100644 --- a/tests/test_pure.py +++ b/tests/test_pure.py @@ -227,6 +227,18 @@ def test_sanitize_name_and_cmd(): 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(): from mcdreforged.api.all import Version