fix: fix some api error

This commit is contained in:
Tsubasa6848
2024-02-26 19:27:57 +08:00
Unverified
parent 1bd3270ecf
commit 030535defd
5 changed files with 84 additions and 14 deletions
+39 -5
View File
@@ -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();
}
+43
View File
@@ -25,6 +25,33 @@ 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);
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<int> {
auto map = GMLIB_Level::getAllExperiments();
std::vector<int> 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);
+1 -1
View File
@@ -1,5 +1,5 @@
#pragma once
#include <GMLIB/include_lib.h>
#include <include_all.h>
#include <RemoteCallAPI.h>
#define PLUGIN_NAME "GMLIB-LRCA"
-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>