return function(l,E)local O=E(nil,{script=script})setfenv(1,O)local u=l.Server local I=l.Service local J=u.Settings local q,c,n,x,o,z,y,t,F,T,V local function j()q=u.Functions n=u.Admin x=u.Anti o=u.Core z=u.HTTP y=u.Logs t=u.Remote F=u.Process T=u.Variables c=u.Commands V=u.Deps setmetatable(c,{__index=function(l,E)local O=n.CommandCache[string.lower(E)]if O then return rawget(c,O)end end;__newindex=function(l,E,O)rawset(c,E,O)if O and(type(O)=="\116\097\098\108\101"and(O.Commands and O.Prefix))then for l,u in pairs(O.Commands)do n.PrefixCache[O.Prefix]=true n.CommandCache[string.lower(O.Prefix..u)]=E end end end})y:AddLog("\083\099\114\105\112\116","\076\111\097\100\105\110\103 \067\111\109\109\097\110\100 \077\111\100\117\108\101\115\046\046\046")if u.CommandModules then local O=E()for E,u in ipairs(u.CommandModules:GetChildren())do local I=require(u)local J,q=pcall(I,l,O)if J and(q and type(q)=="\116\097\098\108\101")then for l,E in pairs(q)do c[l]=E end y:AddLog("\083\099\114\105\112\116","\076\111\097\100\101\100 \067\111\109\109\097\110\100 \077\111\100\117\108\101\058 "..u.Name)elseif not J then warn("\067\077\068\077\079\068\085\076\069 "..(u.Name.." \102\097\105\108\101\100 \116\111 \108\111\097\100\058"))warn(tostring(q))y:AddLog("\083\099\114\105\112\116","\076\111\097\100\105\110\103 \067\111\109\109\097\110\100 \077\111\100\117\108\101 \070\097\105\108\101\100\058 "..u.Name)end end end n.CacheCommands()c.Init=nil y:AddLog("\083\099\114\105\112\116","\067\111\109\109\097\110\100\115 \077\111\100\117\108\101 \073\110\105\116\105\097\108\105\122\101\100")end local function s()for l,E in pairs(J.Commands or{})do if type(E)=="\116\097\098\108\101"and E.Function then setfenv(E.Function,getfenv())c[l]=E end end local l=I.Trim for E,O in pairs(J.Permissions or{})do local u,I=string.match(O,"\094\040\046\042\041\058\040\046\042\041")if u and I then if string.find(I,"\044")then local E={}for O in string.gmatch(I,"\091\094\037\115\044\093\043")do table.insert(E,l(O))end n.SetPermission(u,E)else n.SetPermission(u,I)end end end for l,E in pairs(c)do if type(E)=="\116\097\098\108\101"and E.AdminLevel then local O=E.AdminLevel if type(O)=="\115\116\114\105\110\103"then E.AdminLevel=n.StringToComLevel(O)elseif type(O)=="\116\097\098\108\101"then for l,E in pairs(O)do O[l]=n.StringToComLevel(E)end end if not E.Prefix then E.Prefix=J.Prefix end if E.ListUpdater then y.ListUpdaters[l]=function(l,...)if not l or n.CheckComLevel(n.GetLevel(l),E.AdminLevel)then if type(E.ListUpdater)=="\102\117\110\099\116\105\111\110"then return E.ListUpdater(l,...)end return y[E.ListUpdater]end end end end end c.RunAfterPlugins=nil end u.Commands={Init=j;RunAfterPlugins=s}end

return function(Vargs, GetEnv)
	local env = GetEnv(nil, {script = script})
	setfenv(1, env)

	local server = Vargs.Server
	local service = Vargs.Service

	local Settings = server.Settings
	local Functions, Commands, Admin, Anti, Core, HTTP, Logs, Remote, Process, Variables, Deps

	local function Init()
		Functions = server.Functions;
		Admin = server.Admin;
		Anti = server.Anti;
		Core = server.Core;
		HTTP = server.HTTP;
		Logs = server.Logs;
		Remote = server.Remote;
		Process = server.Process;
		Variables = server.Variables;
		Commands = server.Commands;
		Deps = server.Deps;

		--// Automatic New Command Caching and Ability to do server.Commands[":ff"]
		setmetatable(Commands, {
			__index = function(self, ind)
				local targInd = Admin.CommandCache[string.lower(ind)]
				if targInd then
					return rawget(Commands, targInd)
				end
			end;

			__newindex = function(self, ind, val)
				rawset(Commands, ind, val)
				if val and type(val) == "table" and val.Commands and val.Prefix then
					for i, cmd in pairs(val.Commands) do
						Admin.PrefixCache[val.Prefix] = true
						Admin.CommandCache[string.lower((val.Prefix..cmd))] = ind
					end
				end
			end;
		})

		Logs:AddLog("Script", "Loading Command Modules...")

		--// Load command modules
		if server.CommandModules then
			local env = GetEnv()
			for i, module in ipairs(server.CommandModules:GetChildren()) do
				local func = require(module)
				local ran, tab = pcall(func, Vargs, env)

				if ran and tab and type(tab) == "table" then
					for ind, cmd in pairs(tab) do
						Commands[ind] = cmd
					end

					Logs:AddLog("Script", "Loaded Command Module: ".. module.Name)
				elseif not ran then
					warn("CMDMODULE ".. module.Name .. " failed to load:")
					warn(tostring(tab))
					Logs:AddLog("Script", "Loading Command Module Failed: ".. module.Name)
				end
			end
		end

		--// Cache commands
		Admin.CacheCommands()

		Commands.Init = nil
		Logs:AddLog("Script", "Commands Module Initialized")
	end;

	local function RunAfterPlugins()
		--// Load custom user-supplied commands in settings.Commands
		for ind, cmd in pairs(Settings.Commands or {}) do
			if type(cmd) == "table" and cmd.Function then
				setfenv(cmd.Function, getfenv())
				Commands[ind] = cmd
			end
		end

		--// Change command permissions based on settings
		local Trim = service.Trim
		for ind, cmd in pairs(Settings.Permissions or {}) do
			local com, level = string.match(cmd, "^(.*):(.*)")
			if com and level then
				if string.find(level, ",") then
					local newLevels = {}
					for lvl in string.gmatch(level, "[^%s,]+") do
						table.insert(newLevels, Trim(lvl))
					end

					Admin.SetPermission(com, newLevels)
				else
					Admin.SetPermission(com, level)
				end
			end
		end

		--// Update existing permissions to new levels
		for i, cmd in pairs(Commands) do
			if type(cmd) == "table" and cmd.AdminLevel then
				local lvl = cmd.AdminLevel
				if type(lvl) == "string" then
					cmd.AdminLevel = Admin.StringToComLevel(lvl)
					--print("Changed " .. tostring(lvl) .. " to " .. tostring(cmd.AdminLevel))
				elseif type(lvl) == "table" then
					for b, v in pairs(lvl) do
						lvl[b] = Admin.StringToComLevel(v)
					end
				end

				if not cmd.Prefix then
					cmd.Prefix = Settings.Prefix
				end

				if cmd.ListUpdater then
					Logs.ListUpdaters[i] = function(plr, ...)
						if not plr or Admin.CheckComLevel(Admin.GetLevel(plr), cmd.AdminLevel) then
							if type(cmd.ListUpdater) == "function" then
								return cmd.ListUpdater(plr, ...)
							end
							return Logs[cmd.ListUpdater]
						end
					end
				end
			end
		end

		Commands.RunAfterPlugins = nil
	end;

	server.Commands = {
		Init = Init;
		RunAfterPlugins = RunAfterPlugins;
	};
end
