##############################
##
##        WorldEdit
##    Made By M7mdTG ;)
##
##############################
 
# Ui
 
execute @a[tag=we_host,tag=we_build_menu] ~~~ function we/misc/build_menu/build_menu_ui
execute @a[tag=we_host,tag=we_settings] ~~~ function we/misc/settings/settings_ui
execute @a[tag=we_host,tag=we_book] ~~~ function we/misc/book/book_ui

# rest

tag @a add first_enterance
execute @a[tag=we_host] ~~~ tag @a remove first_enterance

#hostcount 
scoreboard objectives add we_hostcheck dummy "Host-Count"

# Only 1 host
scoreboard players set @a we_hostcheck 0
execute @a[tag=we_host] ~~~ scoreboard players add @a we_hostcheck 1
execute @a[scores={we_hostcheck=0}] ~~~ tag @s add we_host
scoreboard players set @a we_hostcheck 0
execute @a[tag=we_host] ~~~ scoreboard players add @a we_hostcheck 1
execute @a[scores={we_hostcheck=2..}] ~~~ titleraw @a actionbar {"rawtext":[{"text":"<WorldEdit ERROR>\nCouldn't identify host\nTo become host use /function take_worldedit_host\nOr restart world to fix it"}]}
execute @a[scores={we_hostcheck=2..}] ~~~ tag @s remove we_host


tag @a[tag=first_enterance,tag=we_host] add world_edit_enabled
tellraw @a[tag=first_enterance,tag=we_host] {"rawtext":[{"text":"§r§f_______________________________________\n|.        。      ඞ   。   .    •     •\n§r§f|  '  .   •   §l§3WorldEdit Enabled§r§f  。 .  '     •    \n§r§f|  。 .  '   •  §l§aMade by M7md TG§r§f  '   •  。\n§r§f|•     •    .   。         。     •      .\n§r§f|_______________________________________"}]}
give @a[tag=first_enterance,tag=we_host] worldedit:we_book
execute @e[tag=we_host,tag=world_edit_enabled] ~~~ function we/tick

execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_yrot
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_xrot
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_radius
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_b_type
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_b_size
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_settings
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_strength
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_build_mode
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_mask_mode
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_fill_mode
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_b_page
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_x_scale
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_y_scale
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_z_scale
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_x_score
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_y_score
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_z_score
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_cph1
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_cph2
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ scoreboard objectives remove we_blocks_count

execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ tag @a remove we_scoreboards_setup
tag @a[tag=!we_host] remove we_scoreboards_setup
tag @a[tag=!we_host] remove we_book
tag @a[tag=!we_host] remove we_settings
tag @a[tag=!we_host] remove we_build_menu
tag @a[tag=!we_host] remove we_controlling_selection
tag @a[tag=!we_host] remove world_edit_enabled
tag @a[tag=!world_edit_enabled] remove we_swcoreboards_setup
tag @a[tag=!world_edit_enabled] remove we_book
tag @a[tag=!world_edit_enabled] remove we_settings
tag @a[tag=!world_edit_enabled] remove we_build_menu
tag @a[tag=!world_edit_enabled] remove we_controlling_selection
tag @a remove first_enterance

execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:pos1]
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:pos2]
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:dummy]
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:selection_box]
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:selection_border]
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:cursor]
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:pos1_spawner]
execute @a[tag=we_host,tag=!world_edit_enabled] ~~~ kill @e[type=worldedit:pos2_spawner]
 
clear @a[tag=!we_host] worldedit:we_brush
clear @a[tag=!we_host] worldedit:we_eraser
clear @a[tag=!we_host] worldedit:we_settings
clear @a[tag=!we_host] worldedit:we_build_menu
clear @a[tag=!we_host] worldedit:we_book
clear @a[tag=!we_host] worldedit:we_enable
clear @a[tag=!we_host] worldedit:we_disable
clear @a worldedit:pos1_spawn_egg
clear @a worldedit:pos2_spawn_egg
clear @a[tag=!we_host] worldedit:pos1_spawner_spawn_egg
clear @a[tag=!we_host] worldedit:pos2_spawner_spawn_egg

clear @a[tag=!world_edit_enabled] worldedit:we_disable
clear @a[tag=world_edit_enabled] worldedit:we_enable

clear @a[tag=!world_edit_enabled] worldedit:we_brush
clear @a[tag=!world_edit_enabled] worldedit:we_eraser
clear @a[tag=!world_edit_enabled] worldedit:we_settings
clear @a[tag=!world_edit_enabled] worldedit:we_build_menu
clear @a[tag=!world_edit_enabled] worldedit:we_book
clear @a[tag=!world_edit_enabled] worldedit:pos1_spawner_spawn_egg
clear @a[tag=!world_edit_enabled] worldedit:pos2_spawner_spawn_egg

