# Gamerules
gamerule doImmediateRespawn true
gamerule spectatorsGenerateChunks true

# Revive
execute at @e[nbt={Item:{tag:{Revive:1}},PickupDelay:0s}] run tag @p[distance=..3,gamemode=spectator] add Revive
execute at @a[tag=Revive] run kill @e[nbt={Item:{tag:{Revive:1}}},limit=1,distance=..5]
execute at @a[tag=Revive] run gamemode survival @p
execute at @a[tag=Revive] run effect give @p minecraft:glowing 30 2 true
execute at @a[tag=Revive] run playsound minecraft:ui.toast.challenge_complete master @a ~ ~ ~ 10 1
execute at @a[tag=Revive] run tag @p remove Revive

# Set spawn
execute at @a run spawnpoint @p ~ ~ ~

# Ghost particles
execute at @a[gamemode=spectator] run particle minecraft:dust 1 1 1 1 ~ ~1.5 ~ 0.5 0.5 0.5 0 2 force

# Scare
execute at @a[gamemode=spectator] run tag @e[type=!minecraft:player,distance=..1] add Scared
data modify entity @e[tag=Scared,limit=1,nbt=!{TicksFrozen:0}] TicksFrozen set value 140
effect give @e[tag=Scared,nbt=!{ActiveEffects:[{Id:20}]}] minecraft:wither 3 0 true

tag @e[type=!minecraft:player] remove Scared

# Possess
execute at @a[gamemode=spectator] run tag @a[distance=..1,gamemode=survival] add Possess
effect give @a[tag=Possess] minecraft:strength 1 0 true
effect give @a[tag=Possess] minecraft:speed 1 0 true
effect give @a[tag=Possess] minecraft:resistance 1 0 true
effect give @a[tag=Possess] minecraft:glowing 1 0 true
tag @a remove Possess

# Debuffs
scoreboard players remove @a[scores={Cooldown=1..}] Cooldown 1
scoreboard players set @a[gamemode=spectator] Cooldown 0
scoreboard players set @a[scores={Cooldown=0}] Blood 0

execute at @a[scores={Blood=0}] run attribute @p[scores={Blood=0}] minecraft:generic.max_health base set 20
execute at @a[scores={Blood=1}] run attribute @p[scores={Blood=1}] minecraft:generic.max_health base set 10
execute at @a[scores={Blood=2}] run attribute @p[scores={Blood=2}] minecraft:generic.max_health base set 5
execute at @a[scores={Blood=3}] run attribute @p[scores={Blood=3}] minecraft:generic.max_health base set 2

# Blocks
execute at @a[gamemode=spectator] if block ~ ~1 ~ minecraft:furnace run data modify block ~ ~1 ~ BurnTime set value 10
execute at @a[gamemode=spectator] if block ~ ~1 ~ minecraft:smoker run data modify block ~ ~1 ~ BurnTime set value 10
execute at @a[gamemode=spectator] if block ~ ~1 ~ minecraft:blast_furnace run data modify block ~ ~1 ~ BurnTime set value 10

# Show timer
execute as @a[gamemode=survival,scores={Cooldown=1..}] run title @s actionbar ["",{"text":"Ticks Left: ","color":"gray"},{"score":{"name":"@s","objective":"Cooldown"}}]

# Fix scores
scoreboard players set @a[tag=!nHrCheck] Cooldown 0
scoreboard players set @a[tag=!nHrCheck] Blood 0

tag @a add nHrCheck