Preventing a player from swimming up or down

I have a custom dimension where I want the player to be stuck in the middle of a layer of water, is there any way to prevent the player from swimming up and down without a tick function?

The best Idea I've had so far is to use a tick function to run a command for all players in the dimension, then set 4 waterlogged barrier blocks obove and below them while deleting the ones in a ring around that. gamemode can be adventure to prevent placing blocks. Is there a better approach

Continue to help post