diff --git a/SDK-GMLIB b/SDK-GMLIB index 58cec5c..30d1c87 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit 58cec5c0c5eeae94593df1235419fd180ea4a261 +Subproject commit 30d1c8786cd49eddb167c93ea31a06276be1c6df diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index fc743f5..b9d9d8c 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -6,10 +6,16 @@ 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"), + tryGetNameFormUuid: ll.import("GMLIB_API", "tryGetNameFormUuid"), setEducationFeatureEnabled: ll.import("GMLib_ServerAPI", "setEducationFeatureEnabled"), registerAbilityCommand: ll.import("GMLib_ServerAPI", "registerAbilityCommand"), setEnableAchievement: ll.import("GMLib_ServerAPI", "setEnableAchievement"), @@ -72,6 +78,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 +100,7 @@ class StaticFloatingText { update() { GMLIB_API.setFloatingTextData(this.mRuntimeId, this.mText); - return this.sendToClients(); + return this.updateClients(); } updateText(newText) { @@ -109,13 +123,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 +192,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 +234,26 @@ 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 tryGetNameFormUuid(uuid) { + return GMLIB_API.tryGetNameFormUuid(uuid); + } + static setEducationFeatureEnabled() { return GMLIB_API.setEducationFeatureEnabled(); } diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index b694042..26fbd61 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -25,6 +25,33 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector { 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 tags) -> bool { + auto uid = mce::UUID::fromString(uuid); + auto nbt = CompoundTag::fromSnbt(snbt); + logger.error("call"); + return GMLIB_Player::setPlayerNbtTags(uid, *nbt, tags); + } + ); + RemoteCall::exportAs("GMLIB_API", "tryGetNameFormUuid", [](std::string uuid) -> std::string { + auto uid = mce::UUID::fromString(uuid); + auto info = ll::service::PlayerInfo::getInstance().fromUuid(uid); + if (info) { + return info->name; + } + return ""; + }); RemoteCall::exportAs("GMLIB_API", "getAllExperiments", []() -> std::vector { auto map = GMLIB_Level::getAllExperiments(); std::vector result; @@ -91,6 +118,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); diff --git a/src/Global.h b/src/Global.h index b902602..0599c1d 100644 --- a/src/Global.h +++ b/src/Global.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #define PLUGIN_NAME "GMLIB-LRCA" diff --git a/src/MemoryOperators.cc b/src/MemoryOperators.cc deleted file mode 100644 index f7c918a..0000000 --- a/src/MemoryOperators.cc +++ /dev/null @@ -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