$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=!Happy_Ghast.Is_Placing_Placable_Areas] at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=!Happy_Ghast.Is_Placing_Placable_Areas] unless entity @e[type=minecraft:marker,tag=Happy_Ghast_Supplementary.Placable_Area,distance=..6.5,nbt={data:{Source:$(Selected)}}] run tag @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=!Happy_Ghast.Is_Placing_Placable_Areas] add Happy_Ghast.Is_Placing_Placable_Areas

$execute as @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Is_Placing_Placable_Areas] at @s store result entity @s Pos[0] int 1 run data get entity @s Pos[0] 1
$execute as @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Is_Placing_Placable_Areas] at @s store result entity @s Pos[1] int 1 run data get entity @s Pos[1] 1
$execute as @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Is_Placing_Placable_Areas] at @s store result entity @s Pos[2] int 1 run data get entity @s Pos[2] 1

$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=Happy_Ghast.Is_Placing_Placable_Areas] at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=Happy_Ghast.Is_Placing_Placable_Areas] run function better_happy_ghast:tick/player/happy_ghast_order_menu/place_placable_areas/summon_marker_entities {Owner:$(UUID),Happy_Ghast:$(Selected)}

$execute unless entity @e[type=minecraft:marker,tag=Happy_Ghast_Supplementary.Placable_Area,distance=..8] run tag @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=Happy_Ghast.Is_Placing_Placable_Areas] remove Happy_Ghast.Is_Placing_Placable_Areas

$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Is_Placing_Placable_Areas] unless data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ if entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] "§8[§bSky Deck§8] §aPlaced marker areas around the selected Happy Ghast."
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Is_Placing_Placable_Areas] if data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ if entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§8[§bSky Deck§8] §aPlaced marker areas around Happy Ghast named \"",{selector:"@e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}]"},"§a\"."]

$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=!Happy_Ghast.Is_Placing_Placable_Areas] unless data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ if entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] "§8[§bSky Deck§8] §cCould not place marker areas here."
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=!Happy_Ghast.Is_Placing_Placable_Areas] if data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ if entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§8[§bSky Deck§8] §cCould not place marker areas around Happy Ghast named \"",{selector:"@e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}]"},"§c\"."]
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8,tag=!Happy_Ghast.Is_Placing_Placable_Areas] at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ if entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] positioned ~ ~-3 ~ run playsound minecraft:block.stone.place ui @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~ 1 0.5

$tag @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},tag=Happy_Ghast.Is_Placing_Placable_Areas] remove Happy_Ghast.Is_Placing_Placable_Areas

$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] unless data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ unless entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] "§8[§bSky Deck§8] §cNo mob or player is currently on the selected Happy Ghast."
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] if data entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}] CustomName at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ unless entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] ["§8[§bSky Deck§8] §cNo mob or player is currently on Happy Ghast named \"",{selector:"@e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}}]"},"§c\"."]
$execute if entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] at @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] positioned ~ ~3 ~ unless entity @e[type=!#better_happy_ghast:no_mob_exept_player,distance=..2.5] positioned ~ ~-3 ~ run playsound minecraft:block.amethyst_block.step ui @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~ 1 0.8

$execute unless entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] run tellraw @s[scores={better_happy_ghast.player_configs.send_message=1}] "§8[§bSky Deck§8] §cNo selected Happy Ghast was found within 8 blocks."
$execute unless entity @e[type=minecraft:happy_ghast,limit=1,nbt={UUID:$(Selected),data:{Owner:$(UUID)}},distance=..8] run playsound minecraft:block.amethyst_block.step ui @s[scores={better_happy_ghast.player_configs.play_sound=1}] ~ ~ ~ 1 0.8