diff --git a/lib/GMLIB_API-JS.d.ts b/lib/GMLIB_API-JS.d.ts index 2310392..7aba899 100644 --- a/lib/GMLIB_API-JS.d.ts +++ b/lib/GMLIB_API-JS.d.ts @@ -1078,12 +1078,12 @@ export class UserCache { /** 获取玩家信息 */ static getPlayerInfo( - /** 玩家名 或 xuid 或 uuid */ + /** 玩家名 或 xuid 或 uuid 或 serverId 或 uniqueId */ playerIdentifier: string - ): { Xuid: String, Uuid: string, Name: string } | null; + ): { Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string } | null; /** 获取所有玩家信息 */ - static getAllPlayerInfo(): { Xuid: String; Uuid: string; Name: string; }[] + static getAllPlayerInfo(): { Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string }[] } type PacketDataItem = ( diff --git a/lib/GMLIB_API-JS.js b/lib/GMLIB_API-JS.js index 81d2ddf..a2cdcae 100644 --- a/lib/GMLIB_API-JS.js +++ b/lib/GMLIB_API-JS.js @@ -216,7 +216,9 @@ const GMLIB_API = { getXuidByName: ll.imports("GMLIB_API", "getXuidByName"), /** 根据名字获取uuid @type {function(string):string} */ getUuidByName: ll.imports("GMLIB_API", "getUuidByName"), - /** 获取所有已记录的玩家信息 @type {function():Array.<{"Uuid":string,"Xuid":string,"Name":string}>} */ + /** 根据信息获取玩家信息 @type {function():{"Uuid":string,"Xuid":string,"Name":string,"ServerId":string,"ActorUniqueID":string}} */ + getPlayerInfo: ll.imports("GMLIB_API", "getPlayerInfo"), + /** 获取所有已记录的玩家信息 @type {function():Array.<{"Uuid":string,"Xuid":string,"Name":string,"ServerId":string,"ActorUniqueID":string}>} */ getAllPlayerInfo: ll.imports("GMLIB_API", "getAllPlayerInfo"), /** 获取方块RuntimeId @type {function(string,number):number} */ getBlockRuntimeId: ll.imports("GMLIB_API", "getBlockRuntimeId"), @@ -2107,16 +2109,17 @@ class UserCache { /** * 获取玩家信息 - * @param {string} playerIdentifier 玩家的 xuid 或 uuid 或 名称 - * @returns {{Xuid: String, Uuid: string, Name: string}?} 玩家信息 + * @param {string} playerIdentifier 玩家的 xuid 或 uuid 或 realName 或 serverId 或 uniqueId + * @returns {{Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string}?} 玩家信息 */ static getPlayerInfo(playerIdentifier) { - return GMLIB_API.getAllPlayerInfo().find(Info => Object.keys(Info).some(InfoKey => Info[InfoKey] === playerIdentifier)); + const result = GMLIB_API.getPlayerInfo(playerIdentifier) + return Object.keys(result).length === 0 ? null : result; } /** * 获取所有玩家信息 - * @returns {Array.<{Xuid: String, Uuid: string, Name: string}>} 包含所有玩家信息的数组 + * @returns {Array.<{Xuid: string, Uuid: string, Name: string, ServerId: string, ActorUniqueID: string}>} 包含所有玩家信息的数组 */ static getAllPlayerInfo() { return GMLIB_API.getAllPlayerInfo(); diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index fa037a3..28c89be 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -532,17 +532,46 @@ void Export_Compatibility_API() { } return ""; }); + RemoteCall::exportAs( + "GMLIB_API", + "getPlayerInfo", + [](std::string const& info) -> std::unordered_map { + // TODO: 下个GMLIB更新直接改成from(info, UserCache::QueryType::All) + std::unordered_map result; + if (auto uce = UserCache::getInstance()->from(mce::UUID::fromString(info))) { + ll::reflection::forEachMember(*uce, [&](std::string_view name, auto&& member) { + result[std::string{name.substr(1)}] = fmt::to_string(member); + }); + return result; + } + if (auto uniqeuId = ll::string_utils::svtoll(info); uniqeuId) { + if (auto uce = UserCache::getInstance()->from(ActorUniqueID{*uniqeuId})) { + ll::reflection::forEachMember(*uce, [&](std::string_view name, auto&& member) { + result[std::string{name.substr(1)}] = fmt::to_string(member); + }); + return result; + } + } + if (auto uce = UserCache::getInstance()->from(info, UserCache::QueryType::Default)) { + ll::reflection::forEachMember(*uce, [&](std::string_view name, auto&& member) { + result[std::string{name.substr(1)}] = fmt::to_string(member); + }); + return result; + } + return result; + } + ); RemoteCall::exportAs( "GMLIB_API", "getAllPlayerInfo", []() -> std::vector> { std::vector> result; - for (auto entry : UserCache::getInstance()->entries()) { - result.push_back({ - {"Name", entry.mName }, - {"Xuid", entry.mXuid }, - {"Uuid", entry.mUuid.asString()} + for (auto& entry : UserCache::getInstance()->entries()) { + std::unordered_map item; + ll::reflection::forEachMember(entry, [&](std::string_view name, auto&& member) { + item[std::string{name.substr(1)}] = fmt::to_string(member); }); + result.emplace_back(std::move(item)); } return result; } diff --git a/src/Global.h b/src/Global.h index c247e8b..8c63435 100644 --- a/src/Global.h +++ b/src/Global.h @@ -3,9 +3,6 @@ #pragma warning(push) #pragma warning(disable : 4996) #pragma include_alias("mc/world/item/HumanoidArmorItem.h", "modapi/item/types/mc/HumanoidArmorItem.h") -#pragma include_alias("mc/world/level/block/states/BuiltInBlockStateVariant.h", "mc/BuiltInBlockStateVariant.h") -#pragma include_alias("mc/world/events/EventCoordinatorPimpl.h", "mc/EventCoordinatorPimpl.h") -#pragma include_alias("mc/world/events/PlayerNotificationEvent.h", "mc/PlayerNotificationEvent.h") #include #include #include @@ -25,8 +22,8 @@ using namespace modapi; #define PLUGIN_NAME fmt::format(fg(fmt::color::light_green), "GMLIB-LRCA") #define LIB_VERSION_MAJOR 1 -#define LIB_VERSION_MINOR 6 -#define LIB_VERSION_PATCH 0 +#define LIB_VERSION_MINOR 7 +#define LIB_VERSION_PATCH 1 #define LIB_VERSION_PRERELEASE std::nullopt #ifdef LIB_VERSION_PRERELEASE @@ -43,4 +40,20 @@ extern void Export_Event_API(); extern void Export_BinaryStream_API(); extern ll::thread::ThreadPoolExecutor const& getThreadPoolExecutor(); extern ll::io::Logger& getLogger(); -// extern void Export_Form_API(); \ No newline at end of file +// extern void Export_Form_API(); + + +template <> +struct fmt::formatter : fmt::formatter { + template + auto format(ActorUniqueID const& t, FormatContext& ctx) const { + return formatter::format(t.rawID, ctx); + } +}; +template <> +struct fmt::formatter : fmt::formatter { + template + auto format(mce::UUID const& t, FormatContext& ctx) const { + return formatter::format(t.asString(), ctx); + } +}; \ No newline at end of file diff --git a/src/mc/BuiltInBlockStateVariant.h b/src/mc/BuiltInBlockStateVariant.h deleted file mode 100644 index 0accb29..0000000 --- a/src/mc/BuiltInBlockStateVariant.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "mc/_HeaderOutputPredefine.h" -#include "mc/world/level/block/states/BlockStateVariant.h" - -template -class BuiltInBlockStateVariant : public ::BlockStateVariant { -public: - // virtual functions - // NOLINTBEGIN - // vIndex: 0 - virtual ~BuiltInBlockStateVariant() /*override*/ = default; - // NOLINTEND -}; diff --git a/src/mc/EventCoordinatorPimpl.h b/src/mc/EventCoordinatorPimpl.h deleted file mode 100644 index aff3f6f..0000000 --- a/src/mc/EventCoordinatorPimpl.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "mc/_HeaderOutputPredefine.h" -#include "mc/deps/core/utility/EnableNonOwnerReferences.h" -#include "mc/world/events/EventResult.h" - -template -class EventCoordinatorPimpl : Bedrock::EnableNonOwnerReferences { -public: - using EventFuncPtr = std::function; - - std::vector mListeners; - std::vector mEventsToProcess; - std::vector mPendingRegistrations; - bool mHasPendingRegistrations; - std::thread::id mThreadId; - bool mThreadIdInitialized; - uint mThreadCheckIndex; - - // // ServerInstanceEventListener - // virtual ~EventCoordinatorPimpl(); - - // // ServerInstanceEventListener - // MCAPI bool registerListener(gsl::not_null); - - // // ScriptingEventListener - // MCAPI void processEvent(EventFuncPtr); - - // // ActorEventListener - // MCAPI void unregisterListener(gsl::not_null); -}; diff --git a/src/mc/PlayerNotificationEvent.h b/src/mc/PlayerNotificationEvent.h deleted file mode 100644 index 4c11a95..0000000 --- a/src/mc/PlayerNotificationEvent.h +++ /dev/null @@ -1,139 +0,0 @@ -#pragma once - -#include "mc/_HeaderOutputPredefine.h" -#include "mc/world/events/PlayerAddEvent.h" -#include "mc/world/events/PlayerAddExpEvent.h" -#include "mc/world/events/PlayerAddLevelEvent.h" -#include "mc/world/events/PlayerArmorExchangeEvent.h" -#include "mc/world/events/PlayerDamageEvent.h" -#include "mc/world/events/PlayerDestroyBlockEvent.h" -#include "mc/world/events/PlayerDimensionChangeAfterEvent.h" -#include "mc/world/events/PlayerDimensionChangeBeforeEvent.h" -#include "mc/world/events/PlayerDisconnectEvent.h" -#include "mc/world/events/PlayerDropItemEvent.h" -#include "mc/world/events/PlayerEatFoodEvent.h" -#include "mc/world/events/PlayerEmoteEvent.h" -#include "mc/world/events/PlayerFormCloseEvent.h" -#include "mc/world/events/PlayerFormResponseEvent.h" -#include "mc/world/events/PlayerGameModeChangeEvent.h" -#include "mc/world/events/PlayerGetExperienceOrbEvent.h" -#include "mc/world/events/PlayerInitialSpawnEvent.h" -#include "mc/world/events/PlayerInputModeChangeEvent.h" -#include "mc/world/events/PlayerInputPermissionCategoryChangeEvent.h" -#include "mc/world/events/PlayerInteractEvent.h" -#include "mc/world/events/PlayerInteractWithBlockAfterEvent.h" -#include "mc/world/events/PlayerInteractWithBlockBeforeEvent.h" -#include "mc/world/events/PlayerInteractWithEntityAfterEvent.h" -#include "mc/world/events/PlayerInteractWithEntityBeforeEvent.h" -#include "mc/world/events/PlayerOpenContainerEvent.h" -#include "mc/world/events/PlayerRespawnEvent.h" -#include "mc/world/events/PlayerSayCommandEvent.h" -#include "mc/world/events/PlayerScriptInputEvent.h" -#include "mc/world/events/PlayerSelectedItemChangedEvent.h" -#include "mc/world/events/PlayerShootArrowEvent.h" -#include "mc/world/events/PlayerSkinLoadedClientEvent.h" -#include "mc/world/events/PlayerSleepStateChangeEvent.h" -#include "mc/world/events/PlayerStopLoadingEvent.h" -#include "mc/world/events/PlayerSwingStartEvent.h" -#include "mc/world/events/PlayerUpdateInteractionEvent.h" -#include "mc/world/events/PlayerUseNameTagEvent.h" - - -// auto generated inclusion list -#include "mc/world/events/EventVariantImpl.h" - -// auto generated forward declare list -// clang-format off -struct PlayerAddEvent; -struct PlayerAddExpEvent; -struct PlayerAddLevelEvent; -struct PlayerArmorExchangeEvent; -struct PlayerCloseContainerEvent; -struct PlayerDamageEvent; -struct PlayerDestroyBlockEvent; -struct PlayerDimensionChangeAfterEvent; -struct PlayerDimensionChangeBeforeEvent; -struct PlayerDisconnectEvent; -struct PlayerDropItemEvent; -struct PlayerEatFoodEvent; -struct PlayerEmoteEvent; -struct PlayerFormCloseEvent; -struct PlayerFormResponseEvent; -struct PlayerGameModeChangeEvent; -struct PlayerGetExperienceOrbEvent; -struct PlayerHotbarSelectedSlotChangeEvent; -struct PlayerInitialSpawnEvent; -struct PlayerInputModeChangeEvent; -struct PlayerInputPermissionCategoryChangeEvent; -struct PlayerInteractEvent; -struct PlayerInteractWithBlockAfterEvent; -struct PlayerInteractWithBlockBeforeEvent; -struct PlayerInteractWithEntityAfterEvent; -struct PlayerInteractWithEntityBeforeEvent; -struct PlayerInventoryItemChangeEvent; -struct PlayerOpenContainerEvent; -struct PlayerRespawnEvent; -struct PlayerSayCommandEvent; -struct PlayerScriptInputEvent; -struct PlayerSelectedItemChangedEvent; -struct PlayerShootArrowEvent; -struct PlayerSkinLoadedClientEvent; -struct PlayerSleepStateChangeEvent; -struct PlayerStopLoadingEvent; -struct PlayerSwingStartEvent; -struct PlayerUpdateInteractionEvent; -struct PlayerUseNameTagEvent; -// clang-format on - -struct PlayerNotificationEvent : public ::EventVariantImpl< - ::PlayerSkinLoadedClientEvent const, - ::PlayerAddEvent const, - ::PlayerAddExpEvent const, - ::PlayerAddLevelEvent const, - ::PlayerArmorExchangeEvent const, - ::PlayerDestroyBlockEvent const, - ::PlayerUseNameTagEvent const, - ::PlayerDropItemEvent const, - ::PlayerEatFoodEvent const, - ::PlayerDamageEvent const, - ::PlayerDisconnectEvent const, - ::PlayerFormCloseEvent const, - ::PlayerFormResponseEvent const, - ::PlayerInputModeChangeEvent const, - ::PlayerInitialSpawnEvent const, - ::PlayerOpenContainerEvent const, - ::PlayerCloseContainerEvent const, - ::PlayerShootArrowEvent const, - ::PlayerSwingStartEvent const, - ::PlayerRespawnEvent const, - ::PlayerSleepStateChangeEvent const, - ::PlayerStopLoadingEvent const, - ::PlayerUpdateInteractionEvent const, - ::PlayerSelectedItemChangedEvent const, - ::PlayerDimensionChangeBeforeEvent const, - ::PlayerDimensionChangeAfterEvent const, - ::PlayerInteractWithEntityAfterEvent const, - ::PlayerInteractWithBlockAfterEvent const, - ::PlayerEmoteEvent const, - ::PlayerScriptInputEvent const, - ::PlayerInventoryItemChangeEvent const, - ::PlayerHotbarSelectedSlotChangeEvent const, - ::PlayerInputPermissionCategoryChangeEvent const, - ::PlayerSayCommandEvent const, - ::PlayerGetExperienceOrbEvent const, - ::PlayerInteractEvent const, - ::PlayerInteractWithEntityBeforeEvent const, - ::PlayerInteractWithBlockBeforeEvent const, - ::PlayerGameModeChangeEvent const> { -public: - // member functions - // NOLINTBEGIN - MCAPI ~PlayerNotificationEvent(); - // NOLINTEND - -public: - // destructor thunk - // NOLINTBEGIN - MCAPI void $dtor(); - // NOLINTEND -}; diff --git a/tooth.json b/tooth.json index 4f65503..b893fd6 100644 --- a/tooth.json +++ b/tooth.json @@ -2,7 +2,7 @@ "format_version": 3, "format_uuid": "289f771f-2c9a-4d73-9f3f-8492495a924d", "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", - "version": "1.7.0", + "version": "1.7.1", "info": { "name": "GMLIB-LegacyRemoteCallApi", "description": "Legacy RemoteCall API for GMLIB", diff --git a/xmake.lua b/xmake.lua index ba3eb1e..91471a5 100644 --- a/xmake.lua +++ b/xmake.lua @@ -8,11 +8,11 @@ if not has_config("vs_runtime") then set_runtimes("MD") end -add_requires("levilamina 1.7.1", {configs = {target_type = "server"}}) +add_requires("levilamina 1.7.3", {configs = {target_type = "server"}}) add_requires("legacyremotecall") add_requires("levibuildscript 0.5.2") add_requires("ilistenattentively 0.10.0") -add_requires("gmlib 1.7.00") +add_requires("gmlib 1.7.0") add_requires("modapi 0.3.0") target("GMLIB-LegacyRemoteCallApi")