Files
cuberite-2a/MCServer/Plugins/Core/help.lua
T

44 lines
1.1 KiB
Lua
Raw Normal View History

2013-08-11 16:00:53 +01:00
function HandleHelpCommand( Split, Player )
2013-07-27 16:24:03 +01:00
local PluginManager = cRoot:Get():GetPluginManager()
2013-08-11 16:00:53 +01:00
local LinesPerPage = 8
local CurrentPage = 1
local CurrentLine = 0
local PageRequested = 1
local Output = {}
2013-07-27 16:24:03 +01:00
if (#Split == 2) then
2013-08-11 16:00:53 +01:00
PageRequested = tonumber( Split[2] )
2013-07-27 16:24:03 +01:00
end
2013-08-11 16:00:53 +01:00
local Process = function( Command, Permission, HelpString )
if not (Player:HasPermission(Permission)) then
return false
end
2013-07-27 16:24:03 +01:00
if (HelpString == "") then
2013-08-11 16:00:53 +01:00
return false
end
2013-07-27 16:24:03 +01:00
2013-08-11 16:00:53 +01:00
CurrentLine = CurrentLine + 1
CurrentPage = math.floor( CurrentLine / LinesPerPage ) + 1
2013-07-27 16:24:03 +01:00
if (CurrentPage ~= PageRequested) then
2013-08-11 16:00:53 +01:00
return false
end
table.insert( Output, Command .. HelpString )
2013-07-27 16:24:03 +01:00
end
2013-08-11 16:00:53 +01:00
PluginManager:ForEachCommand( Process )
2013-07-27 16:24:03 +01:00
-- CurrentPage now contains the total number of pages, and Output has the individual help lines to be sent
2013-08-11 16:00:53 +01:00
SendMessage( Player, "Page " .. PageRequested .. " out of " .. CurrentPage .. "." )
SendMessage( Player, "'-' means no prefix, '~' means a value is required." )
for idx, msg in ipairs( Output ) do
SendMessage( Player, msg )
end
2013-07-27 16:24:03 +01:00
return true
2013-08-11 16:00:53 +01:00
end