return function(r,P)local L=P(nil,{script=script})setfenv(1,L)local M=r.Server local n=r.Service local c=M.Settings local D,S,O,X,q,i,k,p,R,J,H local function W()D=M.Functions O=M.Admin X=M.Anti q=M.Core i=M.HTTP k=M.Logs p=M.Remote R=M.Process J=M.Variables S=M.Commands H=M.Deps setmetatable(S,{__index=function(r,P)local L=O.CommandCache[string.lower(P)]if L then return rawget(S,L)end end,__newindex=function(r,P,L)rawset(S,P,L)if L and(type(L)=="\116\097\098\108\101"and(L.Commands and L.Prefix))then for r,M in pairs(L.Commands)do O.PrefixCache[L.Prefix]=true O.CommandCache[string.lower(L.Prefix..M)]=P end end end})k: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 M.CommandModules then local L=P()for P,M in ipairs(M.CommandModules:GetChildren())do local n=require(M)local c,D=pcall(n,r,L)if c and(D and type(D)=="\116\097\098\108\101")then for r,P in pairs(D)do S[r]=P end k: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 "..M.Name)elseif not c then warn("\067\077\068\077\079\068\085\076\069 "..(M.Name.." \102\097\105\108\101\100 \116\111 \108\111\097\100\058"))warn(tostring(D))k: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 "..M.Name)end end end O.CacheCommands()S.Init=nil k: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 A()for r,P in pairs(c.Commands or{})do if type(P)=="\116\097\098\108\101"and P.Function then setfenv(P.Function,getfenv())S[r]=P end end local r=n.Trim for P,L in pairs(c.Permissions or{})do local M,n=string.match(L,"\094\040\046\042\041\058\040\046\042\041")if M and n then if string.find(n,"\044")then local P={}for L in string.gmatch(n,"\091\094\037\115\044\093\043")do table.insert(P,r(L))end O.SetPermission(M,P)else O.SetPermission(M,n)end end end for r,P in pairs(S)do if type(P)=="\116\097\098\108\101"and P.AdminLevel then local L=P.AdminLevel if type(L)=="\115\116\114\105\110\103"then P.AdminLevel=O.StringToComLevel(L)elseif type(L)=="\116\097\098\108\101"then for r,P in pairs(L)do L[r]=O.StringToComLevel(P)end elseif type(L)=="\110\105\108"then P.AdminLevel=0 end if not P.Prefix then P.Prefix=c.Prefix end if not P.Args then P.Args={}end if not P.Function then P.Function=function(r)p.MakeGui(r,"\079\117\116\112\117\116",{Message="\078\111 \099\111\109\109\097\110\100 \105\109\112\108\101\109\101\110\116\097\116\105\111\110"})end end if P.ListUpdater then k.ListUpdaters[r]=function(r,...)if not r or O.CheckComLevel(O.GetLevel(r),P.AdminLevel)then if type(P.ListUpdater)=="\102\117\110\099\116\105\111\110"then return P.ListUpdater(r,...)end return k[P.ListUpdater]end end end end end S.RunAfterPlugins=nil end M.Commands={Init=W,RunAfterPlugins=A}end
--// Commands
--// Highly recommended you disable Intellesense before editing this...
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
				elseif type(lvl) == "nil" then
					cmd.AdminLevel = 0
				end

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

				if not cmd.Args then
					cmd.Args = {}
				end

				if not cmd.Function then
					cmd.Function = function(plr)
						Remote.MakeGui(plr, "Output", { Message = "No command implementation" })
					end
				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
