feat: add PlaceholderAPI
This commit is contained in:
+3
-2
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <include_all.h>
|
||||
#include <GMLIB/include_lib.h>
|
||||
#include <RemoteCallAPI.h>
|
||||
|
||||
#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();
|
||||
extern void Export_Compatibility_API();
|
||||
extern void ExportPAPI();
|
||||
@@ -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 <ll/api/memory/MemoryOperators.h>
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "Global.h"
|
||||
#include <regex>
|
||||
|
||||
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<std::string(std::string const& arg, std::unordered_map<std::string, std::string>)>(
|
||||
PluginName,
|
||||
FuncName
|
||||
);
|
||||
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](Player* sp, std::unordered_map<std::string, std::string> map) {
|
||||
return Call(sp->getXuid(), map);
|
||||
},
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string(std::string const& arg)>(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<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName);
|
||||
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
|
||||
PAPIName,
|
||||
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); },
|
||||
PluginName
|
||||
);
|
||||
} else {
|
||||
auto Call = RemoteCall::importAs<std::string()>(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<std::string()>(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);
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user