-- Excl's Jailbreak 7 Commands for ULX
-- Module created by Ryan Hemmet

local CATEGORY_NAME_UTILITY = "Jailbreak Utility"
local CATEGORY_NAME_MISC = "Jailbreak Misc"

--[Utility]
-- 1 Used to set a player to prisoner
function ulx.prisoner(calling_ply, target_ply)
	if target_ply:Team() == TEAM_PRISONER then
		ULib.tsayError( calling_ply, target_ply:Nick() .. " is already a prisoner!", true)
	else
		target_ply:Kill()
		target_ply:SetTeam(TEAM_PRISONER);
		ulx.fancyLogAdmin( calling_ply, "#A set prisoner for #T", target_ply)
	end
end

local prisoner = ulx.command(CATEGORY_NAME_UTILITY, "ulx prisoner", ulx.prisoner, "!setprisoner")
prisoner:addParam{ type=ULib.cmds.PlayerArg}
prisoner:defaultAccess(ULib.ACCESS_SUPERADMIN)
prisoner:help( "Sets target player to prisoner" )

-- 2 Used to set a player to guard
function ulx.guard(calling_ply, target_ply)
	if target_ply:Team() == TEAM_GUARD then
		ULib.tsayError( calling_ply, target_ply:Nick() .. " is already a guard!", true)
	else
		target_ply:Kill()
		target_ply:SetTeam(TEAM_GUARD);
		ulx.fancyLogAdmin( calling_ply, "#A set guard for #T", target_ply)
	end
end

local guard = ulx.command(CATEGORY_NAME_UTILITY, "ulx guard", ulx.guard, "!setguard")
guard:addParam{ type=ULib.cmds.PlayerArg}
guard:defaultAccess(ULib.ACCESS_SUPERADMIN)
guard:help( "Sets target player to guard" )

-- 3 Used to set a player to spectator
function ulx.spectator(calling_ply, target_ply)
	if target_ply:Team() == TEAM_SPECTATOR then
		ULib.tsayError( calling_ply, target_ply:Nick() .. " is already a spectator!", true)
	else
		target_ply:Kill()
		target_ply:SetTeam(TEAM_SPECTATOR)
		ulx.fancyLogAdmin( calling_ply, "#A set spectator for #T", target_ply)
	end
end

local spectator = ulx.command(CATEGORY_NAME_UTILITY, "ulx spectator", ulx.spectator, "!setspectator")
spectator:addParam{ type=ULib.cmds.PlayerArg}
spectator:defaultAccess(ULib.ACCESS_SUPERADMIN)
spectator:help( "Sets target player to spectator" )

-- 4 Sets player to warden
function ulx.warden(calling_ply, target_ply)

	if target_ply:Team() == TEAM_GUARD then
		target_ply:AddWardenStatus()
		ulx.fancyLogAdmin( target_ply, "#A has been set to warden by #T", calling_ply)
	else
		ULib.tsayError( calling_ply, target_ply:Nick() .. " is not a guard!", true)
	end	
end

local warden = ulx.command(CATEGORY_NAME_UTILITY, "ulx warden", ulx.warden, "!setwarden")
warden:addParam{type=ULib.cmds.PlayerArg}
warden:defaultAccess(ULib.ACCESS_SUPERADMIN)
warden:help( "Sets player to warden" )

-- 5 Removes player from warden
function ulx.rwarden(calling_ply, target_ply)
	if target_ply:Team() == TEAM_GUARD then
		target_ply:RemoveWardenStatus()
		ulx.fancyLogAdmin( target_ply, "#T has been removed from warden by #A", calling_ply)
	else
		ULib.tsayError( calling_ply, target_ply:Nick() .. "  is not a guard!", true )
	end
end

local rwarden = ulx.command(CATEGORY_NAME_UTILITY, "ulx removewarden", ulx.rwarden, "!removewarden")
rwarden:addParam{type=ULib.cmds.PlayerArg}
rwarden:defaultAccess(ULib.ACCESS_SUPERADMIN)
rwarden:help( "Removes player from warden" )

-- 6 Ends Round
function ulx.endround(calling_ply)
	JB:EndRound(TEAM_SPECTATOR)
	ulx.fancyLogAdmin( calling_ply, "#A ended the round")
end

local endround = ulx.command(CATEGORY_NAME_UTILITY, "ulx endround", ulx.endround, "!endround")
endround:defaultAccess(ULib.ACCESS_SUPERADMIN)
endround:help( "Ends the current round" ) 

--[Misc.] Just for fun or debugging
-- 7 Used to set a player to rebel
function ulx.rebel(calling_ply, target_ply)
	target_ply:SetRebel(true)
	
	JB:BroadcastNotification(target_ply:Nick().." is rebelling!")
	
	target_ply:SetPlayerColor(Vector(1,0,0));
	target_ply:SetWeaponColor(Vector(1,0,0));
end

local rebel = ulx.command(CATEGORY_NAME_MISC, "ulx rebel", ulx.rebel)
rebel:addParam{ type=ULib.cmds.PlayerArg}
rebel:defaultAccess(ULib.ACCESS_SUPERADMIN)
rebel:help( "Sets target player to rebeler" )

-- 8 Used to set a player to not rebelling
function ulx.rebel(calling_ply, target_ply)
	target_ply:SetRebel(false)
	
	JB:BroadcastNotification(target_ply:Nick().." is no longer rebelling!")
	
	target_ply:SetPlayerColor(Vector(.9,.9,.9));
	target_ply:SetWeaponColor(Vector(.9,.9,.9));
end

local norebel = ulx.command(CATEGORY_NAME_MISC, "ulx norebel", ulx.rebel)
norebel:addParam{ type=ULib.cmds.PlayerArg}
norebel:defaultAccess(ULib.ACCESS_SUPERADMIN)
norebel:help( "Sets target player to rebeler" )

hook.Add( "PlayerInitialSpawn", "checkversion", function( ply )
local version = "1.0"
	http.Fetch( "http://ryan.razegaming.net/versioncheck/jailbreakcommands.txt", function( body ) 
		if ply:IsSuperAdmin() then
			if string.Trim( tostring( body ) ) ~= version then
				ply:ChatPrint( "ULX-Jailbreak Commands is out of date!")
				ply:ChatPrint( "Update at http://forums.ulyssesmod.net/index.php/topic,8592.0.html" )
			end
		end
	end )
end )