diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-27 08:13:40 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-27 08:13:40 +0200 |
commit | e274d0dd8a6eefeb6e84272ffd09ac55b2c08900 (patch) | |
tree | 377f52ed5738810c157e631ec31f626fbe5acef6 /src/Bindings | |
parent | d (diff) | |
parent | Implement anvil chunk sparsing (diff) | |
download | cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.gz cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.bz2 cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.lz cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.xz cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.tar.zst cuberite-e274d0dd8a6eefeb6e84272ffd09ac55b2c08900.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/AllToLua.pkg | 9 | ||||
-rw-r--r-- | src/Bindings/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Bindings/LuaState.cpp | 76 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 5 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 285 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_RankManager.cpp | 71 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_World.cpp | 50 |
7 files changed, 432 insertions, 65 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index b99ac2f88..778cdf42c 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -17,13 +17,15 @@ inheritance doesn't work properly (#1789). $#include "../Globals.h" // Typedefs from Globals.h, so that we don't have to process that file: -typedef long long Int64; -typedef int Int32; -typedef short Int16; +typedef signed long long Int64; +typedef signed int Int32; +typedef signed short Int16; +typedef signed char Int8; typedef unsigned long long UInt64; typedef unsigned int UInt32; typedef unsigned short UInt16; +typedef unsigned char UInt8; $cfile "../Vector3.h" @@ -69,6 +71,7 @@ $cfile "../MapManager.h" $cfile "../Scoreboard.h" $cfile "../Statistics.h" $cfile "../Protocol/MojangAPI.h" +$cfile "../UUID.h" // Entities: $cfile "../Entities/Entity.h" diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt index 6b2ad7ab0..0ab21467b 100644 --- a/src/Bindings/CMakeLists.txt +++ b/src/Bindings/CMakeLists.txt @@ -139,6 +139,7 @@ set(BINDING_DEPENDENCIES ../StringUtils.h ../Tracer.h ../UI/Window.h + ../UUID.h ../Vector3.h ../WebAdmin.h ../World.h diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index b443325ec..7bd4becb6 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -20,6 +20,7 @@ extern "C" #include "../Entities/Entity.h" #include "../BlockEntities/BlockEntity.h" #include "../DeadlockDetect.h" +#include "../UUID.h" @@ -1410,6 +1411,40 @@ bool cLuaState::GetStackValue(int a_StackPos, float & a_ReturnedVal) +bool cLuaState::GetStackValue(int a_StackPos, cUUID & a_Value) +{ + if (lua_isnil(m_LuaState, a_StackPos)) + { + return false; + } + + tolua_Error tolua_Err; + if (tolua_isusertype(m_LuaState, a_StackPos, "cUUID", 0, &tolua_Err)) + { + // Found a cUUID, copy into output value + cUUID * PtrUUID = nullptr; + GetStackValue(a_StackPos, PtrUUID); + if (PtrUUID == nullptr) + { + return false; + } + a_Value = *PtrUUID; + return true; + } + + // Try to get a string and parse as a UUID into the output + AString StrUUID; + if (!GetStackValue(a_StackPos, StrUUID)) + { + return false; + } + return a_Value.FromString(StrUUID); +} + + + + + cLuaState::cStackValue cLuaState::WalkToValue(const AString & a_Name) { // There needs to be at least one value on the stack: @@ -1785,6 +1820,47 @@ bool cLuaState::CheckParamFunctionOrNil(int a_StartParam, int a_EndParam) +bool cLuaState::CheckParamUUID(int a_StartParam, int a_EndParam) +{ + ASSERT(IsValid()); + + if (a_EndParam < 0) + { + a_EndParam = a_StartParam; + } + + cUUID tempUUID; + AString tempStr; + // Accept either a cUUID or a string that contains a valid UUID + for (int i = a_StartParam; i <= a_EndParam; ++i) + { + tolua_Error err; + if (tolua_isusertype(m_LuaState, i, "cUUID", 0, &err) && !lua_isnil(m_LuaState, i)) + { + continue; + } + + if (!tolua_iscppstring(m_LuaState, i, 0, &err)) + { + ApiParamError("Failed to read parameter #%d. UUID expected, got %s", i, GetTypeText(i).c_str()); + return false; + } + + // Check string is a valid UUID + GetStackValue(i, tempStr); + if (!tempUUID.FromString(tempStr)) + { + ApiParamError("Failed to read parameter #%d. UUID expected, got non-UUID string:\n\t\"%s\"", i, tempStr.c_str()); + return false; + } + } + return true; +} + + + + + bool cLuaState::CheckParamEnd(int a_Param) { tolua_Error tolua_err; diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 8014f40d4..98f1cbc28 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -659,6 +659,7 @@ public: bool GetStackValue(int a_StackPos, eBlockFace & a_Value); bool GetStackValue(int a_StackPos, eWeather & a_Value); bool GetStackValue(int a_StackPos, float & a_ReturnedVal); + bool GetStackValue(int a_StackPos, cUUID & a_Value); // template to catch all of the various c++ integral types without overload conflicts template <class T> @@ -787,6 +788,10 @@ public: /** Returns true if the specified parameters on the stack are functions or nils; also logs warning if not */ bool CheckParamFunctionOrNil(int a_StartParam, int a_EndParam = -1); + /** Returns true if the specified parameters on the stack are UUIDs; also logs warning if not + Accepts either cUUID instances or strings that contain UUIDs */ + bool CheckParamUUID(int a_StartParam, int a_EndParam = -1); + /** Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) */ bool CheckParamEnd(int a_Param); diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 6fe133e1e..c87e9ed20 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -1665,6 +1665,28 @@ static int tolua_cPlayer_PermissionMatches(lua_State * tolua_S) +static int tolua_cPlayer_GetUUID(lua_State * tolua_S) +{ + // Check the params: + cLuaState L(tolua_S); + if (!L.CheckParamSelf("cPlayer")) + { + return 0; + } + + // Get the params: + cPlayer * Self = nullptr; + L.GetStackValue(1, Self); + + // Return the UUID as a string + L.Push(Self->GetUUID().ToShortString()); + return 1; +} + + + + + template < class OBJTYPE, void (OBJTYPE::*SetCallback)(cLuaState::cCallbackPtr && a_CallbackFn) @@ -2318,7 +2340,7 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L) { cLuaState S(L); if ( - !S.CheckParamUserType(1, "cClientHandle") || + !S.CheckParamSelf("cClientHandle") || !S.CheckParamString(2, 3) || !S.CheckParamEnd(4) ) @@ -2343,13 +2365,145 @@ static int tolua_cClientHandle_SendPluginMessage(lua_State * L) +static int tolua_cClientHandle_GetUUID(lua_State * tolua_S) +{ + // Check the params: + cLuaState L(tolua_S); + if ( + !L.CheckParamSelf("cClientHandle") || + !L.CheckParamEnd(2) + ) + { + return 0; + } + + // Get the params: + cClientHandle * Self; + L.GetStackValue(1, Self); + + // Return the UUID as a string: + L.Push(Self->GetUUID().ToShortString()); + return 1; +} + + + + + +static int tolua_cClientHandle_GenerateOfflineUUID(lua_State * tolua_S) +{ + // Check the params: + cLuaState L(tolua_S); + if ( + !L.CheckParamStaticSelf("cClientHandle") || + !L.CheckParamString(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Get the params: + AString Username; + L.GetStackValue(2, Username); + + // Return the UUID as a string: + L.Push(cClientHandle::GenerateOfflineUUID(Username).ToShortString()); + return 1; +} + + + + + +static int tolua_cClientHandle_IsUUIDOnline(lua_State * tolua_S) +{ + // Check the params: + cLuaState L(tolua_S); + if ( + !L.CheckParamStaticSelf("cClientHandle") || + !L.CheckParamUUID(2) || + !L.CheckParamEnd(3) + ) + { + return 0; + } + + // Get the params: + cUUID UUID; + L.GetStackValue(2, UUID); + + // Return the result: + L.Push(cClientHandle::IsUUIDOnline(UUID)); + return 1; +} + + + + +static int tolua_cMobHeadEntity_SetOwner(lua_State * tolua_S) +{ + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamSelf("cMobHeadEntity") || + !L.CheckParamUUID(2) || + !L.CheckParamString(3, 5) || + !L.CheckParamEnd(6) + ) + { + return 0; + } + + + // Get the params: + cMobHeadEntity * Self; + cUUID OwnerUUID; + AString OwnerName, OwnerTexture, OwnerTextureSignature; + L.GetStackValues(1, Self, OwnerUUID, OwnerName, OwnerTexture, OwnerTextureSignature); + + // Set the owner: + Self->SetOwner(OwnerUUID, OwnerName, OwnerTexture, OwnerTextureSignature); + return 0; +} + + + + + +static int tolua_cMobHeadEntity_GetOwnerUUID(lua_State * tolua_S) +{ + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamSelf("cMobHeadEntity") || + !L.CheckParamEnd(2) + ) + { + return 0; + } + + // Get the params: + cMobHeadEntity * Self; + L.GetStackValue(1, Self); + + // Return the UUID as a string: + cUUID Owner = Self->GetOwnerUUID(); + L.Push(Owner.IsNil() ? AString{} : Owner.ToShortString()); + return 1; +} + + + + + static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L) { cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cMojangAPI") || + !S.CheckParamStaticSelf("cMojangAPI") || !S.CheckParamString(2) || - !S.CheckParamString(3) || + !S.CheckParamUUID(3) || !S.CheckParamEnd(4) ) { @@ -2357,9 +2511,9 @@ static int tolua_cMojangAPI_AddPlayerNameToUUIDMapping(lua_State * L) } // Retrieve the parameters: - AString UUID, PlayerName; - S.GetStackValue(2, PlayerName); - S.GetStackValue(3, UUID); + AString PlayerName; + cUUID UUID; + S.GetStackValues(2, PlayerName, UUID); // Store in the cache: cRoot::Get()->GetMojangAPI().AddPlayerNameToUUIDMapping(PlayerName, UUID); @@ -2374,15 +2528,15 @@ static int tolua_cMojangAPI_GetPlayerNameFromUUID(lua_State * L) { cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cMojangAPI") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cMojangAPI") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(4) ) { return 0; } - AString UUID; + cUUID UUID; S.GetStackValue(2, UUID); // If the UseOnlyCached param was given, read it; default to false @@ -2407,7 +2561,7 @@ static int tolua_cMojangAPI_GetUUIDFromPlayerName(lua_State * L) { cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cMojangAPI") || + !S.CheckParamStaticSelf("cMojangAPI") || !S.CheckParamString(2) || !S.CheckParamEnd(4) ) @@ -2426,9 +2580,9 @@ static int tolua_cMojangAPI_GetUUIDFromPlayerName(lua_State * L) lua_pop(L, 1); } - // Return the UUID: - AString UUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(PlayerName, ShouldUseCacheOnly); - S.Push(UUID); + // Return the UUID as a string: + cUUID UUID = cRoot::Get()->GetMojangAPI().GetUUIDFromPlayerName(PlayerName, ShouldUseCacheOnly); + S.Push(UUID.IsNil() ? AString{} : UUID.ToShortString()); return 1; } @@ -2440,7 +2594,7 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L) { cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cMojangAPI") || + !S.CheckParamStaticSelf("cMojangAPI") || !S.CheckParamTable(2) || !S.CheckParamEnd(4) ) @@ -2476,23 +2630,23 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L) lua_newtable(L); // Get the UUIDs: - AStringVector UUIDs = cRoot::Get()->GetMojangAPI().GetUUIDsFromPlayerNames(PlayerNames, ShouldUseCacheOnly); + auto UUIDs = cRoot::Get()->GetMojangAPI().GetUUIDsFromPlayerNames(PlayerNames, ShouldUseCacheOnly); if (UUIDs.size() != PlayerNames.size()) { // A hard error has occured while processing the request, no UUIDs were returned. Return an empty table: return 1; } - // Convert to output table, PlayerName -> UUID: + // Convert to output table, PlayerName -> UUID string: size_t len = UUIDs.size(); for (size_t i = 0; i < len; i++) { - if (UUIDs[i].empty()) + if (UUIDs[i].IsNil()) { // No UUID was provided for PlayerName[i], skip it in the resulting table continue; } - lua_pushlstring(L, UUIDs[i].c_str(), UUIDs[i].length()); + S.Push(UUIDs[i].ToShortString()); lua_setfield(L, 3, PlayerNames[i].c_str()); } return 1; @@ -2504,13 +2658,13 @@ static int tolua_cMojangAPI_GetUUIDsFromPlayerNames(lua_State * L) static int tolua_cMojangAPI_MakeUUIDDashed(lua_State * L) { - // Function signature: cMojangAPI:MakeUUIDDashed(UUID) -> string + // Function now non-existant but kept for API compatibility // Check params: cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cMojangAPI") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cMojangAPI") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -2518,11 +2672,11 @@ static int tolua_cMojangAPI_MakeUUIDDashed(lua_State * L) } // Get the params: - AString UUID; + cUUID UUID; S.GetStackValue(2, UUID); // Push the result: - S.Push(cRoot::Get()->GetMojangAPI().MakeUUIDDashed(UUID)); + S.Push(UUID.ToLongString()); return 1; } @@ -2532,13 +2686,13 @@ static int tolua_cMojangAPI_MakeUUIDDashed(lua_State * L) static int tolua_cMojangAPI_MakeUUIDShort(lua_State * L) { - // Function signature: cMojangAPI:MakeUUIDShort(UUID) -> string + // Function now non-existant but kept for API compatibility // Check params: cLuaState S(L); if ( !S.CheckParamUserTable(1, "cMojangAPI") || - !S.CheckParamString(2) || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -2546,11 +2700,11 @@ static int tolua_cMojangAPI_MakeUUIDShort(lua_State * L) } // Get the params: - AString UUID; + cUUID UUID; S.GetStackValue(2, UUID); // Push the result: - S.Push(cRoot::Get()->GetMojangAPI().MakeUUIDShort(UUID)); + S.Push(UUID.ToShortString()); return 1; } @@ -3053,6 +3207,66 @@ static int tolua_cLuaWindow_new_local(lua_State * tolua_S) +static int tolua_cRoot_DoWithPlayerByUUID(lua_State * tolua_S) +{ + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamSelf("cRoot") || + !L.CheckParamUUID(2) || + !L.CheckParamFunction(3) || + !L.CheckParamEnd(4) + ) + { + return 0; + } + + class cCallback : + public cPlayerListCallback + { + public: + cCallback(cLuaState & a_LuaState) : + m_LuaState(a_LuaState) + { + } + + virtual bool Item(cPlayer * a_Player) override + { + bool ret = false; + m_LuaState.Call(m_FnRef, a_Player, cLuaState::Return, ret); + return ret; + } + + cLuaState & m_LuaState; + cLuaState::cRef m_FnRef; + } Callback(L); + + // Get parameters: + cRoot * Self; + cUUID PlayerUUID; + L.GetStackValues(1, Self, PlayerUUID, Callback.m_FnRef); + + if (PlayerUUID.IsNil()) + { + return L.ApiParamError("Expected a non-nil UUID for parameter #1"); + } + if (!Callback.m_FnRef.IsValid()) + { + return L.ApiParamError("Expected a valid callback function for parameter #2"); + } + + // Call the function: + bool res = Self->DoWithPlayerByUUID(PlayerUUID, Callback); + + // Push the result as the return value: + L.Push(res); + return 1; +} + + + + + static int tolua_cRoot_GetBuildCommitID(lua_State * tolua_S) { cLuaState L(tolua_S); @@ -3791,9 +4005,12 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cClientHandle"); - tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); - tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); - tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); + tolua_constant(tolua_S, "MAX_VIEW_DISTANCE", cClientHandle::MAX_VIEW_DISTANCE); + tolua_constant(tolua_S, "MIN_VIEW_DISTANCE", cClientHandle::MIN_VIEW_DISTANCE); + tolua_function(tolua_S, "SendPluginMessage", tolua_cClientHandle_SendPluginMessage); + tolua_function(tolua_S, "GetUUID", tolua_cClientHandle_GetUUID); + tolua_function(tolua_S, "GenerateOfflineUUID", tolua_cClientHandle_GenerateOfflineUUID); + tolua_function(tolua_S, "IsUUIDOnline", tolua_cClientHandle_IsUUIDOnline); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cColor"); @@ -3881,6 +4098,11 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "DoWithMap", DoWithID<cMapManager, cMap, &cMapManager::DoWithMap>); tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cMobHeadEntity"); + tolua_function(tolua_S, "SetOwner", tolua_cMobHeadEntity_SetOwner); + tolua_function(tolua_S, "GetOwnerUUID", tolua_cMobHeadEntity_GetOwnerUUID); + tolua_endmodule(tolua_S); + tolua_beginmodule(tolua_S, "cMojangAPI"); tolua_function(tolua_S, "AddPlayerNameToUUIDMapping", tolua_cMojangAPI_AddPlayerNameToUUIDMapping); tolua_function(tolua_S, "GetPlayerNameFromUUID", tolua_cMojangAPI_GetPlayerNameFromUUID); @@ -3894,6 +4116,7 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "GetPermissions", tolua_cPlayer_GetPermissions); tolua_function(tolua_S, "GetRestrictions", tolua_cPlayer_GetRestrictions); tolua_function(tolua_S, "PermissionMatches", tolua_cPlayer_PermissionMatches); + tolua_function(tolua_S, "GetUUID", tolua_cPlayer_GetUUID); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cPlugin"); @@ -3923,8 +4146,8 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cRoot"); + tolua_function(tolua_S, "DoWithPlayerByUUID", tolua_cRoot_DoWithPlayerByUUID); tolua_function(tolua_S, "FindAndDoWithPlayer", DoWith <cRoot, cPlayer, &cRoot::FindAndDoWithPlayer>); - tolua_function(tolua_S, "DoWithPlayerByUUID", DoWith <cRoot, cPlayer, &cRoot::DoWithPlayerByUUID>); tolua_function(tolua_S, "ForEachPlayer", ForEach<cRoot, cPlayer, &cRoot::ForEachPlayer>); tolua_function(tolua_S, "ForEachWorld", ForEach<cRoot, cWorld, &cRoot::ForEachWorld>); tolua_function(tolua_S, "GetBrewingRecipe", tolua_cRoot_GetBrewingRecipe); diff --git a/src/Bindings/ManualBindings_RankManager.cpp b/src/Bindings/ManualBindings_RankManager.cpp index 84ca67c4e..d24685d2b 100644 --- a/src/Bindings/ManualBindings_RankManager.cpp +++ b/src/Bindings/ManualBindings_RankManager.cpp @@ -8,6 +8,7 @@ #include "../Root.h" #include "tolua++/include/tolua++.h" #include "LuaState.h" +#include "UUID.h" @@ -266,7 +267,7 @@ static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || + !S.CheckParamStaticSelf("cRankManager") || !S.CheckParamEnd(2) ) { @@ -274,10 +275,18 @@ static int tolua_cRankManager_GetAllPlayerUUIDs(lua_State * L) } // Get the player uuid's: - AStringVector Players = cRoot::Get()->GetRankManager()->GetAllPlayerUUIDs(); + std::vector<cUUID> Players = cRoot::Get()->GetRankManager()->GetAllPlayerUUIDs(); + + // Convert to string UUIDs + std::vector<AString> StrUUIDs; + StrUUIDs.reserve(Players.size()); + for (const auto & UUID : Players) + { + StrUUIDs.push_back(UUID.ToShortString()); + } // Push the results: - S.Push(Players); + S.Push(StrUUIDs); return 1; } @@ -430,8 +439,8 @@ static int tolua_cRankManager_GetPlayerGroups(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -439,7 +448,7 @@ static int tolua_cRankManager_GetPlayerGroups(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Get the groups: @@ -462,8 +471,8 @@ static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -471,7 +480,7 @@ static int tolua_cRankManager_GetPlayerMsgVisuals(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Get the permissions: @@ -498,8 +507,8 @@ static int tolua_cRankManager_GetPlayerPermissions(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -507,7 +516,7 @@ static int tolua_cRankManager_GetPlayerPermissions(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Get the permissions: @@ -530,8 +539,8 @@ static int tolua_cRankManager_GetPlayerRestrictions(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -539,7 +548,7 @@ static int tolua_cRankManager_GetPlayerRestrictions(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Get the permissions: @@ -562,8 +571,8 @@ static int tolua_cRankManager_GetPlayerRankName(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -571,7 +580,7 @@ static int tolua_cRankManager_GetPlayerRankName(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Get the rank name: @@ -594,8 +603,8 @@ static int tolua_cRankManager_GetPlayerName(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -603,7 +612,7 @@ static int tolua_cRankManager_GetPlayerName(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Get the player name: @@ -887,8 +896,8 @@ static int tolua_cRankManager_IsPlayerRankSet(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -896,7 +905,7 @@ static int tolua_cRankManager_IsPlayerRankSet(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Get the response: @@ -1067,8 +1076,8 @@ static int tolua_cRankManager_RemovePlayerRank(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || !S.CheckParamEnd(3) ) { @@ -1076,7 +1085,7 @@ static int tolua_cRankManager_RemovePlayerRank(lua_State * L) } // Get the params: - AString PlayerUUID; + cUUID PlayerUUID; S.GetStackValue(2, PlayerUUID); // Remove the player's rank: @@ -1219,8 +1228,9 @@ static int tolua_cRankManager_SetPlayerRank(lua_State * L) cLuaState S(L); if ( - !S.CheckParamUserTable(1, "cRankManager") || - !S.CheckParamString(2, 4) || + !S.CheckParamStaticSelf("cRankManager") || + !S.CheckParamUUID(2) || + !S.CheckParamString(3, 4) || !S.CheckParamEnd(5) ) { @@ -1228,7 +1238,8 @@ static int tolua_cRankManager_SetPlayerRank(lua_State * L) } // Get the params: - AString PlayerUUID, PlayerName, RankName; + AString PlayerName, RankName; + cUUID PlayerUUID; S.GetStackValues(2, PlayerUUID, PlayerName, RankName); // Set the rank: diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 88e3917da..10b5daf1e 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -7,6 +7,7 @@ #include "tolua++/include/tolua++.h" #include "../World.h" #include "../Broadcaster.h" +#include "../UUID.h" #include "ManualBindings.h" #include "LuaState.h" #include "PluginLua.h" @@ -206,6 +207,53 @@ static int tolua_cWorld_DoExplosionAt(lua_State * tolua_S) +static int tolua_cWorld_DoWithPlayerByUUID(lua_State * tolua_S) +{ + // Check params: + cLuaState L(tolua_S); + if ( + !L.CheckParamSelf("cWorld") || + !L.CheckParamUUID(2) || + !L.CheckParamFunction(3) || + !L.CheckParamEnd(4) + ) + { + return 0; + } + + // Get parameters: + cWorld * Self; + cUUID PlayerUUID; + cLuaState::cRef FnRef; + L.GetStackValues(1, Self, PlayerUUID, FnRef); + + if (PlayerUUID.IsNil()) + { + return L.ApiParamError("Expected a non-nil UUID for parameter #1"); + } + if (!FnRef.IsValid()) + { + return L.ApiParamError("Expected a valid callback function for parameter #2"); + } + + // Call the function: + bool res = Self->DoWithPlayerByUUID(PlayerUUID, [&](cPlayer * a_Player) + { + bool ret = false; + L.Call(FnRef, a_Player, cLuaState::Return, ret); + return ret; + } + ); + + // Push the result as the return value: + L.Push(res); + return 1; +} + + + + + static int tolua_cWorld_ForEachLoadedChunk(lua_State * tolua_S) { // Exported manually, because tolua doesn't support converting functions to functor types. @@ -640,7 +688,7 @@ void cManualBindings::BindWorld(lua_State * tolua_S) tolua_function(tolua_S, "DoWithMobHeadAt", DoWithXYZ<cWorld, cMobHeadEntity, &cWorld::DoWithMobHeadAt>); tolua_function(tolua_S, "DoWithNoteBlockAt", DoWithXYZ<cWorld, cNoteEntity, &cWorld::DoWithNoteBlockAt>); tolua_function(tolua_S, "DoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); - tolua_function(tolua_S, "DoWithPlayerByUUID", DoWith< cWorld, cPlayer, &cWorld::DoWithPlayerByUUID>); + tolua_function(tolua_S, "DoWithPlayerByUUID", tolua_cWorld_DoWithPlayerByUUID); tolua_function(tolua_S, "FindAndDoWithPlayer", DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", ForEachInChunk<cWorld, cBlockEntity, &cWorld::ForEachBlockEntityInChunk>); tolua_function(tolua_S, "ForEachBrewingstandInChunk", ForEachInChunk<cWorld, cBrewingstandEntity, &cWorld::ForEachBrewingstandInChunk>); |