# titleAPI by Bryce
options:
	debug: false
	#! Make sure to set this
	# // Applical server versions
	# 1.8, 1.9, 1.10, 1.11
	serverVersion: 1.8
function title(t: text, in: number, stay: number, out: number, p: text):
	set {_t} to coloured {_t}
	set {_in} to {_in} * 20
	set {_stay} to {_stay} * 20
	set {_out} to {_out} * 20
	if {_p} = "*" or "@a":
		loop all players:
			if {@serverVersion} = "1.8":
				console command "/title %loop-player% times %{_in}% %{_stay}% %{_out}%"
				console command "/title %loop-player% title {text:""%{_t}%""}"
			else if {@serverVersion} = "1.9" or "1.10" or "1.11":
				console command "/title %loop-player% times %{_in}% %{_stay}% %{_out}%"
				console command "/title %loop-player% title {""text"":""%{_t}%""}"
	else:
		if {@serverVersion} = "1.8":
			console command "/title %{_p}% times %{_in}% %{_stay}% %{_out}%"
			console command "/title %{_p}% title {text:""%{_t}%""}"
		else if {@serverVersion} = "1.9" or "1.10" or "1.11":
			console command "/title %{_p}% times %{_in}% %{_stay}% %{_out}%"
			console command "/title %{_p}% title {""text"":""%{_t}%""}"
	{@debug} = true:
		loop all players:
			loop-player is op:
				send "&8&o[TitleAPI] &7&o(Sent &7`title` &7&ofunction to &7%{_p}%&7&o)" to loop-player
function subtitle(t: text, in: number, stay: number, out: number, p: text):
	set {_t} to coloured {_t}
	set {_in} to {_in} * 20
	set {_stay} to {_stay} * 20
	set {_out} to {_out} * 20
	if {_p} = "*" or "@a":
		loop all players:
			if {@serverVersion} = "1.8":
				console command "/title %loop-player% times %{_in}% %{_stay}% %{_out}%"
				console command "/title %loop-player% subtitle {text:""%{_t}%""}"
			else if {@serverVersion} = "1.9" or "1.10" or "1.11":
				console command "/title %loop-player% times %{_in}% %{_stay}% %{_out}%"
				console command "/title %loop-player% subtitle {""text"":""%{_t}%""}"
	else:
		if {@serverVersion} = "1.8":
			console command "/title %{_p}% times %{_in}% %{_stay}% %{_out}%"
			console command "/title %{_p}% subtitle {text:""%{_t}%""}"
		else if {@serverVersion} = "1.9" or "1.10" or "1.11":
			console command "/title %{_p}% times %{_in}% %{_stay}% %{_out}%"
			console command "/title %{_p}% subtitle {""text"":""%{_t}%""}"
	{@debug} = true:
		loop all players:
			loop-player is op:
				send "&8&o[TitleAPI] &7&o(Sent &7`subtitle` &7&ofunction to &7%{_p}%&7&o)" to loop-player
function simpleTitle(t: text, in: number, stay: number, out: number, p: text):
	set {_t} to coloured {_t}
	set {_in} to {_in} * 20
	set {_stay} to {_stay} * 20
	set {_out} to {_out} * 20
	set {_titles::*} to {_t} split at "||"
	if {_p} = "*" or "@a":
		loop all players:
			if {@serverVersion} = "1.8":
				console command "/title %loop-player% times %{_in}% %{_stay}% %{_out}%"
				console command "/title %loop-player% title {text:""%{_titles::1}%""}"
				console command "/title %loop-player% subtitle {text:""%{_titles::2}%""}"
			else if {@serverVersion} = "1.9" or "1.10" or "1.11":
				console command "/title %loop-player% times %{_in}% %{_stay}% %{_out}%"
				console command "/title %loop-player% title {""text"":""%{_titles::1}%""}"
				console command "/title %loop-player% subtitle {""text"":""%{_titles::2}%""}"
	else:
		if {@serverVersion} = "1.8":
			console command "/title %{_p}% times %{_in}% %{_stay}% %{_out}%"
			console command "/title %{_p}% title {text:""%{_titles::1}%""}"
			console command "/title %{_p}% subtitle {text:""%{_titles::2}%""}"
		else if {@serverVersion} = "1.9" or "1.10" or "1.11":
			console command "/title %{_p}% times %{_in}% %{_stay}% %{_out}%"
			console command "/title %{_p}% title {""text"":""%{_titles::1}%""}"
			console command "/title %{_p}% subtitle {""text"":""%{_titles::2}%""}"
	{@debug} = true:
		loop all players:
			loop-player is op:
				send "&8&o[TitleAPI] &7&o(Sent &7`simpleTitle` &7&ofunction to &7%{_p}%&7&o)" to loop-player
# ==========EXAMPLE
#
# ===> INPUT
# title("&fI want to &cdie", .5, 1, .5, "*")
# [This uses seconds instead of ticks]
#
# ===> OUTPUT
# Title message saying "I want to die", with an inTime of 10 ticks, stayTime of 20 ticks, outTime of 10 ticks, and sent to all players

command /sendTitle [<text>] [<number>] [<number>] [<number>] [<text>]:
	permission: rank.admin
	trigger:
		title("%arg-5%", arg-2, arg-3, arg-4, "%arg-1%")
command /sendSubtitle [<text>] [<number>] [<number>] [<number>] [<text>]:
	permission: rank.admin
	trigger:
		subtitle("%arg-5%", arg-2, arg-3, arg-4, "%arg-1%")
