summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/Debuggers/Debuggers.lua
diff options
context:
space:
mode:
Diffstat (limited to 'MCServer/Plugins/Debuggers/Debuggers.lua')
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua75
1 files changed, 74 insertions, 1 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 8512fbd5f..624261cbf 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -52,6 +52,7 @@ function Initialize(Plugin)
PM:BindCommand("/fill", "debuggers", HandleFill, "- Fills all block entities in current chunk with junk");
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()");
Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers);
@@ -63,7 +64,8 @@ function Initialize(Plugin)
-- TestBlockAreas();
-- TestSQLiteBindings();
-- TestExpatBindings();
-
+ TestPluginCalls();
+
return true
end;
@@ -71,6 +73,38 @@ end;
+function TestPluginCalls()
+ -- In order to test the inter-plugin communication, we're going to call Core's ReturnColorFromChar() function
+ -- It is a rather simple function that doesn't need any tables as its params and returns a value, too
+ -- Note the signature: function ReturnColorFromChar( Split, char ) ... return cChatColog.Gray ... end
+ -- The Split parameter should be a table, but it is not used in that function anyway,
+ -- so we can get away with passing nil to it.
+
+ -- Use the old, deprecated and unsafe method:
+ local Core = cPluginManager:Get():GetPlugin("Core")
+ if (Core ~= nil) then
+ LOGINFO("Calling Core::ReturnColorFromChar() the old-fashioned way...")
+ local Gray = Core:Call("ReturnColorFromChar", nil, "8")
+ if (Gray ~= cChatColor.Gray) then
+ LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "<nil>"))
+ else
+ LOGINFO("Call succeeded")
+ end
+ end
+
+ -- Use the new method:
+ LOGINFO("Calling Core::ReturnColorFromChar() the recommended way...")
+ local Gray = cPluginManager:CallPlugin("Core", "ReturnColorFromChar", nil, "8")
+ if (Gray ~= cChatColor.Gray) then
+ LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "<nil>"))
+ else
+ LOGINFO("Call succeeded")
+ end
+end
+
+
+
+
function TestBlockAreas()
LOG("Testing block areas...");
@@ -955,6 +989,45 @@ end
+function HandleSched(a_Split, a_Player)
+ local World = a_Player:GetWorld()
+
+ -- Schedule a broadcast of a countdown message:
+ for i = 1, 10 do
+ World:ScheduleTask(i * 20,
+ function(a_World)
+ a_World:BroadcastChat("Countdown: " .. 11 - i)
+ end
+ )
+ end
+
+ -- Schedule a broadcast of the final message and a note to the originating player
+ -- Note that we CANNOT us the a_Player in the callback - what if the player disconnected?
+ -- Therefore we store the player's EntityID
+ local PlayerID = a_Player:GetUniqueID()
+ World:ScheduleTask(220,
+ function(a_World)
+ a_World:BroadcastChat("Countdown: BOOM")
+ a_World:DoWithEntityByID(PlayerID,
+ function(a_Entity)
+ if (a_Entity:IsPlayer()) then
+ -- Although unlikely, it is possible that this player is not the originating player
+ -- However, I leave this as an excercise to you to fix this "bug"
+ local Player = tolua.cast(a_Entity, "cPlayer")
+ Player:SendMessage("Countdown finished")
+ end
+ end
+ )
+ end
+ )
+
+ return true
+end
+
+
+
+
+
function HandleRequest_Debuggers(a_Request)
local FolderContents = cFile:GetFolderContents("./");
return "<p>The following objects have been returned by cFile:GetFolderContents():<ul><li>" .. table.concat(FolderContents, "</li><li>") .. "</li></ul></p>";