##############################
##
##        WorldEdit
##    Made By M7mdTG ;)
##
##############################

execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,tag=!we_savedblock] ~~~ structure save we_selection ~~~ ~~~ false disk true
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,tag=!we_savedblock] ~~~ scoreboard players operation @s we_mask_mode = @a[tag=we_host] we_mask_mode
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,tag=!we_savedblock] ~~~ tellraw @a {"rawtext":[{"text":"<WorldEdit> Wall Operation Started Successfully"}]}
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,tag=!we_savedblock] ~~~ tag @s add we_savedblock

# stage 1

execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~-1,dy=-9999,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ summon worldedit:selection_box ~~~ x "we_stage1"
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~-1,dy=-9999,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ tp ~~1~
 
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~1,dy=9999,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ summon worldedit:selection_box ~~~ x "we_stage1"
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~1,dy=9999,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ tp ~~-1~
 
# stage 2
 
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ tp ~~~ facing @e[type=worldedit:pos2]
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ execute @e[name="we_stage1"] ~~~ tp ~~~ facing @e[type=worldedit:pos2]
 
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ tp ~~~ ~ 0
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ execute @e[name="we_stage1"] ~~~ tp ~~~ ~ 0
 
# stage 3
 
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=1}] ~~~ structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=1}] ~~~ execute @e[name="we_stage1"] ~~~ structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=2}] ~~~ detect ~~~ air -1 structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=2}] ~~~ execute @e[name="we_stage1"] ~~~ detect ~~~ air -1 structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=3}] ~~~ detect ~~~ air -1 tag @s add we_air
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=3}] ~~~ execute @e[name="we_stage1"] ~~~ detect ~~~ air -1 tag @s add we_air
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=3},tag=!we_air] ~~~ structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1,scores={we_mask_mode=3}] ~~~ execute @e[name="we_stage1",tag=!we_air] ~~~ structure load we_selection ~~~
tag @e remove we_air
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ tp ^^^0.5
execute @e[type=worldedit:pos2] ~~~ execute @e[x=~9999,dx=-19999,y=~,dy=0,z=~9999,dz=-19999,type=worldedit:pos1] ~~~ execute @e[name="we_stage1"] ~~~ tp ^^^0.5
 
# stage 4

execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=1}] ~~~ structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=1}] ~~~ execute @e[name="we_stage1"] ~~~ structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=2}] ~~~ detect ~~~ air -1 structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=2}] ~~~ execute @e[name="we_stage1"] ~~~ detect ~~~ air -1 structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=3}] ~~~ detect ~~~ air -1 tag @s add we_air
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=3}] ~~~ execute @e[name="we_stage1"] ~~~ detect ~~~ air -1 tag @s add we_air
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=3},tag=!we_air] ~~~ structure load we_selection ~~~
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0,scores={we_mask_mode=3}] ~~~ execute @e[name="we_stage1",tag=!we_air] ~~~ structure load we_selection ~~~
tag @e remove we_air
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0] ~~~ tag @e[name="we_stage1"] add we_dead
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0] ~~~ tag @e[type=worldedit:pos2] add we_dead
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,x=~,dx=0,y=~,dy=0,z=~,dz=0] ~~~ tag @s add we_dead
execute @e[tag=we_dead,type=worldedit:pos1] ~~~ tellraw @a {"rawtext":[{"text":"               §7>\n§r               Wall Built Successfully"}]}
execute @e[tag=we_dead,type=worldedit:pos1] ~~~ execute @a[tag=we_host] ~~~ playsound random.levelup @s ~~~ 0.5 1
execute @e[type=worldedit:pos1,tag=we_dead] ~~~ structure delete we_selection
kill @e[tag=we_dead]
 
execute @e[type=worldedit:pos2] ~~~ execute @e[type=worldedit:pos1,tag=!we_dead] ~~~ function we/high-end/wall