From b2737599c8562ee44f966a724a5a52826a0ed72c Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Wed, 21 Feb 2024 23:52:24 +0800 Subject: [PATCH 1/3] feat: adapt GMLIB 0.8.4 --- SDK-GMLIB | 2 +- lib/GMLIB-API.js | 348 +++++++++++++++++++++++++++++++++++++++ scripts/after_build.lua | 2 + src/CompatibilityApi.cpp | 14 +- 4 files changed, 360 insertions(+), 6 deletions(-) create mode 100644 lib/GMLIB-API.js diff --git a/SDK-GMLIB b/SDK-GMLIB index 945cea5..32687e7 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit 945cea5caee03d9f911e0d0fb60f9bb601f869ad +Subproject commit 32687e7eda893078565e1b54c284eb3571a5cc59 diff --git a/lib/GMLIB-API.js b/lib/GMLIB-API.js new file mode 100644 index 0000000..add472a --- /dev/null +++ b/lib/GMLIB-API.js @@ -0,0 +1,348 @@ +const GMLIB_API = { + createFloatingText: ll.import("GMLIB_API", "createFloatingText"), + deleteFloatingText: ll.import("GMLIB_API", "deleteFloatingText"), + setFloatingTextData: ll.import("GMLIB_API", "setFloatingTextData"), + sendFloatingTextToPlayer: ll.import("GMLIB_API", "sendFloatingTextToPlayer"), + sendFloatingText: ll.import("GMLIB_API", "sendFloatingText"), + removeFloatingTextFromPlayer: ll.import("GMLIB_API", "removeFloatingTextFromPlayer"), + removeFloatingText: ll.import("GMLIB_API", "removeFloatingText"), + getServerMspt: ll.import("GMLIB_API", "getServerMspt"), + getServerCurrentTps: ll.import("GMLIB_API", "getServerCurrentTps"), + getServerAverageTps: ll.import("GMLIB_API", "getServerAverageTps"), + getAllPlayerUuids: ll.import("GMLIB_API", "getAllPlayerUuids"), + setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"), + registerAbilityCommand: ll.import("GMLib_ServerAPI", "registerAbilityCommand"), + setEnableAchievement: ll.import("GMLib_ServerAPI", "setEnableAchievement"), + setForceTrustSkins: ll.import("GMLib_ServerAPI", "setForceTrustSkins"), + enableCoResourcePack: ll.import("GMLib_ServerAPI", "enableCoResourcePack"), + getLevelName: ll.import("GMLib_ServerAPI", "getLevelName"), + setLevelName: ll.import("GMLib_ServerAPI", "setLevelName"), + setFakeSeed: ll.import("GMLib_ServerAPI", "setFakeSeed"), + spawnEntity: ll.import("GMLib_ServerAPI", "spawnEntity"), + shootProjectile: ll.import("GMLib_ServerAPI", "shootProjectile"), + throwEntity: ll.import("GMLib_ServerAPI", "throwEntity"), + PlayerToEntity: ll.import("GMLib_ServerAPI", "PlayerToEntity"), + setUnknownBlockCleaner: ll.import("GMLib_ModAPI", "setUnknownBlockCleaner"), + getAllExperiments: ll.import("GMLIB_API", "getAllExperiments"), + getExperimentTranslatedName: ll.import("GMLIB_API", "getExperimentTranslatedName"), + getExperimentEnabled: ll.import("GMLib_ModAPI", "getExperimentEnabled"), + setExperimentEnabled: ll.import("GMLib_ModAPI", "setExperimentEnabled"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerExperimentsRequire"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerStoneCutterRecipe"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerSmithingTrimRecipe"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerSmithingTransformRecipe"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerBrewingContainerRecipe"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerBrewingMixRecipe"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerFurnaceRecipe"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerShapedRecipe"), + registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerShapelessRecipe") +} + +const FloatingTextList = []; + +class StaticFloatingText { + constructor(pos, text) { + this.mPosition = pos; + this.mText = text; + this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText); + FloatingTextList.push(this); + this.sendToClients(); + mc.listen("onJoin", (pl) => { + this.sendToClient(pl); + }); + } + + sendToClient(player) { + return GMLIB_API.sendFloatingTextToPlayer(this.mRuntimeId, player); + } + + sendToClients() { + return GMLIB_API.sendFloatingText(this.mRuntimeId); + } + + removeFromClient(player) { + return GMLIB_API.removeFloatingTextFromPlayer(this.mRuntimeId, player); + } + + removeFromClients() { + return GMLIB_API.removeFloatingText(this.mRuntimeId); + } + + getRuntimeId() { + return this.mRuntimeId; + } + + getText() { + return this.mText; + } + + setText(newText) { + this.mText = newText; + } + + update() { + GMLIB_API.setFloatingTextData(this.mRuntimeId, this.mText); + return this.sendToClients(); + } + + updateText(newText) { + this.setText(newText); + return this.update(); + } + + getPos() { + return this.mPosition; + } + + destroy() { + let size_t = FloatingTextList.indexOf(this); + FloatingTextList.splice(size_t, 1); + return GMLIB_API.deleteFloatingText(this.mRuntimeId); + } + + isDynamic() { + return false; + } + + static getFloatingText(runtimeId) { + FloatingTextList.forEach((ft) => { + if (ft.getRuntimeId() == runtimeId) { + if (!ft.isDynamic()) { + return ft; + } + } + }); + return null; + } + + static getAllFloatingTexts() { + let result = []; + FloatingTextList.forEach((ft) => { + if (!ft.isDynamic()) { + result.push(ft); + } + }); + return result; + } +} + +class DynamicFloatingText extends StaticFloatingText { + constructor(pos, text, updateRate = 1) { + super(pos, text); + this.mUpdateRate = updateRate; + this.mTaskId = null; + this.startUpdate(); + } + + getUpdateRate() { + return this.mUpdateRate; + } + + setUpdateRate(updateRate = 1) { + this.stopUpdate(); + this.mUpdateRate = updateRate; + this.startUpdate(); + } + + startUpdate() { + if (this.mTaskId == null) { + this.mTaskId = setInterval(() => { + this.update(); + }, this.mUpdateRate * 1000); + return true; + } + return false; + } + + stopUpdate() { + if (this.mTaskId != null) { + clearInterval(this.mTaskId); + this.mTaskId = null; + return true; + } + return false; + } + + destroy() { + let size_t = FloatingTextList.indexOf(this); + FloatingTextList.splice(size_t, 1); + return GMLIB_API.deleteFloatingText(this.mRuntimeId); + } + + isDynamic() { + return true; + } + + static getFloatingText(runtimeId) { + FloatingTextList.forEach((ft) => { + if (ft.getRuntimeId() == runtimeId) { + if (ft.isDynamic()) { + return ft; + } + } + }); + return null; + } + + static getAllFloatingTexts() { + let result = []; + FloatingTextList.forEach((ft) => { + if (ft.isDynamic()) { + result.push(ft); + } + }); + return result; + } +} + +class Minecraft { + constructor() { + throw new Error("Static class cannot be instantiated"); + } + + static getServerAverageTps() { + return GMLIB_API.getServerAverageTps(); + } + + static getServerCurrentTps() { + return GMLIB_API.getServerCurrentTps(); + } + + static getServerMspt() { + return GMLIB_API.getServerMspt(); + } + + static getAllPlayerUuids() { + return GMLIB_API.getAllPlayerUuids(); + } + + static setEducationFeatureEnabled() { + return GMLIB_API.setEducationFeatureEnabled(); + } + + static registerAbilityCommand() { + return GMLIB_API.registerAbilityCommand(); + } + + static setEnableAchievement() { + return GMLIB_API.setEnableAchievement(); + } + + static setForceTrustSkins() { + return GMLIB_API.setForceTrustSkins(); + } + + static enableCoResourcePack() { + return GMLIB_API.enableCoResourcePack(); + } + + static getWorldName() { + return GMLIB_API.getLevelName(); + } + + static setWorldName(name) { + return GMLIB_API.setLevelName(name); + } + + static setFakeSeed(seed = 114514) { + return GMLIB_API.setFakeSeed(seed); + } + + static setUnknownBlockCleaner() { + return GMLIB_API.setUnknownBlockCleaner(); + } + + static playerToEntity(player) { + return GMLIB_API.PlayerToEntity(player); + } + + static spawnEntity(pos, name) { + return GMLIB_API.spawnEntity(pos, name); + } + + static shootProjectile(entity, proj, speed = 2, offset = 3) { + return GMLIB_API.shootProjectile(entity, proj, speed, offset); + } + + static throwEntity(entity, proj, speed = 2, offset = 3) { + return GMLIB_API.throwEntity(entity, proj, speed = 2, offset = 3); + } +} + +class Recipes { + constructor() { + throw new Error("Static class cannot be instantiated"); + } + + static registerStoneCutterRecipe(recipeId, inputName, inputAux, outputName, outputAux, outputCount) { + return GMLIB_API.registerStoneCutterRecipe(recipeId, inputName, inputAux, outputName, outputAux, outputCount); + } + + static registerSmithingTrimRecipe(recipeId, template, base, addition) { + return GMLIB_API.registerSmithingTrimRecipe(recipeId, template, base, addition); + } + + static registerSmithingTransformRecipe(recipeId, template, base, addition, result) { + return GMLIB_API.registerSmithingTransformRecipe(recipeId, template, base, addition, result); + } + + static registerBrewingContainerRecipe(recipeId, input, output, reagent) { + return GMLIB_API.registerBrewingContainerRecipe(recipeId, input, output, reagent); + } + + static registerBrewingMixRecipe(recipeId, input, output, reagent) { + return GMLIB_API.registerBrewingMixRecipe(recipeId, input, output, reagent); + } + + // tags ["furnace", "blast_furnace", "smoker", "campfire", "soul_campfire"] + static registerFurnaceRecipe(recipeId, input, output, tags = ["furnace"]) { + return GMLIB_API.registerFurnaceRecipe(recipeId, input, output, tags); + } + + // unlock : "AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None", Item ID + static registerShapedRecipe(recipeId, shape, ingredients, result, count = 1, unlock = "AlwaysUnlocked") { + return GMLIB_API.registerShapedRecipe(recipeId, shape, ingredients, result, count, unlock); + } + + static registerShapelessRecipe(recipeId, ingredients, result, count = 1, unlock = "AlwaysUnlocked") { + return GMLIB_API.registerShapelessRecipe(recipeId, ingredients, result, count, unlock); + } +} + +class Experiments { + constructor() { + throw new Error("Static class cannot be instantiated"); + } + + static getAllExperimentIds() { + return GMLIB_API.getAllExperiments(); + } + + static getExperimentTranslatedName(id) { + return GMLIB_API.getExperimentTranslatedName(id); + } + + static getExperimentsMap() { + let ids = this.getAllExperimentIds(); + let result = {}; + for (let id in ids) { + let name = this.getExperimentTranslatedName(id); + result[id] = name; + } + return result; + } + + static getExperimentEnabled(id) { + return GMLIB_API.getExperimentEnabled(id); + } + + static setExperimentEnabled(id, value = true) { + return GMLIB_API.setExperimentEnabled(id, value); + } + + static registerExperimentsRequire(id) { + return GMLIB_API.registerExperimentsRequire(id); + } +} + +export { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments }; \ No newline at end of file diff --git a/scripts/after_build.lua b/scripts/after_build.lua index 9475b5a..3c1f6d1 100644 --- a/scripts/after_build.lua +++ b/scripts/after_build.lua @@ -92,6 +92,7 @@ function pack_plugin(target,plugin_define) local outputdir = path.join(bindir, plugin_define.pluginName) local targetfile = path.join(outputdir, plugin_define.pluginFile) local pdbfile = path.join(outputdir, path.basename(plugin_define.pluginFile) .. ".pdb") + local libfile = path.join(os.projectdir(), "lib") local manifestfile = path.join(outputdir, "manifest.json") local oritargetfile = target:targetfile() local oripdbfile = path.join(path.directory(oritargetfile), path.basename(oritargetfile) .. ".pdb") @@ -101,6 +102,7 @@ function pack_plugin(target,plugin_define) if os.isfile(oripdbfile) then os.cp(oripdbfile, pdbfile) end + os.cp(libfile, outputdir) formattedmanifest = string_formatter(manifest, plugin_define) io.writefile(manifestfile,formattedmanifest) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 124b8fa..806b9e3 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -36,14 +36,18 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getExperimentTranslatedName", [](int id) -> std::string { auto map = GMLIB_Level::getAllExperimentsTranslateKeys(); if (map.count(id)) { - return map[id]; + return std::string(map[id]); } return ""; }); - RemoteCall::exportAs("GMLIB_API", "createFloatingText", [](std::pair pos, std::string text) -> int { - auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second); - return ft->getRuntimeID(); - }); + RemoteCall::exportAs( + "GMLIB_API", + "createFloatingText", + [](std::pair pos, std::string text, bool papi) -> int { + auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second, papi); + return ft->getRuntimeID(); + } + ); RemoteCall::exportAs("GMLIB_API", "setFloatingTextData", [](int id, std::string text) -> bool { auto ft = GMLIB::Server::FloatingText::getFloatingText(id); if (ft) { From 0001f80ff26e62024052737861c96dec19455eb2 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 22 Feb 2024 22:29:42 +0800 Subject: [PATCH 2/3] feat: add PlaceholderAPI --- SDK-GMLIB | 2 +- lib/BEPlaceholderAPI-JS.js | 54 +++++++++++ lib/{GMLIB-API.js => GMLIB_API-JS.js} | 11 ++- src/Global.h | 5 +- src/MemoryOperators.cpp | 7 ++ src/PlaceholderApi.cpp | 131 ++++++++++++++++++++++++++ src/Plugin.cpp | 1 + 7 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 lib/BEPlaceholderAPI-JS.js rename lib/{GMLIB-API.js => GMLIB_API-JS.js} (97%) create mode 100644 src/MemoryOperators.cpp create mode 100644 src/PlaceholderApi.cpp diff --git a/SDK-GMLIB b/SDK-GMLIB index 32687e7..0ad5f24 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit 32687e7eda893078565e1b54c284eb3571a5cc59 +Subproject commit 0ad5f249edef7c909497e385699eb527b7acab97 diff --git a/lib/BEPlaceholderAPI-JS.js b/lib/BEPlaceholderAPI-JS.js new file mode 100644 index 0000000..b0ac46a --- /dev/null +++ b/lib/BEPlaceholderAPI-JS.js @@ -0,0 +1,54 @@ +const PAPIgetValueAPI = ll.import("BEPlaceholderAPI", "GetValue") +const PAPIgetValueByPlayerAPI = ll.import("BEPlaceholderAPI", "GetValueWithPlayer") +const PAPIregisterPlayerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder") +const PAPIregisterServerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerServerPlaceholder") +const PAPIregisterStaticPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerStaticPlaceholder") +const PAPItranslateStringAPI = ll.import("BEPlaceholderAPI", "translateString") +const PAPIunRegisterPlaceholderAPI = ll.import("BEPlaceholderAPI", "unRegisterPlaceholder") + +Function.prototype.getName = function () { + + return this.name || this.toString().match(/function\s*([^(]*)\(/)[1] + +} + +class PAPI { + constructor() { } + + static registerPlayerPlaceholder(func, PluginName, PAPIName) { + + ll.export(func, PluginName, func.getName()) + PAPIregisterPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName) + } + + static registerServerPlaceholder(func, PluginName, PAPIName) { + ll.export(func, PluginName, func.getName()) + PAPIregisterServerPlaceholderAPI(PluginName, func.getName(), PAPIName) + } + + static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) { + ll.export(func, PluginName, func.getName()) + PAPIregisterStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval) + } + + static getValue(key) { + return PAPIgetValueAPI(key) + } + + static getValueByPlayer(key, xuid) { + return PAPIgetValueByPlayerAPI(key, xuid) + } + + static translateString(str, xuid = "") { + return PAPItranslateStringAPI(str, xuid) + } + + static unRegisterPlaceholder(str) { + return PAPIunRegisterPlaceholderAPI(str) + } + +} + +module.exports = { + PAPI +}; \ No newline at end of file diff --git a/lib/GMLIB-API.js b/lib/GMLIB_API-JS.js similarity index 97% rename from lib/GMLIB-API.js rename to lib/GMLIB_API-JS.js index add472a..922217a 100644 --- a/lib/GMLIB-API.js +++ b/lib/GMLIB_API-JS.js @@ -41,10 +41,11 @@ const GMLIB_API = { const FloatingTextList = []; class StaticFloatingText { - constructor(pos, text) { + constructor(pos, text, papi = true) { this.mPosition = pos; this.mText = text; - this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText); + this.mPlaceholderAPI = papi; + this.mRuntimeId = GMLIB_API.createFloatingText(this.mPosition, this.mText, this.mPlaceholderAPI); FloatingTextList.push(this); this.sendToClients(); mc.listen("onJoin", (pl) => { @@ -127,8 +128,8 @@ class StaticFloatingText { } class DynamicFloatingText extends StaticFloatingText { - constructor(pos, text, updateRate = 1) { - super(pos, text); + constructor(pos, text, updateRate = 1, papi = true) { + super(pos, text, papi); this.mUpdateRate = updateRate; this.mTaskId = null; this.startUpdate(); @@ -345,4 +346,4 @@ class Experiments { } } -export { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments }; \ No newline at end of file +module.exports = { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments }; \ No newline at end of file diff --git a/src/Global.h b/src/Global.h index c445e32..2dd567b 100644 --- a/src/Global.h +++ b/src/Global.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #define PLUGIN_NAME "GMLIB-LRCA" @@ -8,4 +8,5 @@ extern ll::Logger logger; extern void Export_Legacy_GMLib_ModAPI(); extern void Export_Legacy_GMLib_ServerAPI(); -extern void Export_Compatibility_API(); \ No newline at end of file +extern void Export_Compatibility_API(); +extern void ExportPAPI(); \ No newline at end of file diff --git a/src/MemoryOperators.cpp b/src/MemoryOperators.cpp new file mode 100644 index 0000000..f7c918a --- /dev/null +++ b/src/MemoryOperators.cpp @@ -0,0 +1,7 @@ +// This file will make your plugin use LeviLamina's memory operators by default. +// This improves the memory management of your plugin and is recommended to use. +// You should not modify anything in this file. + +#define LL_MEMORY_OPERATORS + +#include diff --git a/src/PlaceholderApi.cpp b/src/PlaceholderApi.cpp new file mode 100644 index 0000000..ac7c4e5 --- /dev/null +++ b/src/PlaceholderApi.cpp @@ -0,0 +1,131 @@ +#include "Global.h" +#include + +namespace PAPIRemoteCall { + +std::string removeBrackets(std::string a1) { + a1.erase(a1.find_last_not_of("%") + 1); + return a1; +} + +bool isParameters(std::string str) { + std::regex reg("[<]([^<>]+)[>]"); + return std::regex_search(removeBrackets(str), reg); +} + +std::string GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); } + +std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) { + return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2)); +} + +std::string +registerPlayerPlaceholder(std::string const& PluginName, std::string const& FuncName, std::string const& PAPIName) { + if (RemoteCall::hasFunc(PluginName, FuncName)) { + if (isParameters(PAPIName)) { + auto Call = + RemoteCall::importAs)>( + PluginName, + FuncName + ); + GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder( + PAPIName, + [Call](Player* sp, std::unordered_map map) { + return Call(sp->getXuid(), map); + }, + PluginName + ); + } else { + auto Call = RemoteCall::importAs(PluginName, FuncName); + GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder( + PAPIName, + [Call](Player* sp) { return Call(sp->getXuid()); }, + PluginName + ); + } + } else { + // logger.error("Function no find({}:{})", PluginName, FuncName); + return "Function no find"; + } + return "Register Success"; +} + +std::string +registerServerPlaceholder(std::string const& PluginName, std::string const& FuncName, std::string const& PAPIName) { + if (RemoteCall::hasFunc(PluginName, FuncName)) { + if (isParameters(PAPIName)) { + auto Call = + RemoteCall::importAs)>(PluginName, FuncName); + GMLIB::Server::PlaceholderAPI::registerServerPlaceholder( + PAPIName, + [Call](std::unordered_map map) { return Call(map); }, + PluginName + ); + } else { + auto Call = RemoteCall::importAs(PluginName, FuncName); + GMLIB::Server::PlaceholderAPI::registerServerPlaceholder( + PAPIName, + [Call]() { return Call(); }, + PluginName + ); + } + } else { + // logger.error("Function no find({}:{})", PluginName, FuncName); + return "Function no find"; + } + return "Register Success"; +} + +std::string registerStaticPlaceholder( + std::string const& PluginName, + std::string const& FuncName, + std::string const& PAPIName, + int num +) { + if (RemoteCall::hasFunc(PluginName, FuncName)) { + if (isParameters(PAPIName)) { + auto Call = RemoteCall::importAs(PluginName, FuncName); + if (num == -1) { + GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder( + PAPIName, + [Call] { return Call(); }, + PluginName + ); + } else { + GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder( + PAPIName, + num, + [Call] { return Call(); }, + PluginName + ); + } + } + } else { + // logger.error("Function no find({}:{})", PluginName, FuncName); + return "Function no find"; + } + return "Register Success"; +} + +std::string translateString(std::string const& str, std::string const& xuid) { + std::string _str = str; + GMLIB::Server::PlaceholderAPI::translateString(_str, ll::service::bedrock::getLevel()->getPlayerByXuid(xuid)); + return _str; +} + +bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unRegisterPlaceholder(str); } + +} // namespace PAPIRemoteCall + +#define EXPORTAPI(T) \ + RemoteCall::exportAs("BEPlaceholderAPI", ll::utils::string_utils::replaceAll(#T, "PAPIRemoteCall::", ""), T); + +void ExportPAPI() { + EXPORTAPI(PAPIRemoteCall::registerPlayerPlaceholder); + EXPORTAPI(PAPIRemoteCall::registerServerPlaceholder); + EXPORTAPI(PAPIRemoteCall::registerStaticPlaceholder); + EXPORTAPI(PAPIRemoteCall::GetValue); + EXPORTAPI(PAPIRemoteCall::GetValueWithPlayer); + EXPORTAPI(PAPIRemoteCall::translateString); + EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder); +} \ No newline at end of file diff --git a/src/Plugin.cpp b/src/Plugin.cpp index a9b0f8e..a8dd1ad 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -10,6 +10,7 @@ Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) { Export_Legacy_GMLib_ModAPI(); Export_Legacy_GMLib_ServerAPI(); Export_Compatibility_API(); + ExportPAPI(); logger.info("GMLIB-LegacyRemoteCallApi Loaded!"); logger.info("Author: GroupMountain"); logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi"); From cb9c8a015d8eea38591ce5e4b9bc47c4ff3e6907 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:41:37 +0800 Subject: [PATCH 3/3] feat: adapt GMLIB 0.8.5 --- SDK-GMLIB | 2 +- lib/BEPlaceholderAPI-JS.js | 9 ++++++++- src/PlaceholderApi.cpp | 7 ++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/SDK-GMLIB b/SDK-GMLIB index 0ad5f24..58cec5c 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit 0ad5f249edef7c909497e385699eb527b7acab97 +Subproject commit 58cec5c0c5eeae94593df1235419fd180ea4a261 diff --git a/lib/BEPlaceholderAPI-JS.js b/lib/BEPlaceholderAPI-JS.js index b0ac46a..afcc3af 100644 --- a/lib/BEPlaceholderAPI-JS.js +++ b/lib/BEPlaceholderAPI-JS.js @@ -5,6 +5,7 @@ const PAPIregisterServerPlaceholderAPI = ll.import("BEPlaceholderAPI", "register const PAPIregisterStaticPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerStaticPlaceholder") const PAPItranslateStringAPI = ll.import("BEPlaceholderAPI", "translateString") const PAPIunRegisterPlaceholderAPI = ll.import("BEPlaceholderAPI", "unRegisterPlaceholder") +const PAPIgetAllPAPI = ll.import("BEPlaceholderAPI", "getAllPAPI") Function.prototype.getName = function () { @@ -13,7 +14,9 @@ Function.prototype.getName = function () { } class PAPI { - constructor() { } + constructor() { + throw new Error("Static class cannot be instantiated"); + } static registerPlayerPlaceholder(func, PluginName, PAPIName) { @@ -47,6 +50,10 @@ class PAPI { return PAPIunRegisterPlaceholderAPI(str) } + static getAllPAPI() { + return PAPIgetAllPAPI(); + } + } module.exports = { diff --git a/src/PlaceholderApi.cpp b/src/PlaceholderApi.cpp index ac7c4e5..bea552f 100644 --- a/src/PlaceholderApi.cpp +++ b/src/PlaceholderApi.cpp @@ -108,13 +108,13 @@ std::string registerStaticPlaceholder( } std::string translateString(std::string const& str, std::string const& xuid) { - std::string _str = str; - GMLIB::Server::PlaceholderAPI::translateString(_str, ll::service::bedrock::getLevel()->getPlayerByXuid(xuid)); - return _str; + return GMLIB::Server::PlaceholderAPI::translate(str, ll::service::bedrock::getLevel()->getPlayerByXuid(xuid)); } bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unRegisterPlaceholder(str); } +std::vector getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); } + } // namespace PAPIRemoteCall #define EXPORTAPI(T) \ @@ -128,4 +128,5 @@ void ExportPAPI() { EXPORTAPI(PAPIRemoteCall::GetValueWithPlayer); EXPORTAPI(PAPIRemoteCall::translateString); EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder); + EXPORTAPI(PAPIRemoteCall::getAllPAPI); } \ No newline at end of file