summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/Debuggers/Debuggers.lua
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-02-09 20:40:20 +0100
committermadmaxoft <github@xoft.cz>2014-02-09 20:40:20 +0100
commit1447d6d0dc0cca5b3362c6775c57d8483f8d8d17 (patch)
treeaf5c7109a6a46866ca0e2d4d962bd9f07ee1ed4a /MCServer/Plugins/Debuggers/Debuggers.lua
parentFirst working version of cLuaChunkStay. (diff)
downloadcuberite-1447d6d0dc0cca5b3362c6775c57d8483f8d8d17.tar
cuberite-1447d6d0dc0cca5b3362c6775c57d8483f8d8d17.tar.gz
cuberite-1447d6d0dc0cca5b3362c6775c57d8483f8d8d17.tar.bz2
cuberite-1447d6d0dc0cca5b3362c6775c57d8483f8d8d17.tar.lz
cuberite-1447d6d0dc0cca5b3362c6775c57d8483f8d8d17.tar.xz
cuberite-1447d6d0dc0cca5b3362c6775c57d8483f8d8d17.tar.zst
cuberite-1447d6d0dc0cca5b3362c6775c57d8483f8d8d17.zip
Diffstat (limited to '')
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua72
1 files changed, 72 insertions, 0 deletions
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 <ChunkX> <ChunkZ>")
+ 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
+
+
+
+