#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

execute if entity @s[tag=powerup_bossbar1] store result bossbar minecraft:powerup1 value run scoreboard players get @s poweruptime
execute if entity @s[tag=powerup_bossbar2] store result bossbar minecraft:powerup2 value run scoreboard players get @s poweruptime
execute if entity @s[tag=powerup_bossbar3] store result bossbar minecraft:powerup3 value run scoreboard players get @s poweruptime
execute if entity @s[tag=powerup_bossbar4] store result bossbar minecraft:powerup4 value run scoreboard players get @s poweruptime
scoreboard players remove @s poweruptime 1
playsound minecraft:block.beacon.deactivate master @s[scores={poweruptime=0}] ~ ~ ~ 1000000
playsound minecraft:block.note_block.snare master @s ~ ~ ~ 0.2 2

#Bossbar
execute if entity @s[tag=powerup_bossbar1] run bossbar set minecraft:powerup1 players @s
execute if entity @s[tag=powerup_bossbar2] run bossbar set minecraft:powerup2 players @s
execute if entity @s[tag=powerup_bossbar3] run bossbar set minecraft:powerup3 players @s
execute if entity @s[tag=powerup_bossbar4] run bossbar set minecraft:powerup4 players @s
execute if score @s[tag=powerup_bossbar1] poweruptime matches ..0 run bossbar set minecraft:powerup1 players
execute if score @s[tag=powerup_bossbar2] poweruptime matches ..0 run bossbar set minecraft:powerup2 players
execute if score @s[tag=powerup_bossbar3] poweruptime matches ..0 run bossbar set minecraft:powerup3 players
execute if score @s[tag=powerup_bossbar4] poweruptime matches ..0 run bossbar set minecraft:powerup4 players

#Effects
effect give @s[tag=speed,scores={poweruptime=20..}] speed 1 6 true
effect give @s[tag=speed,scores={poweruptime=20..}] jump_boost 1 1 true
effect give @s[tag=invisible,scores={poweruptime=20..}] invisibility 1 0 true
clear @s[tag=invisible] leather_chestplate

tag @s[scores={poweruptime=..0}] remove invisible
tag @s[scores={poweruptime=..0}] remove machinegun
tag @s[scores={poweruptime=..0}] remove invulnerable
tag @s[scores={poweruptime=..0}] remove base
tag @s[scores={poweruptime=..0}] remove speed
tag @s[scores={poweruptime=..0}] remove goldmultiplier
tag @s[scores={poweruptime=..0}] remove get_powerup
tag @s[scores={poweruptime=..0}] remove powerup_bossbar1
tag @s[scores={poweruptime=..0}] remove powerup_bossbar2
tag @s[scores={poweruptime=..0}] remove powerup_bossbar3
tag @s[scores={poweruptime=..0}] remove powerup_bossbar4

execute at @s[tag=invulnerable] run particle minecraft:block_marker barrier ~ ~0.7 ~ 0 0 0 0 1

#base powerup
execute if entity @s[tag=base] run function f:game/powerup/base

#end base
execute unless entity @p[team=blue,tag=base] run kill @e[tag=base_barrier_blue]
execute unless entity @p[team=red,tag=base] run kill @e[tag=base_barrier_red]
execute unless entity @p[team=green,tag=base] run kill @e[tag=base_barrier_green]
execute unless entity @p[team=yellow,tag=base] run kill @e[tag=base_barrier_yellow]