
# -> If player is in creative or spectator then return
#execute unless entity @s[gamemode=survival] \
    unless entity @s[gamemode=adventure] run \
        return fail

# -> Add to loneliness check timer
scoreboard players add @s OverlyRealistic.Player.LonelinessCheckTimer 1

# -> If loneliness check timer < max then return
execute unless score @s OverlyRealistic.Player.LonelinessCheckTimer matches 3.. run \
    return fail

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

# -> If the loneliness setting is disabled then return and reset loneliness
execute if score #or.setting.loneliness OverlyRealistic.Settings.ArbitrarySetting matches 0 run \
    return run \
        scoreboard players set @s OverlyRealistic.Player.Stats.Loneliness 0

# -> Add temp tag
tag @s add OverlyRealistic.Player.TempPlayerNearbyCheck

# -> Reset temp value
scoreboard players set #or.is_player_nearby_sanity_edit OverlyRealistic.General.ArbitraryData 0

# -> If there is a nearby player then set value
execute if entity @p[tag=!OverlyRealistic.Player.TempPlayerNearbyCheck,distance=..12,sort=arbitrary] run \
    scoreboard players set #or.is_player_nearby_sanity_edit OverlyRealistic.General.ArbitraryData 1

# -> Remove temp tag
tag @s remove OverlyRealistic.Player.TempPlayerNearbyCheck

# -> If there are players nearby then return and decrease loneliness
execute if score #or.is_player_nearby_sanity_edit OverlyRealistic.General.ArbitraryData matches 1 run \
    return run \
        scoreboard players remove @s[scores={OverlyRealistic.Player.Stats.Loneliness=2..}] OverlyRealistic.Player.Stats.Loneliness 2

# -> Increase loneliness
scoreboard players add @s OverlyRealistic.Player.Stats.Loneliness 1

# -> Clamp loneliness value
scoreboard players set @s[scores={OverlyRealistic.Player.Stats.Loneliness=151..}] OverlyRealistic.Player.Stats.Loneliness 150
