From 4ef6c56f32d73ad9cb29c7958871ba3034f27d9d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 18:56:43 +0100 Subject: Debuggers: Disabled testing plugin calls. --- MCServer/Plugins/Debuggers/Debuggers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MCServer/Plugins/Debuggers') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 624261cbf..521032239 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -64,7 +64,7 @@ function Initialize(Plugin) -- TestBlockAreas(); -- TestSQLiteBindings(); -- TestExpatBindings(); - TestPluginCalls(); + -- TestPluginCalls(); return true end; -- cgit v1.2.3 From 1447d6d0dc0cca5b3362c6775c57d8483f8d8d17 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 9 Feb 2014 20:40:20 +0100 Subject: Debuggers: Added a cLuaChunkStay test code. --- MCServer/Plugins/Debuggers/Debuggers.lua | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'MCServer/Plugins/Debuggers') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 521032239..fca993065 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -53,6 +53,7 @@ function Initialize(Plugin) PM:BindCommand("/fr", "debuggers", HandleFurnaceRecipe, "- Shows the furnace recipe for the currently held item"); PM:BindCommand("/ff", "debuggers", HandleFurnaceFuel, "- Shows how long the currently held item would burn in a furnace"); PM:BindCommand("/sched", "debuggers", HandleSched, "- Schedules a simple countdown using cWorld:ScheduleTask()"); + PM:BindCommand("/cs", "debuggers", HandleChunkStay, "- Tests the ChunkStay Lua integration for the specified chunk coords"); Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers); @@ -1061,3 +1062,74 @@ end + +function HandleChunkStay(a_Split, a_Player) + if (#a_Split ~= 3) then + a_Player:SendMessage("Usage: /cs ") + return true + end + + local ChunkX = tonumber(a_Split[2]) + local ChunkZ = tonumber(a_Split[3]) + if ((ChunkX == nil) or (ChunkZ == nil)) then + a_Player:SendMessage("Invalid chunk coords.") + return true + end + + local World = a_Player:GetWorld() + local PlayerID = a_Player:GetUniqueID() + + -- Create the ChunkStay object: + local ChunkStay = cLuaChunkStay() + + -- Add the wanted chunks: + for z = -1, 1 do for x = -1, 1 do + ChunkStay:Add(ChunkX + x, ChunkZ + z) + end end + + -- The function that is called when all chunks are available + -- Will perform the action and finally get rid of the ChunkStay object + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + local OnAllChunksAvailable = function() + -- Build something on the neighboring chunks, to verify: + for z = -1, 1 do for x = -1, 1 do + local BlockX = (ChunkX + x) * 16 + 8 + local BlockZ = (ChunkZ + z) * 16 + 8 + for y = 20, 80 do + World:SetBlock(BlockX, y, BlockZ, E_BLOCK_OBSIDIAN, 0) + end + end end + + -- Teleport the player there for visual inspection: + World:DoWithEntityByID(PlayerID, + function (a_CallbackPlayer) + a_CallbackPlayer:TeleportToCoords(ChunkX * 16 + 8, 85, ChunkZ * 16 + 8) + a_CallbackPlayer:SendMessage("ChunkStay fully available") + end + ) + + -- Deactivate and remove the ChunkStay object (so that MCS can unload the chunks): + -- Forgetting this might crash the server when it stops! + ChunkStay:Disable() + ChunkStay = nil + end + + -- This function will be called for each chunk that is made available + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + local OnChunkAvailable = function(a_ChunkX, a_ChunkZ) + LOGINFO("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") + World:DoWithEntityByID(PlayerID, + function (a_CallbackPlayer) + a_CallbackPlayer:SendMessage("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") + end + ) + end + + -- Activate the ChunkStay: + ChunkStay:Enable(World, OnChunkAvailable, OnAllChunksAvailable) + return true +end + + + + -- cgit v1.2.3 From 2b1506de9c92539bfe7ffaceef87b5dd610bd04c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 10 Feb 2014 22:47:32 +0100 Subject: Debuggers: Updated to reflect the new API. --- MCServer/Plugins/Debuggers/Debuggers.lua | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'MCServer/Plugins/Debuggers') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index fca993065..853b0a1dc 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -1079,18 +1079,17 @@ function HandleChunkStay(a_Split, a_Player) local World = a_Player:GetWorld() local PlayerID = a_Player:GetUniqueID() - -- Create the ChunkStay object: - local ChunkStay = cLuaChunkStay() - - -- Add the wanted chunks: + -- Set the wanted chunks: + local Chunks = {} for z = -1, 1 do for x = -1, 1 do - ChunkStay:Add(ChunkX + x, ChunkZ + z) + table.insert(Chunks, {ChunkX + x, ChunkZ + z}) end end -- The function that is called when all chunks are available - -- Will perform the action and finally get rid of the ChunkStay object - -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + -- Will perform the actual action with all those chunks + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before the chunks load local OnAllChunksAvailable = function() + LOGINFO("ChunkStay all chunks now available") -- Build something on the neighboring chunks, to verify: for z = -1, 1 do for x = -1, 1 do local BlockX = (ChunkX + x) * 16 + 8 @@ -1107,15 +1106,10 @@ function HandleChunkStay(a_Split, a_Player) a_CallbackPlayer:SendMessage("ChunkStay fully available") end ) - - -- Deactivate and remove the ChunkStay object (so that MCS can unload the chunks): - -- Forgetting this might crash the server when it stops! - ChunkStay:Disable() - ChunkStay = nil end -- This function will be called for each chunk that is made available - -- Note that the player needs to be referenced using their EntityID - in case they disconnect before this completes + -- Note that the player needs to be referenced using their EntityID - in case they disconnect before the chunks load local OnChunkAvailable = function(a_ChunkX, a_ChunkZ) LOGINFO("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") World:DoWithEntityByID(PlayerID, @@ -1125,8 +1119,8 @@ function HandleChunkStay(a_Split, a_Player) ) end - -- Activate the ChunkStay: - ChunkStay:Enable(World, OnChunkAvailable, OnAllChunksAvailable) + -- Process the ChunkStay: + World:ChunkStay(Chunks, OnChunkAvailable, OnAllChunksAvailable) return true end -- cgit v1.2.3 From 90d68c57e43773587fb8b2cd9f073806e2828f78 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 11 Feb 2014 08:54:29 +0100 Subject: Debuggers: Updated messaging functions --- MCServer/Plugins/Debuggers/Debuggers.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'MCServer/Plugins/Debuggers') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 853b0a1dc..8345e2169 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -1064,20 +1064,25 @@ end function HandleChunkStay(a_Split, a_Player) + -- As an example of using ChunkStay, this call will load 3x3 chunks around the specified chunk coords, + -- then build an obsidian pillar in the middle of each one. + -- Once complete, the player will be teleported to the middle pillar + if (#a_Split ~= 3) then - a_Player:SendMessage("Usage: /cs ") + a_Player:SendMessageInfo("Usage: /cs ") return true end local ChunkX = tonumber(a_Split[2]) local ChunkZ = tonumber(a_Split[3]) if ((ChunkX == nil) or (ChunkZ == nil)) then - a_Player:SendMessage("Invalid chunk coords.") + a_Player:SendMessageFailure("Invalid chunk coords.") return true end local World = a_Player:GetWorld() local PlayerID = a_Player:GetUniqueID() + a_Player:SendMessageInfo("Loading chunks, stand by..."); -- Set the wanted chunks: local Chunks = {} @@ -1103,7 +1108,7 @@ function HandleChunkStay(a_Split, a_Player) World:DoWithEntityByID(PlayerID, function (a_CallbackPlayer) a_CallbackPlayer:TeleportToCoords(ChunkX * 16 + 8, 85, ChunkZ * 16 + 8) - a_CallbackPlayer:SendMessage("ChunkStay fully available") + a_CallbackPlayer:SendMessageSuccess("ChunkStay fully available") end ) end @@ -1114,7 +1119,7 @@ function HandleChunkStay(a_Split, a_Player) LOGINFO("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") World:DoWithEntityByID(PlayerID, function (a_CallbackPlayer) - a_CallbackPlayer:SendMessage("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") + a_CallbackPlayer:SendMessageInfo("ChunkStay now has chunk [" .. a_ChunkX .. ", " .. a_ChunkZ .. "]") end ) end -- cgit v1.2.3