Creating a double-jump mechanic in Minecraft using commands

Solution 1:

You can detect if a player sneaks with the help of this command:

/scoreboard objectives add sneaks minecraft.custom:minecraft.sneak_time

Then run this command in a repeating command block to make every player that has sneaked for 1 tick and is not on the ground levitate (which seems to be the way how you want the second jump to work)

/execute as @e[scores={sneaks=1},nbt={OnGround:0b}] run effect give @s minecraft:levitation 1 2 true

You can use a chain command block to the run this command, it will reset the sneak time for any player who is standing on the ground:

/scoreboard players reset @a[nbt={OnGround:1b}] sneaks

If you sneak for a really short time, then you may have a sneak time of 1, which would lead to levitating indefinitely, as the effect would get set repeatedly. To prevent this you can use this command in a second chain command block:

/execute as @a[scores={sneaks=1}] run scoreboard players add @s sneaks 1

When the player hits their head, then you want them to stop levitating and fall again, you can achieve this with yet another chain command block and this command:

/execute as @a[scores={sneaks=2..}] at @s unless block ~ ~1.8 ~ minecraft:air run effect clear @s minecraft:levitation

Edit after some refining

You can put these commands into a repeating command block and 4 chain command blocks, it works similarly to what I explained above, but it feels more like actually jumping mid air, because the levitation effect is much stronger. I added a dummy scoreboard objective called "duration", which gets a value from the ActiveEffects-tag in the 4th command. The 5th command clears the levitation effect 17 ticks (0.85 seconds) before it would usually wear off:

/execute as @e[scores={sneaks=1},nbt={OnGround:0b}] run effect give @s minecraft:levitation 1 20 true
/scoreboard players reset @a[nbt={OnGround:1b}] sneaks
/execute as @a[scores={sneaks=1}] run scoreboard players add @s sneaks 1
/execute as @a store result score @s duration run data get entity @s ActiveEffects[{Id:25b}].Duration 1
/execute as @a[scores={duration=..17}] run effect clear @s

Note: I removed the command that checks if you hit your head, because the levitation effect will be so short that you hardly notice that you levitate against a ceiling.

Note 2: this has the side effect of adding some kind of super jump if you sneak and jump while sneaking, this jump is about 4 blocks high and you cannot perform a double jump from it. A double jump takes you about 3 blocks high.