summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins/Core/help.lua
blob: 68cdeca66197ae8f3f52373d1a7c49e4b9d6b905 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function HandleHelpCommand(Split, Player)
	local PluginManager = cRoot:Get():GetPluginManager()
	
	local LinesPerPage = 9;
	local CurrentPage = 1;
	local CurrentLine = 0;
	local PageRequested = 1;
	local Output = {};
	
	if (#Split == 2) then
		PageRequested = tonumber(Split[2]);
	end
	
	local Process = function(Command, Permission, HelpString)
		if not(Player:HasPermission(Permission)) then
			return false;
		end;
		if (HelpString == "") then
			return false;
		end;

		CurrentLine = CurrentLine + 1;
		CurrentPage = math.floor(CurrentLine / LinesPerPage) + 1;
		if (CurrentPage ~= PageRequested) then
			return false;
		end;
		table.insert(Output, cChatColor.Blue .. Command .. HelpString);
	end

	PluginManager:ForEachCommand(Process);

	-- CurrentPage now contains the total number of pages, and Output has the individual help lines to be sent

	Player:SendMessage(cChatColor.Purple .. "- All commands - " .. cChatColor.Gold .. "[Page " .. PageRequested .. " / " .. CurrentPage .. "]");
	for idx, msg in ipairs(Output) do
		Player:SendMessage(msg);
	end;
	
	return true
end