release: Iridium 26.9.1
MCDR plugin: item share, hat, player head, calculator, join MOTD. All rights reserved. Author: 云镜之端/SKYMirror
This commit is contained in:
commit
d5ba9743ed
18 files changed
+1796
No files matched your search
@@ -0,0 +1,50 @@
|
||||
from typing import Optional
|
||||
|
||||
from mcdreforged.api.all import *
|
||||
|
||||
from iridium.config import config
|
||||
|
||||
# Fallback strings when ServerInterface is unavailable (unit tests / early import)
|
||||
_FALLBACK = {
|
||||
"click_copy": "click to copy data",
|
||||
"click_suggest": "click for data command",
|
||||
"calc_usage": "Usage: !!c <expression>",
|
||||
"share_showing": "is showing",
|
||||
}
|
||||
|
||||
|
||||
def tr(key: str, *args) -> str:
|
||||
si = ServerInterface.get_instance()
|
||||
if si is None:
|
||||
text = _FALLBACK.get(key, key)
|
||||
if args:
|
||||
try:
|
||||
return text.format(*args)
|
||||
except Exception:
|
||||
return text
|
||||
return text
|
||||
return si.tr(f"iridium.{key}", *args)
|
||||
|
||||
|
||||
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))
|
||||
info = server.get_server_information()
|
||||
if info is None or info.version is None:
|
||||
return None
|
||||
return info.version
|
||||
|
||||
|
||||
def require_version(server: PluginServerInterface, src: CommandSource) -> Optional[Version]:
|
||||
version = get_mc_version(server)
|
||||
if version is None:
|
||||
src.reply(RText(tr("version_unknown"), RColor.red))
|
||||
return version
|
||||
|
||||
|
||||
def is_at_least(version: Version, target: str) -> bool:
|
||||
return version >= Version(target)
|
||||
Reference in new issue
Block a user