TCT-Datapack/data/tctvote/functions/prepare.mcfunction

44 lines
2.3 KiB
Mcfunction

# Create scores, and teams
scoreboard objectives add mt_vote_balance dummy "Vote results"
scoreboard objectives add mt_vote_trigger trigger
scoreboard objectives add mt_vote_anon dummy
scoreboard objectives add mt_countdown dummy
bossbar add minecraft:votetimer "Vote time remaining"
bossbar set minecraft:votetimer max 20
bossbar set minecraft:votetimer style notched_20
bossbar set minecraft:votetimer color green
bossbar set minecraft:votetimer value 20
bossbar set minecraft:votetimer players @a
team add green "Green"
team modify green color dark_green
team add red "Red"
team modify red color red
team join green AYE
team join red NO
# Summon the VoteStand
summon minecraft:armor_stand ~ ~ ~ {NoGravity:1b,Invulnerable:1b,Small:1b,Marker:1b,Invisible:1b,Tags:["mt_votestand"]}
scoreboard players set @e[tag=mt_votestand] mt_countdown 20
# Announce the vote
tellraw @a[scores={mt_vote_eligible=1}] ["",{"text":"Vote >>","bold":true,"color":"dark_green"},{"text":" Vote using the voting book now!","bold":true,"color":"white"}]
# Enable the trigger
scoreboard players enable @a[scores={mt_vote_eligible=1}] mt_vote_trigger
# Give the VoteBook
give @a[scores={mt_vote_eligible=1}] minecraft:written_book{display:{Name:'{"text":"Voting Book","color":"white","bold":true}',Lore:['{"text":"Cast your vote now!"}']},certified:votebook,title:"Voting Book",author:"Kipje",pages:['[{"text":"Cast your vote!\\n Click AYE or NO below.\\n\\n\\n"},{"text":"AYE","color":"dark_green","bold":true,"hoverEvent":{"action":"show_text","contents":[{"text":"Click to vote AYE on this vote."}]},"clickEvent":{"action":"run_command","value":"/trigger mt_vote_trigger set 1"}},{"text":" | "},{"text":"NO","color":"red","bold":true,"hoverEvent":{"action":"show_text","contents":[{"text":"Click to vote NO on this vote."}]},"clickEvent":{"action":"run_command","value":"/trigger mt_vote_trigger set 2"}}]']} 1
# Reset the scores
scoreboard players set AYE mt_vote_balance 0
scoreboard players set NO mt_vote_balance 0
# Schedule the notes and countdown
schedule function tctvote:notes/up_0 1t
function tctvote:countdownstart
# And start the countdown
schedule function tctvote:halt 20s
# Give everyone advancements
advancement grant @a[scores={mt_vote_eligible=1},advancements={craftytable:joinmeeting=true}] only craftytable:vote