Compare commits

..

30 Commits

16 changed files with 480 additions and 231 deletions
+27 -24
View File
@@ -1,16 +1,17 @@
const PAPIgetValueAPI = ll.import("BEPlaceholderAPI", "GetValue") const PlaceholderAPI = {
const PAPIgetValueByPlayerAPI = ll.import("BEPlaceholderAPI", "GetValueWithPlayer") getValueAPI: ll.import("BEPlaceholderAPI", "GetValue"),
const PAPIregisterPlayerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder") getValueByPlayerAPI: ll.import("BEPlaceholderAPI", "GetValueWithPlayer"),
const PAPIregisterServerPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerServerPlaceholder") registerPlayerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerPlayerPlaceholder"),
const PAPIregisterStaticPlaceholderAPI = ll.import("BEPlaceholderAPI", "registerStaticPlaceholder") registerServerPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerServerPlaceholder"),
const PAPItranslateStringAPI = ll.import("BEPlaceholderAPI", "translateString") registerStaticPlaceholderAPI: ll.import("BEPlaceholderAPI", "registerStaticPlaceholder"),
const PAPIunRegisterPlaceholderAPI = ll.import("BEPlaceholderAPI", "unRegisterPlaceholder") translateStringAPI: ll.import("BEPlaceholderAPI", "translateString"),
const PAPIgetAllPAPI = ll.import("BEPlaceholderAPI", "getAllPAPI") translateStringWithPlayerAPI: ll.import("BEPlaceholderAPI", "translateStringWithPlayer"),
unRegisterPlaceholderAPI: ll.import("BEPlaceholderAPI", "unRegisterPlaceholder"),
getAllPAPI: ll.import("BEPlaceholderAPI", "getAllPAPI")
}
Function.prototype.getName = function () { Function.prototype.getName = function () {
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1] return this.name || this.toString().match(/function\s*([^(]*)\(/)[1]
} }
class PAPI { class PAPI {
@@ -19,39 +20,41 @@ class PAPI {
} }
static registerPlayerPlaceholder(func, PluginName, PAPIName) { static registerPlayerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName());
ll.export(func, PluginName, func.getName()) return PlaceholderAPI.registerPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName);
PAPIregisterPlayerPlaceholderAPI(PluginName, func.getName(), PAPIName)
} }
static registerServerPlaceholder(func, PluginName, PAPIName) { static registerServerPlaceholder(func, PluginName, PAPIName) {
ll.export(func, PluginName, func.getName()) ll.export(func, PluginName, func.getName());
PAPIregisterServerPlaceholderAPI(PluginName, func.getName(), PAPIName) return PlaceholderAPI.registerServerPlaceholderAPI(PluginName, func.getName(), PAPIName);
} }
static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) { static registerStaticPlaceholder(func, PluginName, PAPIName, UpdateInterval = 50) {
ll.export(func, PluginName, func.getName()) ll.export(func, PluginName, func.getName());
PAPIregisterStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval) return PlaceholderAPI.registerStaticPlaceholderAPI(PluginName, func.getName(), PAPIName, UpdateInterval);
} }
static getValue(key) { static getValue(key) {
return PAPIgetValueAPI(key) return PlaceholderAPI.getValueAPI(key);
} }
static getValueByPlayer(key, xuid) { static getValueByPlayer(key, pl) {
return PAPIgetValueByPlayerAPI(key, xuid) return PlaceholderAPI.getValueByPlayerAPI(key, pl);
} }
static translateString(str, xuid = "") { static translateString(str, pl = null) {
return PAPItranslateStringAPI(str, xuid) if (pl) {
return PlaceholderAPI.translateStringWithPlayerAPI(str, pl);
}
return PlaceholderAPI.translateStringAPI(str);
} }
static unRegisterPlaceholder(str) { static unRegisterPlaceholder(str) {
return PAPIunRegisterPlaceholderAPI(str) return PlaceholderAPI.unRegisterPlaceholderAPI(str);
} }
static getAllPAPI() { static getAllPAPI() {
return PAPIgetAllPAPI(); return PlaceholderAPI.getAllPAPI();
} }
} }
+29
View File
@@ -0,0 +1,29 @@
const CallEvent = ll.import("GMLIB_API", "callCustomEvent");
let NextEventId = 0;
function getNextEventId() {
NextEventId++;
return "GMLIB_Event_" + NextEventId;
}
class Event {
constructor() {
throw new Error("Static class cannot be instantiated");
}
static listen(event, callback) {
let eventId = getNextEventId();
ll.export(callback, event, eventId);
let result = CallEvent(event, eventId);
if (!result) {
logger.error(`Cannot listen event "${event}"!`);
logger.error(`Event "${event}" No Found!`);
}
return result;
}
}
module.exports = {
Event
};
+74 -14
View File
@@ -6,10 +6,17 @@ const GMLIB_API = {
sendFloatingText: ll.import("GMLIB_API", "sendFloatingText"), sendFloatingText: ll.import("GMLIB_API", "sendFloatingText"),
removeFloatingTextFromPlayer: ll.import("GMLIB_API", "removeFloatingTextFromPlayer"), removeFloatingTextFromPlayer: ll.import("GMLIB_API", "removeFloatingTextFromPlayer"),
removeFloatingText: ll.import("GMLIB_API", "removeFloatingText"), removeFloatingText: ll.import("GMLIB_API", "removeFloatingText"),
updateClientFloatingTextData: ll.import("GMLIB_API", "updateClientFloatingTextData"),
updateAllClientsFloatingTextData: ll.import("GMLIB_API", "updateAllClientsFloatingTextData"),
getServerMspt: ll.import("GMLIB_API", "getServerMspt"), getServerMspt: ll.import("GMLIB_API", "getServerMspt"),
getServerCurrentTps: ll.import("GMLIB_API", "getServerCurrentTps"), getServerCurrentTps: ll.import("GMLIB_API", "getServerCurrentTps"),
getServerAverageTps: ll.import("GMLIB_API", "getServerAverageTps"), getServerAverageTps: ll.import("GMLIB_API", "getServerAverageTps"),
getAllPlayerUuids: ll.import("GMLIB_API", "getAllPlayerUuids"), getAllPlayerUuids: ll.import("GMLIB_API", "getAllPlayerUuids"),
getPlayerNbt: ll.import("GMLIB_API", "getPlayerNbt"),
setPlayerNbt: ll.import("GMLIB_API", "setPlayerNbt"),
setPlayerNbtTags: ll.import("GMLIB_API", "setPlayerNbtTags"),
resourcePackTranslate: ll.import("GMLIB_API", "resourcePackTranslate"),
chooseResourcePackI18nLanguage: ll.import("GMLIB_API", "chooseResourcePackI18nLanguage"),
setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"), setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"),
registerAbilityCommand: ll.import("GMLib_ServerAPI", "registerAbilityCommand"), registerAbilityCommand: ll.import("GMLib_ServerAPI", "registerAbilityCommand"),
setEnableAchievement: ll.import("GMLib_ServerAPI", "setEnableAchievement"), setEnableAchievement: ll.import("GMLib_ServerAPI", "setEnableAchievement"),
@@ -28,14 +35,17 @@ const GMLIB_API = {
getExperimentEnabled: ll.import("GMLib_ModAPI", "getExperimentEnabled"), getExperimentEnabled: ll.import("GMLib_ModAPI", "getExperimentEnabled"),
setExperimentEnabled: ll.import("GMLib_ModAPI", "setExperimentEnabled"), setExperimentEnabled: ll.import("GMLib_ModAPI", "setExperimentEnabled"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerExperimentsRequire"), registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerExperimentsRequire"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerStoneCutterRecipe"), registerStoneCutterRecipe: ll.import("GMLib_ModAPI", "registerStoneCutterRecipe"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerSmithingTrimRecipe"), registerSmithingTrimRecipe: ll.import("GMLib_ModAPI", "registerSmithingTrimRecipe"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerSmithingTransformRecipe"), registerSmithingTransformRecipe: ll.import("GMLib_ModAPI", "registerSmithingTransformRecipe"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerBrewingContainerRecipe"), registerBrewingContainerRecipe: ll.import("GMLib_ModAPI", "registerBrewingContainerRecipe"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerBrewingMixRecipe"), registerBrewingMixRecipe: ll.import("GMLib_ModAPI", "registerBrewingMixRecipe"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerFurnaceRecipe"), registerFurnaceRecipe: ll.import("GMLib_ModAPI", "registerFurnaceRecipe"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerShapedRecipe"), registerShapedRecipe: ll.import("GMLib_ModAPI", "registerShapedRecipe"),
registerExperimentsRequire: ll.import("GMLib_ModAPI", "registerShapelessRecipe") registerShapelessRecipe: ll.import("GMLib_ModAPI", "registerShapelessRecipe"),
isVersionMatched: ll.import("GMLIB_API", "isVersionMatched"),
getVersion_LRCA: ll.import("GMLIB_API", "getVersion_LRCA"),
getVersion_GMLIB: ll.import("GMLIB_API", "getVersion_GMLIB")
} }
const FloatingTextList = []; const FloatingTextList = [];
@@ -69,6 +79,14 @@ class StaticFloatingText {
return GMLIB_API.removeFloatingText(this.mRuntimeId); return GMLIB_API.removeFloatingText(this.mRuntimeId);
} }
updateClient(player) {
return GMLIB_API.updateClientFloatingTextData(this.mRuntimeId, player);
}
updateClients() {
return GMLIB_API.updateAllClientsFloatingTextData(this.mRuntimeId);
}
getRuntimeId() { getRuntimeId() {
return this.mRuntimeId; return this.mRuntimeId;
} }
@@ -83,7 +101,7 @@ class StaticFloatingText {
update() { update() {
GMLIB_API.setFloatingTextData(this.mRuntimeId, this.mText); GMLIB_API.setFloatingTextData(this.mRuntimeId, this.mText);
return this.sendToClients(); return this.updateClients();
} }
updateText(newText) { updateText(newText) {
@@ -106,13 +124,13 @@ class StaticFloatingText {
} }
static getFloatingText(runtimeId) { static getFloatingText(runtimeId) {
FloatingTextList.forEach((ft) => { for (const ft of FloatingTextList) {
if (ft.getRuntimeId() == runtimeId) { if (ft.getRuntimeId() == runtimeId) {
if (!ft.isDynamic()) { if (!ft.isDynamic()) {
return ft; return ft;
} }
} }
}); }
return null; return null;
} }
@@ -175,13 +193,13 @@ class DynamicFloatingText extends StaticFloatingText {
} }
static getFloatingText(runtimeId) { static getFloatingText(runtimeId) {
FloatingTextList.forEach((ft) => { for (const ft of FloatingTextList) {
if (ft.getRuntimeId() == runtimeId) { if (ft.getRuntimeId() == runtimeId) {
if (ft.isDynamic()) { if (ft.isDynamic()) {
return ft; return ft;
} }
} }
}); }
return null; return null;
} }
@@ -217,6 +235,22 @@ class Minecraft {
return GMLIB_API.getAllPlayerUuids(); 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() { static setEducationFeatureEnabled() {
return GMLIB_API.setEducationFeatureEnabled(); return GMLIB_API.setEducationFeatureEnabled();
} }
@@ -268,6 +302,14 @@ class Minecraft {
static throwEntity(entity, proj, speed = 2, offset = 3) { static throwEntity(entity, proj, speed = 2, offset = 3) {
return GMLIB_API.throwEntity(entity, proj, speed = 2, offset = 3); return GMLIB_API.throwEntity(entity, proj, speed = 2, offset = 3);
} }
static chooseResourcePackI18nLanguage(language) {
return GMLIB_API.chooseResourcePackI18nLanguage(language);
}
static resourcePackTranslate(key, params = []) {
return GMLIB_API.resourcePackTranslate(key, params);
}
} }
class Recipes { class Recipes {
@@ -346,4 +388,22 @@ class Experiments {
} }
} }
module.exports = { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments }; class GMLIB {
constructor() {
throw new Error("Static class cannot be instantiated");
}
static isVersionMatched(major, minor, patch) {
return GMLIB_API.isVersionMatched(major, minor, patch);
}
static getVersion_LRCA() {
return GMLIB_API.getVersion_LRCA();
}
static getVersion_GMLIB() {
return GMLIB_API.getVersion_GMLIB();
}
}
module.exports = { StaticFloatingText, DynamicFloatingText, Minecraft, Recipes, Experiments, GMLIB };
+50
View File
@@ -25,6 +25,24 @@ void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> { RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
return GMLIB_Player::getAllUuids(); 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> { RemoteCall::exportAs("GMLIB_API", "getAllExperiments", []() -> std::vector<int> {
auto map = GMLIB_Level::getAllExperiments(); auto map = GMLIB_Level::getAllExperiments();
std::vector<int> result; std::vector<int> result;
@@ -91,4 +109,36 @@ void Export_Compatibility_API() {
} }
return false; 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);
});
RemoteCall::exportAs("GMLIB_API", "getVersion_LRCA", []() -> std::string { return LIB_VERSION.asString(); });
RemoteCall::exportAs("GMLIB_API", "getVersion_GMLIB", []() -> std::string {
return GMLIB::Version::getLibVersionString();
});
RemoteCall::exportAs(
"GMLIB_API",
"resourcePackTranslate",
[](std::string key, std::vector<std::string> params) -> std::string { return I18n::get(key, params); }
);
RemoteCall::exportAs("GMLIB_API", "chooseResourcePackI18nLanguage", [](std::string code) -> void {
I18n::chooseLanguage(code);
});
} }
-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
+58
View File
@@ -0,0 +1,58 @@
#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();
Export_Event_API();
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
+162
View File
@@ -0,0 +1,162 @@
#include "Global.h"
using namespace ll::hash_utils;
void Export_Event_API() {
auto eventBus = &ll::event::EventBus::getInstance();
RemoteCall::exportAs(
"GMLIB_API",
"callCustomEvent",
[eventBus](std::string eventName, std::string eventId) -> bool {
if (RemoteCall::hasFunc(eventName, eventId)) {
switch (doHash(eventName)) {
case doHash("onClientLogin"): {
auto Call = RemoteCall::importAs<
bool(std::string realName, std::string uuid, std::string serverXuid, std::string clientXuid)>(
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::PacketEvent::ClientLoginAfterEvent>(
[Call](GMLIB::Event::PacketEvent::ClientLoginAfterEvent& ev) {
try {
Call(
ev.getRealName(),
ev.getUuid().asString(),
ev.getServerAuthXuid(),
ev.getClientAuthXuid()
);
} catch (...) {}
}
);
return true;
}
case doHash("onWeatherChange"): {
auto Call =
RemoteCall::importAs<bool(int lightningLevel, int rainLevel, int lightningLast, int rainLast)>(
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent>(
[Call](GMLIB::Event::LevelEvent::WeatherUpdateBeforeEvent& ev) {
bool result = true;
try {
result = Call(
ev.getLightningLevel(),
ev.getRainLevel(),
ev.getLightningLastTick(),
ev.getRainingLastTick()
);
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onMobPick"): {
auto Call = RemoteCall::importAs<bool(Actor * mob, Actor * item)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::MobPickupItemBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self(), (Actor*)&ev.getItemActor());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onItemTrySpawn"): {
auto Call = RemoteCall::importAs<
bool(const ItemStack* item, std::pair<Vec3, int> position, Actor* spawner)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent>(
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnBeforeEvent& ev) {
auto pos = ev.getPosition();
auto dimid = ev.getBlockSource().getDimensionId().id;
std::pair<Vec3, int> lsePos = {pos, dimid};
bool result = true;
try {
result = Call(&ev.getItem(), lsePos, ev.getSpawner());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onItemSpawned"): {
auto Call = RemoteCall::importAs<
bool(const ItemStack* item, Actor* itemActor, std::pair<Vec3, int> position, Actor* spawner)>(
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent>(
[Call](GMLIB::Event::EntityEvent::ItemActorSpawnAfterEvent& ev) {
auto pos = ev.getPosition();
auto dimid = ev.getBlockSource().getDimensionId().id;
std::pair<Vec3, int> lsePos = {pos, dimid};
try {
Call(&ev.getItem(), (Actor*)&ev.getItemActor(), lsePos, ev.getSpawner());
} catch (...) {}
}
);
return true;
}
case doHash("onTextSend"): {
auto Call = RemoteCall::importAs<bool(std::string author, std::string message)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::PacketEvent::TextPacketSendBeforeEvent>(
[Call](GMLIB::Event::PacketEvent::TextPacketSendBeforeEvent& ev) {
auto pkt = ev.getPacket();
bool result = true;
try {
result = Call(pkt.mAuthor, pkt.mMessage);
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onLeaveBed"): {
auto Call = RemoteCall::importAs<bool(Player * pl)>(eventName, eventId);
eventBus->emplaceListener<GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent>(
[Call](GMLIB::Event::PlayerEvent::PlayerStopSleepBeforeEvent& ev) {
bool result = true;
try {
result = Call(&ev.self());
} catch (...) {}
if (!result) {
ev.cancel();
}
}
);
return true;
}
case doHash("onDeathMessage"): {
auto Call = RemoteCall::importAs<bool(std::string message, std::vector<std::string>, Actor * dead)>(
eventName,
eventId
);
eventBus->emplaceListener<GMLIB::Event::EntityEvent::DeathMessageAfterEvent>(
[Call](GMLIB::Event::EntityEvent::DeathMessageAfterEvent& ev) {
auto msg = ev.getDeathMessage();
auto source = ev.getDamageSource();
try {
Call(msg.first, msg.second, &ev.self());
} catch (...) {}
}
);
return true;
}
default:
return false;
}
}
return false;
}
);
}
+4 -1
View File
@@ -1,8 +1,10 @@
#pragma once #pragma once
#include <GMLIB/include_lib.h> #include <include_all.h>
#include <RemoteCallAPI.h> #include <RemoteCallAPI.h>
#define PLUGIN_NAME "GMLIB-LRCA" #define PLUGIN_NAME "GMLIB-LRCA"
#define LIB_VERSION SemVersion(0, 9, 1, "", "")
extern ll::Logger logger; extern ll::Logger logger;
@@ -10,3 +12,4 @@ extern void Export_Legacy_GMLib_ModAPI();
extern void Export_Legacy_GMLib_ServerAPI(); extern void Export_Legacy_GMLib_ServerAPI();
extern void Export_Compatibility_API(); extern void Export_Compatibility_API();
extern void ExportPAPI(); extern void ExportPAPI();
extern void Export_Event_API();
+8 -8
View File
@@ -33,7 +33,7 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto res = RecipeIngredient(result, 0, count); auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock); auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::CustomRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl); GMLIB::Mod::JsonRecipe::registerShapelessCraftingTableRecipe(recipe_id, types, res, unl);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -56,7 +56,7 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto res = RecipeIngredient(result, 0, count); auto res = RecipeIngredient(result, 0, count);
auto unl = makeRecipeUnlockingKey(unlock); auto unl = makeRecipeUnlockingKey(unlock);
GMLIB::Mod::CustomRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl); GMLIB::Mod::JsonRecipe::registerShapedCraftingTableRecipe(recipe_id, shape, types, res, unl);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -69,7 +69,7 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags); GMLIB::Mod::JsonRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -81,7 +81,7 @@ void Export_Legacy_GMLib_ModAPI() {
return; return;
} }
auto rea = RecipeIngredient(reagent, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea); GMLIB::Mod::JsonRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -95,7 +95,7 @@ void Export_Legacy_GMLib_ModAPI() {
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
auto rea = RecipeIngredient(reagent, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::CustomRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea); GMLIB::Mod::JsonRecipe::registerBrewingContainerRecipe(recipe_id, inp, outp, rea);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -110,7 +110,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) { if (!level) {
return; return;
} }
GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe( GMLIB::Mod::JsonRecipe::registerSmithingTransformRecipe(
recipe_id, recipe_id,
smithing_template, smithing_template,
base, base,
@@ -127,7 +127,7 @@ void Export_Legacy_GMLib_ModAPI() {
if (!level) { if (!level) {
return; return;
} }
GMLIB::Mod::CustomRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition); GMLIB::Mod::JsonRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
} }
); );
RemoteCall::exportAs( RemoteCall::exportAs(
@@ -145,7 +145,7 @@ void Export_Legacy_GMLib_ModAPI() {
} }
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::CustomRecipe::registerStoneCutterRecipe(recipe_id, inp, outp); GMLIB::Mod::JsonRecipe::registerStoneCutterRecipe(recipe_id, inp, outp);
} }
); );
// 错误方块清理 // 错误方块清理
+1 -5
View File
@@ -27,11 +27,7 @@ void Export_Legacy_GMLib_ServerAPI() {
return level->setLevelName(name); return level->setLevelName(name);
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void { RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
auto level = GMLIB_Level::getLevel(); return GMLIB_Level::setFakeSeed(seed);
if (!level) {
return;
}
return level->setFakeSeed(seed);
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair<Vec3, int> pos, std::string name) -> Actor* { RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair<Vec3, int> pos, std::string name) -> Actor* {
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name); return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name);
+48 -82
View File
@@ -3,114 +3,79 @@
namespace PAPIRemoteCall { 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 GetValue(std::string const& from) { return GMLIB::Server::PlaceholderAPI::getValue(from); }
std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) { std::string GetValueWithPlayer(std::string const& a1, std::string const& a2) {
return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2)); return GMLIB::Server::PlaceholderAPI::getValue(a1, ll::service::bedrock::getLevel()->getPlayer(a2));
} }
std::string bool registerPlayerPlaceholder(
registerPlayerPlaceholder(std::string const& PluginName, std::string const& FuncName, std::string const& PAPIName) { std::string const& PluginName,
std::string const& FuncName,
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) { if (RemoteCall::hasFunc(PluginName, FuncName)) {
if (isParameters(PAPIName)) { auto Call = RemoteCall::importAs<std::string(Player * pl)>(PluginName, FuncName);
auto Call = GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder(
RemoteCall::importAs<std::string(std::string const& arg, std::unordered_map<std::string, std::string>)>( PAPIName,
PluginName, [Call](Player* sp) { return Call(sp); },
FuncName PluginName
); );
GMLIB::Server::PlaceholderAPI::registerPlayerPlaceholder( return true;
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"; return false;
} }
std::string bool registerServerPlaceholder(
registerServerPlaceholder(std::string const& PluginName, std::string const& FuncName, std::string const& PAPIName) { std::string const& PluginName,
std::string const& FuncName,
std::string const& PAPIName
) {
if (RemoteCall::hasFunc(PluginName, FuncName)) { if (RemoteCall::hasFunc(PluginName, FuncName)) {
if (isParameters(PAPIName)) { auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
auto Call = GMLIB::Server::PlaceholderAPI::registerServerPlaceholder(
RemoteCall::importAs<std::string(std::unordered_map<std::string, std::string>)>(PluginName, FuncName); PAPIName,
GMLIB::Server::PlaceholderAPI::registerServerPlaceholder( [Call]() { return Call(); },
PAPIName, PluginName
[Call](std::unordered_map<std::string, std::string> map) { return Call(map); }, );
PluginName return true;
);
} 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"; return false;
} }
std::string registerStaticPlaceholder( bool registerStaticPlaceholder(
std::string const& PluginName, std::string const& PluginName,
std::string const& FuncName, std::string const& FuncName,
std::string const& PAPIName, std::string const& PAPIName,
int num int num
) { ) {
if (RemoteCall::hasFunc(PluginName, FuncName)) { if (RemoteCall::hasFunc(PluginName, FuncName)) {
if (isParameters(PAPIName)) { auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName);
auto Call = RemoteCall::importAs<std::string()>(PluginName, FuncName); if (num == -1) {
if (num == -1) { GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder( PAPIName,
PAPIName, [Call] { return Call(); },
[Call] { return Call(); }, PluginName
PluginName );
); } else {
} else { GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder(
GMLIB::Server::PlaceholderAPI::registerStaticPlaceholder( PAPIName,
PAPIName, num,
num, [Call] { return Call(); },
[Call] { return Call(); }, PluginName
PluginName );
);
}
} }
} else { return true;
// logger.error("Function no find({}:{})", PluginName, FuncName);
return "Function no find";
} }
return "Register Success"; return false;
} }
std::string translateString(std::string const& str, std::string const& xuid) { std::string translateStringWithPlayer(std::string const& str, Player* pl) {
return GMLIB::Server::PlaceholderAPI::translate(str, ll::service::bedrock::getLevel()->getPlayerByXuid(xuid)); 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); } bool unRegisterPlaceholder(std::string const& str) { return GMLIB::Server::PlaceholderAPI::unRegisterPlaceholder(str); }
std::vector<std::string> getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); } std::vector<std::string> getAllPAPI() { return GMLIB::Server::PlaceholderAPI::getAllPAPI(); }
@@ -127,6 +92,7 @@ void ExportPAPI() {
EXPORTAPI(PAPIRemoteCall::GetValue); EXPORTAPI(PAPIRemoteCall::GetValue);
EXPORTAPI(PAPIRemoteCall::GetValueWithPlayer); EXPORTAPI(PAPIRemoteCall::GetValueWithPlayer);
EXPORTAPI(PAPIRemoteCall::translateString); EXPORTAPI(PAPIRemoteCall::translateString);
EXPORTAPI(PAPIRemoteCall::translateStringWithPlayer);
EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder); EXPORTAPI(PAPIRemoteCall::unRegisterPlaceholder);
EXPORTAPI(PAPIRemoteCall::getAllPAPI); EXPORTAPI(PAPIRemoteCall::getAllPAPI);
} }
-29
View File
@@ -1,29 +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("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
+8 -7
View File
@@ -1,21 +1,22 @@
{ {
"format_version": 2, "format_version": 2,
"tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"version": "0.8.2", "version": "0.9.3",
"info": { "info": {
"name": "GMLIB-LegacyRemoteCallApi", "name": "GMLIB-LegacyRemoteCallApi",
"description": "Legacy RemoteCall API for GMLIB", "description": "Legacy RemoteCall API for GMLIB",
"source": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi",
"author": "GroupMountain", "author": "GroupMountain",
"tags": [ "tags": [
"LeviLamina", "levilamina",
"GMLIB", "gmlib",
"GMLIB-LegacyRemoteCallApi", "lse",
"Library" "library"
] ]
}, },
"asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.8.2/GMLIB-LegacyRemoteCallApi-windows-x64.zip", "asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.9.3/GMLIB-LegacyRemoteCallApi-windows-x64.zip",
"dependencies": { "dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.8.1" "github.com/GroupMountain/GMLIB": ">=0.9.6"
}, },
"files": { "files": {
"place": [ "place": [