summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/Debuggers/Debuggers.lua
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-03-18 16:07:15 +0100
committerMattes D <github@xoft.cz>2015-03-18 16:07:15 +0100
commitfa17fb9b80c0f6c7614746edfd64fcc71167b86c (patch)
tree7032578bb204eb5c34585cc684bdc95523279952 /MCServer/Plugins/Debuggers/Debuggers.lua
parentWorld:DoWithEntityByID() checks the entities-to-add as well. (diff)
downloadcuberite-fa17fb9b80c0f6c7614746edfd64fcc71167b86c.tar
cuberite-fa17fb9b80c0f6c7614746edfd64fcc71167b86c.tar.gz
cuberite-fa17fb9b80c0f6c7614746edfd64fcc71167b86c.tar.bz2
cuberite-fa17fb9b80c0f6c7614746edfd64fcc71167b86c.tar.lz
cuberite-fa17fb9b80c0f6c7614746edfd64fcc71167b86c.tar.xz
cuberite-fa17fb9b80c0f6c7614746edfd64fcc71167b86c.tar.zst
cuberite-fa17fb9b80c0f6c7614746edfd64fcc71167b86c.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua75
1 files changed, 75 insertions, 0 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 9ea623b64..d0c362ab4 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -1643,6 +1643,81 @@ end
+--- Monitors the state of the "inh" entity-spawning hook
+-- if false, the hook is installed before the "inh" command processing
+local isInhHookInstalled = false
+
+function HandleConsoleInh(a_Split, a_FullCmd)
+ -- Check the param:
+ local kindStr = a_Split[2] or "pkArrow"
+ local kind = cProjectileEntity[kindStr]
+ if (kind == nil) then
+ return true, "There's no projectile kind '" .. kindStr .. "'."
+ end
+
+ -- Get the world to test in:
+ local world = cRoot:Get():GetDefaultWorld()
+ if (world == nil) then
+ return true, "Cannot test inheritance, no default world"
+ end
+
+ -- Install the hook, if needed:
+ if not(isInhHookInstalled) then
+ cPluginManager:AddHook(cPluginManager.HOOK_SPAWNING_ENTITY,
+ function (a_CBWorld, a_CBEntity)
+ LOG("New entity is spawning:")
+ LOG(" Lua type: '" .. type(a_CBEntity) .. "'")
+ LOG(" ToLua type: '" .. tolua.type(a_CBEntity) .. "'")
+ LOG(" GetEntityType(): '" .. a_CBEntity:GetEntityType() .. "'")
+ LOG(" GetClass(): '" .. a_CBEntity:GetClass() .. "'")
+ end
+ )
+ isInhHookInstalled = true
+ end
+
+ -- Create the projectile:
+ LOG("Creating a " .. kindStr .. " projectile in world " .. world:GetName() .. "...")
+ local msg
+ world:ChunkStay({{0, 0}},
+ nil,
+ function ()
+ -- Create a projectile at {8, 100, 8}:
+ local entityID = world:CreateProjectile(8, 100, 8, kind, nil, nil)
+ if (entityID < 0) then
+ msg = "Cannot test inheritance, projectile creation failed."
+ return
+ end
+ LOG("Entity created, ID #" .. entityID)
+
+ -- Call a function on the newly created entity:
+ local hasExecutedCallback = false
+ world:DoWithEntityByID(
+ entityID,
+ function (a_CBEntity)
+ LOG("Projectile created and found using the DoWithEntityByID() callback")
+ LOG("Lua type: '" .. type(a_CBEntity) .. "'")
+ LOG("ToLua type: '" .. tolua.type(a_CBEntity) .. "'")
+ LOG("GetEntityType(): '" .. a_CBEntity:GetEntityType() .. "'")
+ LOG("GetClass(): '" .. a_CBEntity:GetClass() .. "'")
+ hasExecutedCallback = true
+ end
+ )
+ if not(hasExecutedCallback) then
+ msg = "The callback failed to execute"
+ return
+ end
+
+ msg = "Inheritance test finished"
+ end
+ )
+
+ return true, msg
+end
+
+
+
+
+
function HandleConsoleLoadChunk(a_Split)
-- Check params:
local numParams = #a_Split