diff --git a/SDK-GMLIB b/SDK-GMLIB index cda5bfb..37d9220 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit cda5bfbf85a291a85a78529f760883d1ca7216da +Subproject commit 37d92200bd9a534ec6f86d8c27abf3a0af0b40f4 diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index 0201a96..535a701 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -480,6 +480,53 @@ class Experiments { } } +class Version { + constructor(major, minor, patch) { + this.mMajor = major; + this.mMinor = minor; + this.mPatch = patch; + } + + toString(prefix = true) { + let result = `${this.mMajor}.${this.mMinor}.${this.mPatch}`; + if (prefix) { + result = "v" + result; + } + return result; + } + + toArray() { + return [this.mMajor, this.mMinor, this.mPatch]; + } + + valueOf() { + return 100000000 * this.mMajor + 10000 * this.mMinor + this.mPatch; + } + + static fromString(string) { + if (typeof string === 'string' || string instanceof String) { + let pattern = /^v?\d+\.\d+\.\d+$/; + if (pattern.test(string)) { + let regex = /\d+/g; + let numbers = string.match(regex); + let array = numbers.slice(0, 3).map(Number); + return new Version(array[0], array[1], array[2]); + } + } + return null; + } + + static fromArray(array) { + if (Array.isArray(array) && array.length == 3) { + let isNumber = array.every(element => typeof element == "number"); + if (isNumber) { + return new Version(array[0], array[1], array[2]) + } + } + return null; + } +} + class GMLIB { constructor() { throw new Error("Static class cannot be instantiated"); @@ -782,5 +829,6 @@ module.exports = { Scoreboard, JsonConfig, JsonLanguage, - JsonI18n + JsonI18n, + Version }; \ No newline at end of file diff --git a/manifest.json b/manifest.json index 1f154fe..f00ab5a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "${pluginName}", "entry": "${pluginFile}", - "version": "0.9.5", + "version": "0.10.0", "author": "GroupMountain", "type": "native", "dependencies": [ diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 62413be..da9350a 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -158,8 +158,8 @@ void Export_Compatibility_API() { return false; }); RemoteCall::exportAs("GMLIB_API", "isVersionMatched", [](int a, int b, int c) -> bool { - auto version = SemVersion(a, b, c, "", ""); - return LIB_VERSION.satisfies(version); + auto version = GMLIB::Version(a, b, c, "", ""); + return version >= LIB_VERSION; }); RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); }); RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string { diff --git a/src/Global.h b/src/Global.h index 5bee402..3b86088 100644 --- a/src/Global.h +++ b/src/Global.h @@ -4,7 +4,7 @@ #include #define PLUGIN_NAME "GMLIB-LRCA" -#define LIB_VERSION SemVersion(0, 9, 4, "", "") +#define LIB_VERSION GMLIB::Version(0, 9, 4) extern ll::Logger logger; diff --git a/template/GMLIB_LRCA-Plugin-Template/GMLIB_LRCA-Plugin-Template.js b/template/GMLIB_LRCA-Plugin-Template/GMLIB_LRCA-Plugin-Template.js new file mode 100644 index 0000000..4813570 --- /dev/null +++ b/template/GMLIB_LRCA-Plugin-Template/GMLIB_LRCA-Plugin-Template.js @@ -0,0 +1,53 @@ +/** + * + * @name GMLIB_LRCA-Plugin-Template + * @brief plugin template for GMLIB-LegacyRemoteCallApi + * + * @copyright Copyright (c) 2024 GroupMountain + * GMLIB-LegacyRemoteCallApi + * + */ + +const PluginInfo = { + Name: "GMLIB_LRCA-Plugin-Template", + Author: "your name", + Version: "0.0.1" +} + +// 导入 API +const { JsonConfig, JsonI18n } = require('./GMLIB-LegacyRemoteCallApi/lib/GMLIB_API-JS'); + +// 默认配置文件 +const defaultConfig = { + "language": "zh_CN" +}; + +// 默认语言文件 +const zh_CN = { + "consolelog.loaded": "加载成功!", + "consolelog.info": "插件作者: {1}, 当前版本: v{2}" +}; + +// 初始化配置文件 +const config = new JsonConfig(`./plugins/${PluginInfo.Name}/config/config.json`, defaultConfig); + +// 初始化 I18n +const I18n = new JsonI18n(`./plugins/${PluginInfo.Name}/language/`, config.get("language")); +I18n.loadLanguage("zh_CN", zh_CN); // 升级语言文件 +I18n.setDefaultLanguage("zh_CN"); // 设置I18n无法翻译时采用的默认语言 + +// I18n快捷翻译函数 +function tr(key, data = []) { + return I18n.translate(key, data); +} + +// 监听服务器启动 +// 在无特殊说明的情况下,一切 MCAPI 都应该在服务器启动后访问。 +mc.listen("onServerStarted", () => { + // 你的代码 + + + // 打印插件信息 + logger.info(tr("consolelog.loaded")); + logger.info(tr("consolelog.info", [PluginInfo.Author, PluginInfo.Version])); +}); \ No newline at end of file diff --git a/template/GMLIB_LRCA-Plugin-Template/config/config.json b/template/GMLIB_LRCA-Plugin-Template/config/config.json new file mode 100644 index 0000000..5f2a55d --- /dev/null +++ b/template/GMLIB_LRCA-Plugin-Template/config/config.json @@ -0,0 +1,3 @@ +{ + "language": "zh_CN" +} \ No newline at end of file diff --git a/template/GMLIB_LRCA-Plugin-Template/language/zh_CN.json b/template/GMLIB_LRCA-Plugin-Template/language/zh_CN.json new file mode 100644 index 0000000..084709f --- /dev/null +++ b/template/GMLIB_LRCA-Plugin-Template/language/zh_CN.json @@ -0,0 +1,4 @@ +{ + "consolelog.loaded": "加载成功!", + "consolelog.info": "插件作者: {1}, 当前版本: v{2}" +} \ No newline at end of file diff --git a/template/GMLIB_LRCA-Plugin-Template/manifest.json b/template/GMLIB_LRCA-Plugin-Template/manifest.json new file mode 100644 index 0000000..2df6d9b --- /dev/null +++ b/template/GMLIB_LRCA-Plugin-Template/manifest.json @@ -0,0 +1,16 @@ +{ + "entry": "GMLIB_LRCA-Plugin-Template.js", + "name": "GMLIB_LRCA-Plugin-Template", + "type": "lse-quickjs", + "version": "0.0.1", + "author": "Your Name", + "description": "plugin description", + "dependencies": [ + { + "name": "legacy-script-engine-quickjs" + }, + { + "name": "GMLIB-LegacyRemoteCallApi" + } + ] +} \ No newline at end of file diff --git a/tooth.json b/tooth.json index 4c1c55c..d2b9ef9 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", - "version": "0.9.5", + "version": "0.10.0", "info": { "name": "GMLIB-LegacyRemoteCallApi", "description": "Legacy RemoteCall API for GMLIB", @@ -14,9 +14,9 @@ "library" ] }, - "asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.9.5/GMLIB-LegacyRemoteCallApi-windows-x64.zip", + "asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.10.0/GMLIB-LegacyRemoteCallApi-windows-x64.zip", "dependencies": { - "github.com/GroupMountain/GMLIB": ">=0.9.8" + "github.com/GroupMountain/GMLIB": ">=0.10.0" }, "files": { "place": [