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

# Starting build
 
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_fill] ~~~ function we/high-end/fill
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_hollow] ~~~ function we/high-end/hollow
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_outline] ~~~ function we/high-end/outline
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_wall] ~~~ function we/high-end/wall
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_clear] ~~~ function we/high-end/clear
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_sphere,tag=!we_sphere_started] ~~~ scoreboard players operation @s we_radius = @a[tag=we_host] we_radius
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_sphere,tag=!we_sphere_started] ~~~ tag @s add we_sphere_started
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_sphere_started] ~~~ function we/high-end/sphere
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_circle,tag=!we_circle_started] ~~~ scoreboard players operation @s we_radius = @a[tag=we_host] we_radius
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_circle,tag=!we_circle_started] ~~~ tp ~~~ 0 0
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_circle,tag=!we_circle_started] ~~~ tag @s add we_circle_started
execute @e[type=worldedit:pos1,tag=we_ready,tag=we_circle_started] ~~~ function we/high-end/circle
  
#Scoreboards
 
scoreboard objectives add we_yrot dummy "Y-Rotation"
scoreboard objectives add we_xrot dummy "X-Rotation"
scoreboard objectives add we_radius dummy "Sphere-Radius"
scoreboard objectives add we_b_type dummy "Brush-Type"
scoreboard objectives add we_b_size dummy "Brush-Radius"
scoreboard objectives add we_settings dummy "Settings"
scoreboard objectives add we_strength dummy "WorldEdit-Strength"
scoreboard objectives add we_build_mode dummy "Build-Mode"
scoreboard objectives add we_mask_mode dummy "Mask-Mode"
scoreboard objectives add we_fill_mode dummy "Fill-Mode"
scoreboard objectives add we_b_page dummy "Current-Book-Page"
#calculations 
scoreboard objectives add we_x_scale dummy "X-Scale"
scoreboard objectives add we_y_scale dummy "Y-Scale"
scoreboard objectives add we_z_scale dummy "Z-Scale"
scoreboard objectives add we_x_score dummy "X-Score"
scoreboard objectives add we_y_score dummy "Y-Score"
scoreboard objectives add we_z_score dummy "Z-Score"
scoreboard objectives add we_cph1 dummy "Calculation-Placeholder-1"
scoreboard objectives add we_cph2 dummy "Calculation-Placeholder-2"

scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_strength 2
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_radius 1
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_b_type 1
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_b_size 1
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_settings 1
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_build_mode 1
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_mask_mode 1
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_fill_mode 1
scoreboard players set @a[tag=we_host,tag=!we_scoreboards_setup] we_b_page 1
tag @a[tag=we_host] add we_scoreboards_setup

#Cycling scores

scoreboard players set @a[scores={we_strength=4..}] we_strength 1
scoreboard players set @a[scores={we_radius=101..}] we_radius 1
scoreboard players set @a[scores={we_b_type=3..}] we_b_type 1
scoreboard players set @a[scores={we_b_size=6..}] we_b_size 1
scoreboard players set @a[scores={we_settings=7..}] we_settings 1
scoreboard players set @a[scores={we_build_mode=7..}] we_build_mode 1
scoreboard players set @a[scores={we_mask_mode=4..}] we_mask_mode 1
scoreboard players set @a[scores={we_fill_mode=4..}] we_fill_mode 1
scoreboard players set @a[scores={we_b_page=9..}] we_b_page 1

scoreboard players set @a[scores={we_strength=..0}] we_strength 3
scoreboard players set @a[scores={we_radius=..0}] we_radius 100
scoreboard players set @a[scores={we_b_type=..0}] we_b_type 2
scoreboard players set @a[scores={we_b_size=..0}] we_b_size 5
scoreboard players set @a[scores={we_settings=..0}] we_settings 6
scoreboard players set @a[scores={we_build_mode=..0}] we_build_mode 6
scoreboard players set @a[scores={we_mask_mode=..0}] we_mask_mode 3
scoreboard players set @a[scores={we_fill_mode=..0}] we_fill_mode 3
scoreboard players set @a[scores={we_b_page=..0}] we_b_page 8


# Only 1 from each pos
execute @e[type=worldedit:pos1_spawner] ~~~ summon worldedit:pos1 ~~-0.5~
kill @e[type=worldedit:pos1_spawner]
execute @e[type=worldedit:pos2_spawner] ~~~ summon worldedit:pos2 ~~-0.5~
kill @e[type=worldedit:pos2_spawner]
execute @e[type=worldedit:pos1,tag=!we_ready] ~ ~ ~ kill @e[type=worldedit:pos1,tag=we_ready]
execute @e[type=worldedit:pos2,tag=!we_ready] ~ ~ ~ kill @e[type=worldedit:pos2,tag=we_ready]
 
execute @e[type=worldedit:pos1,tag=!we_ready] ~~~ tp ~~~ 0 90
execute @e[type=worldedit:pos1] ~ ~ ~ structure save we_selection ~~~ ~~~ false disk true
execute @e[type=worldedit:pos1] ~ ~ ~ detect ~ ~ ~ air -1 structure delete we_selection
execute @e[type=worldedit:pos1,tag=!we_ready] ~~~ tag @s add we_ready
execute @e[type=worldedit:pos2,tag=!we_ready] ~~~ tag @s add we_ready
 
# Brush cursor
 
execute @a[tag=we_brush_cursor,tag=we_host] ^^^10 tp @e[type=worldedit:cursor] ~~56.75~

# not under condition operations
 
execute @e[type=worldedit:pos1,tag=we_tested_bad] ~~~ tellraw @a[tag=we_host] {"rawtext":[{"text":"<WorldEdit> Area too large: "},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_x_scale"}},{"text":"x"},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_y_scale"}},{"text":"x"},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_z_scale"}}]}
execute @e[type=worldedit:pos1,tag=we_tested_bad] ~~~ execute @a[tag=we_host] ~~~ playsound item.trident.return @s ~~~ 0.5 0.8
execute @e[type=worldedit:pos1,tag=we_tested_bad] ~~~ execute @a[tag=we_host] ~~~ playsound random.hurt @s ~~~ 0.3 1
tag @e[type=worldedit:pos1,tag=we_tested_bad] remove we_fill
tag @e[type=worldedit:pos1,tag=we_tested_bad] remove we_outline
tag @e[type=worldedit:pos1,tag=we_tested_bad] remove we_hollow
tag @e[type=worldedit:pos1,tag=we_tested_bad] remove we_clear
tag @e[type=worldedit:pos1,tag=we_tested_bad] remove we_measured
tag @e[type=worldedit:pos1,tag=we_tested_bad] remove we_tested_bad

execute @e[type=worldedit:pos1,tag=we_found_bad_surface] ~~~ tellraw @a[tag=we_host] {"rawtext":[{"text":"<WorldEdit> Area too large: "},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_x_scale"}},{"text":"x"},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_y_scale"}},{"text":"x"},{"score":{"name":"@e[type=worldedit:pos1]","objective":"we_z_scale"}}]}
execute @e[type=worldedit:pos1,tag=we_found_bad_surface] ~~~ execute @a[tag=we_host] ~~~ playsound item.trident.return @s ~~~ 0.5 0.8
execute @e[type=worldedit:pos1,tag=we_found_bad_surface] ~~~ execute @a[tag=we_host] ~~~ playsound random.hurt @s ~~~ 0.3 1
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_fill
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_outline
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_hollow
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_clear
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_measured
tag @e[type=worldedit:pos1,tag=we_found_bad_surface] remove we_found_bad_surface
