
# -> Reset adv trigger
advancement revoke @s only overly_realistic:items/use_bandage

# -> Add to bandage timer
scoreboard players add @s OverlyRealistic.Player.UseBandageTimer 1

# -> If timer is less than the max then return
execute unless score @s OverlyRealistic.Player.UseBandageTimer matches 10.. run \
    return fail

# -> Add to bandage usage
scoreboard players add @s OverlyRealistic.Player.UseItem_Bandage 1

# -> Debug
#tellraw @s [{score:{name:"@s",objective:"OverlyRealistic.Player.UseItem_Bandage"}},{text:" / "},{score:{name:"@s",objective:"OverlyRealistic.Player.UseItem_Bandage_Max"}}]

# -> Reset timer
scoreboard players reset @s OverlyRealistic.Player.UseBandageTimer

# -> Sound
playsound minecraft:block.wool.step player @a ~ ~ ~ 0.5 2

# -> If bandage usage time >= max time then use the bandage item
execute if score @s OverlyRealistic.Player.UseItem_Bandage >= @s OverlyRealistic.Player.UseItem_Bandage_Max run \
    return run \
        function overly_realistic:players/operations/player_use_bandage

# -> If player is not shifting then return
execute unless score @s OverlyRealistic.PredicateValue.IsSneaking matches 1 run \
    return fail

# -> Set title time
title @s times 0 15 0

# -> If there is a player in front of the user then set title
tag @s add OverlyRealistic.Player.TempBandagePlayer
title @s title ""
execute anchored eyes \
    positioned ^ ^ ^1 \
    positioned ~-1 ~-1 ~-1 \
    if entity @p[tag=!OverlyRealistic.Player.TempBandagePlayer,dx=1,dy=1,dz=1] run \
        title @s subtitle [{text:"[Bandaging Player]"}]
tag @s remove OverlyRealistic.Player.TempBandagePlayer
