Compare commits

...

11 Commits

13 changed files with 216 additions and 210 deletions
+27 -21
View File
@@ -1,11 +1,14 @@
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")
const PAPIgetAllPAPI = ll.import("BEPlaceholderAPI", "getAllPAPI")
const PlaceholderAPI = {
getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"),
getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"),
registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"),
registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"),
registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"),
translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"),
translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"),
unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"),
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
}
Function.prototype.getName = function () {
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1]
@@ -17,38 +20,41 @@ class PAPI {
}
static registerPlayerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName())
PAPIregisterPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName)
ll.export(func, PluginName, func.getName());
PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
}
static registerServerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName())
PAPIregisterServerPlaceholderAPI(PluginName, func.getName(), PAPIName)
ll.export(func, PluginName, func.getName());
PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
}
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
ll.export(func, PluginName, func.getName())
PAPIregisterStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval)
ll.export(func, PluginName, func.getName());
PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
}
static getValue(key) {
return PAPIgetValueAPI(key)
return PlaceholderAPI.getValueAPI(key);
}
static getValueByPlayer(key, xuid) {
return PAPIgetValueByPlayerAPI(key, xuid)
static getValueByPlayer(key, pl) {
return PlaceholderAPI.getValueByPlayerAPI(key, pl);
}
static translateString(str, xuid = "") {
return PAPItranslateStringAPI(str, xuid)
static translateString(str, pl = null) {
if (pl) {
return PlaceholderAPI.translateStringWithPlayerAPI(str, pl);
}
return PlaceholderAPI.translateStringAPI(str);
}
static unRegisterPlaceholder(str) {
return PAPIunRegisterPlaceholderAPI(str)
return PlaceholderAPI.unRegisterPlaceholderAPI(str);
}
static getAllPAPI() {
return PAPIgetAllPAPI();
return PlaceholderAPI.getAllPAPI();
}
}
+34 -5
View File
@@ -6,10 +6,15 @@ const GMLIB_API = {
sendFloatingText: ll.import("GMLIB_API", "sendFloatingText"),
removeFloatingTextFromPlayer: ll.import("GMLIB_API", "removeFloatingTextFromPlayer"),
removeFloatingText: ll.import("GMLIB_API", "removeFloatingText"),
updateClientFloatingTextData: ll.import("GMLIB_API", "updateClientFloatingTextData"),
updateAllClientsFloatingTextData: ll.import("GMLIB_API", "updateAllClientsFloatingTextData"),
getServerMspt: ll.import("GMLIB_API", "getServerMspt"),
getServerCurrentTps: ll.import("GMLIB_API", "getServerCurrentTps"),
getServerAverageTps: ll.import("GMLIB_API", "getServerAverageTps"),
getAllPlayerUuids: ll.import("GMLIB_API", "getAllPlayerUuids"),
getPlayerNbt: ll.import("GMLIB_API", "getPlayerNbt"),
setPlayerNbt: ll.import("GMLIB_API", "setPlayerNbt"),
setPlayerNbtTags: ll.import("GMLIB_API", "setPlayerNbtTags"),
setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"),
registerAbilityCommand: ll.import("GMLib_ServerAPI", "registerAbilityCommand"),
setEnableAchievement: ll.import("GMLib_ServerAPI", "setEnableAchievement"),
@@ -72,6 +77,14 @@ class StaticFloatingText {
return GMLIB_API.removeFloatingText(this.mRuntimeId);
}
updateClient(player) {
return GMLIB_API.updateClientFloatingTextData(this.mRuntimeId, player);
}
updateClients() {
return GMLIB_API.updateAllClientsFloatingTextData(this.mRuntimeId);
}
getRuntimeId() {
return this.mRuntimeId;
}
@@ -86,7 +99,7 @@ class StaticFloatingText {
update() {
GMLIB_API.setFloatingTextData(this.mRuntimeId, this.mText);
return this.sendToClients();
return this.updateClients();
}
updateText(newText) {
@@ -109,13 +122,13 @@ class StaticFloatingText {
}
static getFloatingText(runtimeId) {
FloatingTextList.forEach((ft) => {
for (const ft of FloatingTextList) {
if (ft.getRuntimeId() == runtimeId) {
if (!ft.isDynamic()) {
return ft;
}
}
});
}
return null;
}
@@ -178,13 +191,13 @@ class DynamicFloatingText extends StaticFloatingText {
}
static getFloatingText(runtimeId) {
FloatingTextList.forEach((ft) => {
for (const ft of FloatingTextList) {
if (ft.getRuntimeId() == runtimeId) {
if (ft.isDynamic()) {
return ft;
}
}
});
}
return null;
}
@@ -220,6 +233,22 @@ class Minecraft {
return GMLIB_API.getAllPlayerUuids();
}
static getPlayerNbt(uuid) {
let snbt = GMLIB_API.getPlayerNbt(uuid);
let nbt = NBT.parseSNBT(snbt);
return nbt;
}
static setPlayerNbt(uuid, nbt) {
let snbt = nbt.toSNBT();
return GMLIB_API.setPlayerNbt(uuid, snbt);
}
static setPlayerNbtTags(uuid, nbt, tags) {
let snbt = nbt.toSNBT();
return GMLIB_API.setPlayerNbtTags(uuid, snbt, tags);
}
static setEducationFeatureEnabled() {
return GMLIB_API.setEducationFeatureEnabled();
}
+34
View File
@@ -25,6 +25,24 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
return GMLIB_Player::getAllUuids();
});
RemoteCall::exportAs("GMLIB_API", "getPlayerNbt", [](std::string uuid) -> std::string {
auto uid = mce::UUID::fromString(uuid);
return GMLIB_Player::getPlayerNbt(uid)->toSnbt();
});
RemoteCall::exportAs("GMLIB_API", "setPlayerNbt", [](std::string uuid, std::string snbt) -> bool {
auto uid = mce::UUID::fromString(uuid);
auto nbt = CompoundTag::fromSnbt(snbt);
return GMLIB_Player::setPlayerNbt(uid, *nbt);
});
RemoteCall::exportAs(
"GMLIB_API",
"setPlayerNbtTags",
[](std::string uuid, std::string snbt, std::vector<std::string> tags) -> bool {
auto uid = mce::UUID::fromString(uuid);
auto nbt = CompoundTag::fromSnbt(snbt);
return GMLIB_Player::setPlayerNbtTags(uid, *nbt, tags);
}
);
RemoteCall::exportAs("GMLIB_API", "getAllExperiments", []() -> std::vector<int> {
auto map = GMLIB_Level::getAllExperiments();
std::vector<int> result;
@@ -91,6 +109,22 @@ void Export_Compatibility_API() {
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "updateClientFloatingTextData", [](int id, Player* pl) -> bool {
auto ft = GMLIB::Server::FloatingText::getFloatingText(id);
if (ft) {
ft->updateClient(pl);
return true;
}
return false;
});
RemoteCall::exportAs("GMLIB_API", "updateAllClientsFloatingTextData", [](int id) -> bool {
auto ft = GMLIB::Server::FloatingText::getFloatingText(id);
if (ft) {
ft->updateAllClients();
return true;
}
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);
-32
View File
@@ -1,32 +0,0 @@
#include <memory>
#include <ll/api/plugin/NativePlugin.h>
#include "Plugin.h"
namespace plugin {
// The global plugin instance.
std::unique_ptr<Plugin> plugin = nullptr;
extern "C" {
_declspec(dllexport) bool ll_plugin_load(ll::plugin::NativePlugin& self) {
plugin = std::make_unique<plugin::Plugin>(self);
return true;
}
/// @warning Unloading the plugin may cause a crash if the plugin has not released all of its
/// resources. If you are unsure, keep this function commented out.
// _declspec(dllexport) bool ll_plugin_unload(ll::plugin::Plugin&) {
// plugin.reset();
//
// return true;
// }
_declspec(dllexport) bool ll_plugin_enable(ll::plugin::NativePlugin&) { return plugin->enable(); }
_declspec(dllexport) bool ll_plugin_disable(ll::plugin::NativePlugin&) { return plugin->disable(); }
}
} // namespace plugin
+57
View File
@@ -0,0 +1,57 @@
#include "Entry.h"
#include "Global.h"
ll::Logger logger(PLUGIN_NAME);
namespace GMLIB_LegacyRemoteCallApi {
namespace {
std::unique_ptr<std::reference_wrapper<ll::plugin::NativePlugin>>
selfPluginInstance; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
auto disable(ll::plugin::NativePlugin& /*self*/) -> bool { return false; }
auto enable(ll::plugin::NativePlugin& /*self*/) -> bool { return true; }
auto load(ll::plugin::NativePlugin& self) -> bool {
selfPluginInstance = std::make_unique<std::reference_wrapper<ll::plugin::NativePlugin>>(self);
Export_Legacy_GMLib_ModAPI();
Export_Legacy_GMLib_ServerAPI();
Export_Compatibility_API();
ExportPAPI();
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
logger.info("Version: {}", LIB_VERSION.asString());
logger.info("Author: GroupMountain");
logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
return true;
}
auto unload(ll::plugin::NativePlugin& self) -> bool { return false; }
} // namespace
auto getSelfPluginInstance() -> ll::plugin::NativePlugin& {
if (!selfPluginInstance) {
throw std::runtime_error("selfPluginInstance is null");
}
return *selfPluginInstance;
}
} // namespace GMLIB_LegacyRemoteCallApi
extern "C" {
_declspec(dllexport) auto ll_plugin_disable(ll::plugin::NativePlugin& self) -> bool {
return GMLIB_LegacyRemoteCallApi::disable(self);
}
_declspec(dllexport) auto ll_plugin_enable(ll::plugin::NativePlugin& self) -> bool {
return GMLIB_LegacyRemoteCallApi::enable(self);
}
_declspec(dllexport) auto ll_plugin_load(ll::plugin::NativePlugin& self) -> bool {
return GMLIB_LegacyRemoteCallApi::load(self);
}
_declspec(dllexport) auto ll_plugin_unload(ll::plugin::NativePlugin& self) -> bool {
return GMLIB_LegacyRemoteCallApi::unload(self);
}
}
+9
View File
@@ -0,0 +1,9 @@
#pragma once
#include <ll/api/plugin/NativePlugin.h>
namespace GMLIB_LegacyRemoteCallApi {
[[nodiscard]] auto getSelfPluginInstance() -> ll::plugin::NativePlugin&;
} // namespace GMLIB_LegacyRemoteCallApi
+3 -2
View File
@@ -1,9 +1,10 @@
#pragma once
#include <GMLIB/include_lib.h>
#include <include_all.h>
#include <RemoteCallAPI.h>
#define PLUGIN_NAME "GMLIB-LRCA"
#define LIB_VERSION SemVersion(0, 8, 4, "", "")
#define LIB_VERSION SemVersion(0, 9, 1, "", "")
extern ll::Logger logger;
-7
View File
@@ -1,7 +0,0 @@
// 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>
+48 -82
View File
@@ -3,114 +3,79 @@
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) {
bool 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";
auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
PAPIName,
[Call](Player* sp) { return Call(sp); },
PluginName
);
return true;
}
return "Register Success";
return false;
}
std::string
registerServerPlaceholder(std::string const& PluginName, std::string const& FuncName, std::string const& PAPIName) {
bool 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";
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
PAPIName,
[Call]() { return Call(); },
PluginName
);
return true;
}
return "Register Success";
return false;
}
std::string registerStaticPlaceholder(
bool 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
);
}
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 true;
}
return "Register Success";
return false;
}
std::string translateString(std::string const& str, std::string const& xuid) {
return GMLIB::Server::PlaceholderAPI::translate(str, ll::service::bedrock::getLevel()->getPlayerByXuid(xuid));
std::string translateStringWithPlayer(std::string const& str, Player* pl) {
return GMLIB::Server::PlaceholderAPI::translateString(str, pl);
}
std::string translateString(std::string const& str) { return GMLIB::Server::PlaceholderAPI::translateString(str); }
bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unRegisterPlaceholder(str); }
std::vector<std::string> getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); }
@@ -127,6 +92,7 @@ void ExportPAPI() {
EXPORTAPI(PAPIRemoteCall::GetValue);
EXPORTAPI(PAPIRemoteCall::GetValueWithPlayer);
EXPORTAPI(PAPIRemoteCall::translateString);
EXPORTAPI(PAPIRemoteCall::translateStringWithPlayer);
EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder);
EXPORTAPI(PAPIRemoteCall::getAllPAPI);
}
-30
View File
@@ -1,30 +0,0 @@
#include "Plugin.h"
#include "Global.h"
ll::Logger logger(PLUGIN_NAME);
namespace plugin {
Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) {
// Code for loading the plugin goes here.
Export_Legacy_GMLib_ModAPI();
Export_Legacy_GMLib_ServerAPI();
Export_Compatibility_API();
ExportPAPI();
logger.info("GMLIB-LegacyRemoteCallApi Loaded!");
logger.info("Version: {}", LIB_VERSION.asString());
logger.info("Author: GroupMountain");
logger.info("Repository: https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi");
}
bool Plugin::enable() {
// Code for enabling the plugin goes here.
return true;
}
bool Plugin::disable() {
// Code for disabling the plugin goes here.
return true;
}
} // namespace plugin
-27
View File
@@ -1,27 +0,0 @@
#pragma once
#include <ll/api/plugin/NativePlugin.h>
namespace plugin {
class Plugin {
public:
explicit Plugin(ll::plugin::NativePlugin& self);
Plugin(Plugin&&) = delete;
Plugin(const Plugin&) = delete;
Plugin& operator=(Plugin&&) = delete;
Plugin& operator=(const Plugin&) = delete;
~Plugin() = default;
/// @return True if the plugin is enabled successfully.
bool enable();
/// @return True if the plugin is disabled successfully.
bool disable();
private:
ll::plugin::NativePlugin& mSelf;
};
} // namespace plugin
+3 -3
View File
@@ -1,7 +1,7 @@
{
"format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "0.8.4",
"version": "0.9.1",
"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.8.4/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.9.1/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.8.5"
"github.com/GroupMountain/GMLIB": ">=0.9.2"
},
"files": {
"place": [