Posts: 25 
	Threads: 6 
	Joined: Oct 2015
	
 Thanks: 5 
	Given 12 thank(s) in 6 post(s)
  
	 
 
	
	
		Did a simple plugin that shows all permissions (if the plugin have a info.lua file with the proper information) with the commands and help string. I made this plugin so it would be easier for me to assign permissions to each group. c: 
At this moment there is no pages, so the list just goes on. I will however create that later on, when i get more time.
 Preview Image
 
You can download the plugin from my GitHub page below   
https://github.com/jonnyboy0719/Cuberite...ermissions
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 4,637 
	Threads: 115 
	Joined: Dec 2011
	
 Thanks: 697 
	Given 518 thank(s) in 441 post(s)
  
	 
 
	
	
		Ooh, that's a great idea. Perhaps you could categorize all the permissions. Something like: 
WorldEdit
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 25 
	Threads: 6 
	Joined: Oct 2015
	
 Thanks: 5 
	Given 12 thank(s) in 6 post(s)
  
	 
 
	
	
		 (10-08-2015, 05:03 AM)NiLSPACE Wrote:  Ooh, that's a great idea. Perhaps you could categorize all the permissions. Something like: 
WorldEdit
 
Yeah, that what i did first, before i redid my code (everything was manual  ). Currently using the same function/hook thing that help.lua uses. No idea if i can somehow retrieve  Name from g_PluginInfo.
	  
	
	
	
	
 
 
	
	
	
		
	Posts: 4,637 
	Threads: 115 
	Joined: Dec 2011
	
 Thanks: 697 
	Given 518 thank(s) in 441 post(s)
  
	 
 
	
		
		
		10-08-2015, 06:17 AM 
(This post was last modified: 10-08-2015, 06:25 AM by NiLSPACE.)
		
	 
	
		Looking at the code you aren't actually using g_PluginInfo. You're looping through all the known commands and getting the info from there. As of yet every plugin I've seen uses "<PluginName>.<Permission>" in their permissions. You could thus get the name by using something like this: 
local PluginName = a_CBPermission:match("^.-%.")
This would of course mean that you'd mostly have lowercase plugin names like "worldedit" instead of "WorldEdit" (unless a plugin has permissions that look weird)
 
If you would actually use the Info.lua file you would use something like this:
 
cPluginManager:ForEachPlugin(
	function(a_Plugin)
		if (not cFile:Exists(a_Plugin:GetLocalFolder() .. "/Info.lua")) then
			-- The plugin doesn't have a Info.lua file
			return false
		end
		
		local PluginInfoLoader = loadfile(a_Plugin:GetLocalFolder() .. "/Info.lua")
		local LoaderEnv = {}
		
		-- This way the function can't overwrite any of the functions in this environment.
		-- And we can extract the g_PluginInfo variable
		setfenv(PluginInfoLoader, LoaderEnv)
		
		local PluginInfo = LoaderEnv["g_PluginInfo"]
		local PluginName = PluginInfo.Name -- You can also use a_Plugin:GetName() of course.
		
		-- For each command like usually.
		for CommandString, CommandInfo in pairs(PluginInfo.Commands) do
			ins(Row, "<tr></td><td valign='top'>" .. CommandString .. "<br/></td><td valign='top'>" .. (CommandInfo.Permission or "") .. "<br/></td><td valign='top'>" .. (CommandInfo.HelpString or "") .. "<br/></td><td valign='top'></tr>")
		end
	end
)
Keep in mind that I haven't tested this    It could fail miserably.
 
 
I believe the prettifier escaped some single quotes. You probably need to fix that before testing   
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 6,482 
	Threads: 176 
	Joined: Jan 2012
	
 Thanks: 131 
	Given 1085 thank(s) in 857 post(s)
  
	 
 
	
	
		That's a great idea, thanks! (And welcome to the forum, by the way    ) 
Keep in mind that there are plugins that use subcommands ("/time set" etc.), your plugin may want to parse those as well.
 
As a side idea, it would be even better to allow the admin to assign the permission to a permission-group, somehow. My first idea: add an Assign button in each permission's row and the page that it displays would have a list of all permission groups and a button to add the permission or add as restriction. Some special care would be needed if the group already contained a parent permission, such as "core.*"; it would make sense to disable adding any "core.something" permission to such a group (but still makes sense to add it as a restriction).
	  
	
	
	
	
 
 
	
	
	
		
	Posts: 6,482 
	Threads: 176 
	Joined: Jan 2012
	
 Thanks: 131 
	Given 1085 thank(s) in 857 post(s)
  
	 
 
	
	
		Heh, the web handler structure seems familiar, I suppose You cloned it off one of my plugins - Gallery, GalExport, or my additions to the Core?   
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 25 
	Threads: 6 
	Joined: Oct 2015
	
 Thanks: 5 
	Given 12 thank(s) in 6 post(s)
  
	 
 
	
	
		 (10-08-2015, 07:09 AM)xoft Wrote:  Heh, the web handler structure seems familiar, I suppose You cloned it off one of my plugins - Gallery, GalExport, or my additions to the Core?   
heh, yeah. I was lazy & tierd at that time, sorry   And thanks for the warm welcome   
 (10-08-2015, 06:17 AM)NiLSPACE Wrote:  
cPluginManager:ForEachPlugin(
	function(a_Plugin)
		if (not cFile:Exists(a_Plugin:GetLocalFolder() .. "/Info.lua")) then
			-- The plugin doesn't have a Info.lua file
			return false
		end
		
		local PluginInfoLoader = loadfile(a_Plugin:GetLocalFolder() .. "/Info.lua")
		local LoaderEnv = {}
		
		-- This way the function can't overwrite any of the functions in this environment.
		-- And we can extract the g_PluginInfo variable
		setfenv(PluginInfoLoader, LoaderEnv)
		
		local PluginInfo = LoaderEnv["g_PluginInfo"]
		local PluginName = PluginInfo.Name -- You can also use a_Plugin:GetName() of course.
		
		-- For each command like usually.
		for CommandString, CommandInfo in pairs(PluginInfo.Commands) do
			ins(Row, "<tr></td><td valign='top'>" .. CommandString .. "<br/></td><td valign='top'>" .. (CommandInfo.Permission or "") .. "<br/></td><td valign='top'>" .. (CommandInfo.HelpString or "") .. "<br/></td><td valign='top'></tr>")
		end
	end
)
Keep in mind that I haven't tested this   It could fail miserably. 
 
I believe the prettifier escaped some single quotes. You probably need to fix that before testing   
The code should work, but its just the setfenv(function, table) that isn't working properly, It always prints an empty table  
I also made a failstate, so it doesn't puke out errors.
 
local function GetPlugins()
	local Row = {}
	-- Lets grab all plugin permission, commands and help string
	cPluginManager:ForEachPlugin(
		function(a_Plugin)
			if (not cFile:IsFile(a_Plugin:GetLocalFolder() .. "/Info.lua")) then
				-- The plugin doesn't have a Info.lua file
				return false
			end
			
			local PluginInfoLoader = loadfile(a_Plugin:GetLocalFolder() .. "/Info.lua")
			local LoaderEnv = {}
			
			-- This way the function can't overwrite any of the functions in this environment.
			-- And we can extract the g_PluginInfo variable
			setfenv(PluginInfoLoader, LoaderEnv)
			
			local PluginInfo = LoaderEnv["g_PluginInfo"]
			
			-- Instead of puking out errors, lets do a failstate
			-- by making everything "Invalid"
			if PluginInfo == nil then
				ins(LoaderEnv, {
					["g_PluginInfo"] =
					{
						Name = "Invalid",
						Commands = {
							["/example"] = 
							{
								Permission = "example.core",
								Handler = HandleInvalid,
								HelpString = "Invalid",
							},
							["/another_example"] = 
							{
								Permission = "example.another",
								Handler = HandleInvalid,
								HelpString = "Another Invalid",
							},
						}
					}
				})
				PluginInfo = LoaderEnv[1]["g_PluginInfo"]
			end
			
			local PluginName = PluginInfo.Name -- You can also use a_Plugin:GetName() of course.
			
			-- For each command like usually.
			for CommandString, CommandInfo in pairs(PluginInfo.Commands) do
				ins(Row, "<tr></td><td valign='top'>" .. CommandString .. "<br/></td><td valign='top'>" .. (CommandInfo.Permission or "") .. "<br/></td><td valign='top'>" .. (CommandInfo.HelpString or "") .. "<br/></td><td valign='top'></tr>")
			end
		end
	)
	
	return con(Row)
end
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 25 
	Threads: 6 
	Joined: Oct 2015
	
 Thanks: 5 
	Given 12 thank(s) in 6 post(s)
  
	 
 
	
		
		
		10-08-2015, 09:34 AM 
(This post was last modified: 10-08-2015, 09:35 AM by JonnyBoy0719.)
		
	 
	
		Modified the function GetPlugins() a tiny bit, added a "Info Counter", basically it counts everytime it finds a Info.lua file, if none were found (counter is still on 0) it won't show the failsafe, since that will be empty, but will instead tell the player that none of the enabled plugins have a info.lua file :3
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 4,637 
	Threads: 115 
	Joined: Dec 2011
	
 Thanks: 697 
	Given 518 thank(s) in 441 post(s)
  
	 
 
	
		
		
		10-08-2015, 04:36 PM 
(This post was last modified: 10-08-2015, 04:41 PM by NiLSPACE.)
		
	 
	
		I don't really think the failsafe is needed. If the Info.lua exists but is invalid then the plugin might not even be loaded. 
That got me thinking, this plugin also shows permissions from plugins that aren't loaded. If you want to remove those you might want to put
 
if (not a_Plugin:IsLoaded()) then
   return false
end
 
At the top of the ForEachPlugin callback.
 
 
Also, I found out why the LoaderEnv table is empty. I forgot to actually call the loader    If you'd use "PluginInfoLoader()" after the setfenv function it works normally.
	  
	
	
	
	
 
 
	
	
	
		
	Posts: 25 
	Threads: 6 
	Joined: Oct 2015
	
 Thanks: 5 
	Given 12 thank(s) in 6 post(s)
  
	 
 
	
	
		Thanks for the help NiLSPACE  
I have also removed some code and redid some areas, this is how it currently looks (Add Permission button doesn't work yet, but i will get onto it)
 https://youtu.be/dyaF_Mflv4Q
	 
	
	
	
	
 
 
	 
 |