summaryrefslogtreecommitdiffstats
path: root/src/Bindings/ManualBindings_World.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-08-25 14:43:18 +0200
committerAlexander Harkness <me@bearbin.net>2017-08-25 14:43:18 +0200
commitf4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7 (patch)
tree70139b1ad7ed221e4b75c3a9e247b337de68eb07 /src/Bindings/ManualBindings_World.cpp
parentcompile.sh update. Fixed -d and -n, intelligent thread choice (#3960) (diff)
downloadcuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.gz
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.bz2
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.lz
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.xz
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.zst
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.zip
Diffstat (limited to 'src/Bindings/ManualBindings_World.cpp')
-rw-r--r--src/Bindings/ManualBindings_World.cpp50
1 files changed, 49 insertions, 1 deletions
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>);