fix: coerce Version for comparisons and bind server in !!c (26.9.3)
This commit is contained in:
1 parent
e1841c0fc9
commit
b464b5ba5e
6 files changed
+43
-10
No files matched your search
@@ -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
|
||||
|
||||
@@ -4,7 +4,7 @@ MCDReforged 插件:物品展示 / 戴头 / 获取头颅 / 游戏内计算器 /
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 版本 | **26.9.2** |
|
||||
| 版本 | **26.9.3** |
|
||||
| 作者 | 云镜之端/SKYMirror |
|
||||
| 许可 | 保留所有权益(All Rights Reserved) |
|
||||
| 前置 | MCDReforged `>= 2.6.0` |
|
||||
|
||||
@@ -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 <expression>", do_calc)
|
||||
builder.command("!!c <expression>", lambda src, ctx: do_calc(server, src, ctx))
|
||||
builder.arg("expression", GreedyText)
|
||||
builder.register(server)
|
||||
server.register_help_message("!!c <expression>", tr("calc_help"))
|
||||
+22
-7
@@ -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:
|
||||
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
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"id": "iridium",
|
||||
"version": "26.9.2",
|
||||
"version": "26.9.3",
|
||||
"name": "Iridium",
|
||||
"description": {
|
||||
"zh_cn": "物品展示 / 戴头 / 获取头颅 / 游戏内计算器 / 进服 MOTD",
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user