flycard.sk

Created by ShaneBee

Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.

# _______  ___      __   __    _______  _______  ______    ______
#|       ||   |    |  | |  |  |       ||   _   ||    _ |  |      |
#|    ___||   |    |  |_|  |  |       ||  |_|  ||   | ||  |  _    |
#|   |___ |   |    |       |  |       ||       ||   |_||_ | | |   |
#|    ___||   |___ |_     _|  |      _||       ||    __  || |_|   |
#|   |    |       |  |   |    |     |_ |   _   ||   |  | ||       |
#|___|    |_______|  |___|    |_______||__| |__||___|  |_||______|

#    Created by ShaneBee

options:
	server: YourServerHere #<-- color codes can be used as well
	prefix: &7[&b&lFlyCard&7] #<--- Use any prefix you would like, currently set to "FlyCard" in pink/purple
	version: 1.6.2 #! Do not edit version

	UpdateChecker: true # Whether or not this skript will check for updates during loading

	flyminutes: 30 # You can choose how many minutes the fly card will last for

	#!Enable or disable combat mode - In combat mode, if a player is flying, and hits another player, they loose their flight for the defined time
	combatmode: true
	combattimeout: 15 seconds

on load:
	if {@UpdateChecker} is true:
		send a "GET" request to "https://raw.githubusercontent.com/ShaneBeee/FlyCard/master/version"
		set {_t} to last http response
		set {_j} to {_t}'s body
		set {_v::*} to {_j} split at "|"
		send "&7[&bFlyCard&7] - &2Loaded successfully" to console
		if "{@version}" is not equal to "%{_v::2}%":
			send "&7[&bFlyCard&7] - &2Running version: {@version}" to console
			send "&7[&bFlyCard&7] - &cUpdate available, version: %{_v::2}%" to console
		else:
			send "&7[&bFlyCard&7] - &2Running current version: {@version}" to console
	else:
		send "&7[&bFlyCard&7] - &2Loaded successfully" to console
		send "&7[&bFlyCard&7] - &2Running version: {@version}" to console

on join:
	if {@UpdateChecker} is true:
		wait 1 second
		if player has permission "flycard.admin":
			send a "GET" request to "https://raw.githubusercontent.com/ShaneBeee/FlyCard/master/version"
			set {_t} to last http response
			set {_j} to {_t}'s body
			set {_v::*} to {_j} split at "|"
			if "{@version}" is not equal to "%{_v::2}%":
				send "&7[&bFlyCard&7] - &2Running version: {@version}" to player
				send "&7[&bFlyCard&7] - &cUpdate available, version: %{_v::2}%" to player

command /flycard [<player=%player%>]:
	description: This is used to give flycards to players
	permission: flycard.admin
	permission message: {@prefix} - &cYou do not have permission for this command
	trigger:
		give arg-1 1 paper named "&2&lFly&a&lCard" with lore " ||&7This is your FlyCard||&7It is a &6ONE TIME USE &7card!||&7FlyCards give you &b{@flyminutes} minutes||&7of fly time! Use WISELY!|| ||&dFlyCards are stackable"

command /flyclear [<player>]:
	description: This is used to clear a players flytime and flymode
	permission: flycard.admin
	permission message: {@prefix} - &cYou do not have permission for this command
	trigger:
		if arg-1 is set:
			delete {flycard::%arg-1%::*}
			set arg-1's fly mode to false
		else:
			send "{@prefix} - &6Correct usage &b/flyclear <player>"
		
function flycard(p: player):
	set {_p}'s fly mode to true
	set {flycard::%{_p}%::board} to true
	while {flycard::%{_p}%::timeleft} is set:
		if "%{_p}%" parsed as offline player is online:
			if {flycard::%{_p}%::timeleft} > 0 seconds:
				remove 1 second from {flycard::%{_p}%::timeleft}
			if {flycard::%{_p}%::timeleft} = 1 minute:
				send "{@prefix} - &aYour fly time will run out in &b1 minute&a!" to {_p}
			if {flycard::%{_p}%::timeleft} = 9 seconds:
				send "{@prefix} - &aYour fly time will run out in &b10 seconds&a!" to {_p}
				send "{@prefix} - &aPrepare for a safe landing" to {_p}
			if {flycard::%{_p}%::timeleft} = 3 seconds:
				send "{@prefix} - &cFLIGHT IS OVER IN..." to {_p}
			if {flycard::%{_p}%::timeleft} = 2 seconds:
				send "{@prefix} - &c... 3 ..." to {_p}
			if {flycard::%{_p}%::timeleft} = 1 seconds:
				send "{@prefix} - &c... 2 ..." to {_p}
			if {flycard::%{_p}%::timeleft} = 0 seconds:
				send "{@prefix} - &c... 1 ..." to {_p}
				wait 1 second
				send "{@prefix} - &aYour fly time has &cExpired&a!" to {_p}
				send "{@prefix} - &aWe hope you enjoyed flying with {@server}" to {_p}
				set {_p}'s fly mode to false
				delete {flycard::%{_p}%::*}
				stop
			wait 1 second
		else:
			stop

on right-click holding a paper:
	if "%lore of players's tool%" contains "This is your FlyCard":
		wait 1 tick
		remove 1 of item from player's inventory
		if {flycard::%player%::timeleft} is set:
			add "{@flyminutes} minutes" parsed as timespan to {flycard::%player%::timeleft}
			send "&9&l+----------{@prefix}&9&l----------+"
			send " "
			send "&aYou added &b{@flyminutes} minutes&a to your fly time!"
			send "&aToggle your FlyBoard with &c/flyboard"
			send " "
			send "&9&l+---------------------------+"
		else:
			add "{@flyminutes} minutes" parsed as timespan to {flycard::%player%::timeleft}
			send "&9&l+----------{@prefix}&9&l----------+"
			send " "
			send "&aYou can now fly for &b%{flycard::%player%::timeleft}%!"
			send "          &aEnjoy your flight!"
			send "&aToggle your FlyBoard with &c/flyboard"
			send " "
			send "&9&l+---------------------------+"
			flycard(player)

on join:
	if {flycard::%player%::timeleft} is set:
		set player's fly mode to true
		wait 1 second
		send "{@prefix} - &aYou still have &b%{flycard::%player%::timeleft}% &aof flytime left" to player
		flycard(player)

on player world change:
	if {flycard::%player%::timeleft} is set:
		set player's fly mode to true

command /flytime [<offline player=%player%>]:
	trigger:
		if {flycard::%arg-1%::timeleft} is set:
			if arg-1 is player:
				send "{@prefix} - &aYou have &b%{flycard::%arg-1%::timeleft}% minutes &aof flytime left" to player
			else:
				if sender has permission "flycard.admin":
					send "{@prefix} - &b%arg-1% &ahas &b%{flycard::%arg-1%::timeleft}% minutes &aof flytime left" to sender
				else:
					send "{@prefix} - &cYou do not have permission to use this command"
		if {flycard::%arg-1%::timeleft} is not set:
			if arg-1 is player:
				send "{@prefix} - &cYou currently have no flytime available" to player
			else:
				if sender has permission "flycard.admin":
					send "{@prefix} - &b%arg-1% &ccurrently has no flytime available" to sender
				else:
					send "{@prefix} - &cYou do not have permission to use this command"

command /flycheck [<player>]:
	trigger:
		if player has permission "flycard.admin":
			if arg-1 is not set:
				if player's fly mode is true:
					send "&6Flight Mode: &aTRUE" to player
				if player's fly mode is false:
					send "&6Flight Mode: &cFALSE" to player
			if arg-1 is set:
				if arg-1's fly mode is true:
					send "&b%arg-1%&6's Flight Mode: &aTRUE" to player
					if {flycard::%arg-1%::timeleft} is set:
						send "&b%arg-1%&6's Remaining Fly Time: &a%{flycard::%arg-1%::timeleft}%"
					else:
						send "&b%arg-1%&6 has no remaining fly time... Flying by other means"
				if arg-1's fly mode is false:
					send "&b%arg-1%&6's Flight Mode: &cFALSE" to player
					
#! --- New Combat Mode --- !# -- Used to give a little timeout for hitting someone

function combat(p: player):
	while {flycard::combat::%{_p}%} is set:
		if difference between now and {flycard::combat::%{_p}%} > {@combattimeout}:
			delete {flycard::combat::%{_p}%} 
			set fly mode of {_p} to true
			send "{@prefix} - &6Combat mode is now OVER, flight has been &aENABLED" to {_p}
		wait 1 second

on damage:
	if {@combatmode} is true:
		if {flycard::%attacker%::timeleft} is set:
			if {flycard::combat::%attacker%} is not set:
				if victim is a player:
					set {flycard::combat::%attacker%} to now
					set attacker's fly mode to false
					combat(attacker)
					send "{@prefix} - &6You are now in combat mode, flight has been &cDISABLED &6for {@combattimeout}" to attacker
			if {flycard::combat::%attacker%} is set:
				if victim is a player:
					set {flycard::combat::%attacker%} to now
					set attacker's fly mode to false

on death:
	if victim is a player:
		if {flycard::%victim%::timeleft} is set:
			if {flycard::combat::%victim%} is set:
				delete {flycard::combat::%victim%}
				set fly mode of victim to true


#! --- SCOREBOARD --- !# --- If you do not want to use the scoreboard system, remove this section

command /flyboard:
	trigger:
		if {flycard::%player%::board} is true:
			set {flycard::%player%::board} to false
			send "{@prefix} - &cFlyBoard has been disabled" to player
			stop
		if {flycard::%player%::board} is false:
			set {flycard::%player%::board} to true
			send "{@prefix} - &aFlyBoard has been enabled" to player
			stop


function roundSpan(t: timespan) :: timespan:
	set {_s::*} to split "%{_t}%" at " "
	loop {_s::*}:
		delete {_rounded}
		set {_rounded} to loop-value parsed as a number
		set {_s1::%loop-index%} to round({_rounded}) if {_rounded} is set else loop-value
	return (join {_s1::*} with " ") parsed as a timespan

function flyBoard(p: player):
	while "%{_p}%" parsed as offline player is online:
		if {flycard::%{_p}%::timeleft} is set:
			if {flycard::%{_p}%::board} is true:
				if {flycard::combat::%{_p}%} is set:
					if stylish scoreboard "flycard-%{_p}%-combat" does not exist:
						set {_time} to difference between now and {flycard::combat::%{_p}%}
						set {_dif} to difference between {_time} and {@combattimeout}
						set {_time} to "%roundSpan({_dif})%"
						replace all "second" with "sec" in {_time}
						delete stylish scoreboard "flycard-%{_p}%"
						create new stylish scoreboard named "flycard-%{_p}%-combat"
						create a new id based score "%{_p}%-1" with text "&3Remaining Fly Time:" slot 4 for stylish scoreboard "flycard-%{_p}%-combat"
						set {_time2} to "%{flycard::%{_p}%::timeleft}%"
						replace all "second" with "sec" in {_time2}
						replace all "minute" with "min" in {_time2}
						create a new id based score "%{_p}%-2" with text "&a%{_time2}%" slot 3 for stylish scoreboard "flycard-%{_p}%-combat"
						create a new id based score "%{_p}%-3" with text "&3Combat Timeout:" slot 2 for stylish scoreboard "flycard-%{_p}%-combat"
						create a new id based score "%{_p}%-4" with text "&c%{_time}%" slot 1 for stylish scoreboard "flycard-%{_p}%-combat"
						set title of stylish scoreboard "flycard-%{_p}%-combat" to "{@prefix}"
						set stylish scoreboard of {_p} to "flycard-%{_p}%-combat"
					else:
						set {_time2} to "%{flycard::%{_p}%::timeleft}%"
						replace all "second" with "sec" in {_time2}
						replace all "minute" with "min" in {_time2}
						set {_time} to difference between now and {flycard::combat::%{_p}%}
						set {_dif} to difference between {_time} and {@combattimeout}
						set {_time} to "%roundSpan({_dif})%"
						replace all "second" with "sec" in {_time}
						set text of id "%{_p}%-2" to "&a%{_time2}%" 
						set text of id "%{_p}%-4" to "&c%{_time}%"
				if {flycard::combat::%{_p}%} is not set:
					if stylish scoreboard "flycard-%{_p}%" does not exist:
						delete stylish scoreboard "flycard-%{_p}%-combat"
						create new stylish scoreboard named "flycard-%{_p}%"
						create a new id based score "%{_p}%-1" with text "&3Remaining Fly Time:" slot 2 for stylish scoreboard "flycard-%{_p}%"
						set {_time} to "%{flycard::%{_p}%::timeleft}%"
						replace all "second" with "sec" in {_time}
						replace all "minute" with "min" in {_time}
						create a new id based score "%{_p}%-2" with text "&a%{_time}%" slot 1 for stylish scoreboard "flycard-%{_p}%"
						set title of stylish scoreboard "flycard-%{_p}%" to "{@prefix}"
						set stylish scoreboard of {_p} to "flycard-%{_p}%"
					else:
						set {_time} to "%{flycard::%{_p}%::timeleft}%"
						replace all "second" with "sec" in {_time}
						replace all "minute" with "min" in {_time}
						if {flycard::%{_p}%::timeleft} > 30 seconds:
							set text of id "%{_p}%-2" to "&a%{_time}%"
						else:
							set text of id "%{_p}%-2" to "&c%{_time}%"
			if {flycard::%{_p}%::board} is false:
				delete stylish scoreboard "flycard-%{_p}%"
				delete stylish scoreboard "flycard-%{_p}%-combat"
		else:
			delete stylish scoreboard "flycard-%{_p}%"
			delete stylish scoreboard "flycard-%{_p}%-combat"
			stop
		wait 1 second
	delete stylish scoreboard "flycard-%{_p}%"
	delete stylish scoreboard "flycard-%{_p}%-combat"
	stop

on right-click holding a paper:
	if "%lore of players's tool%" contains "This is your FlyCard":
		wait 1 second
		flyBoard(player)

on join:
	if {flycard::%player%::timeleft} is set:
		set {flycard::%player%::board} to true
		flyBoard(player)