It's important to remember that
y == 0 is the top of the screen.
if (playerPaddleY <= 0 && paddleDirection == -1)
If the player tries to move the paddle past the top, then...
paddleRight.cy(paddleHeight / 2);
...set the center position of the paddle to be 1/2 of the paddle's height from the top. If the paddle is 20 pixels long, then this will set the paddle's center to
10px from the top. This makes sure that the paddle never travels past the top edge.
else if (playerPaddleY >= height-paddleHeight && paddleDirection == 1)
y == 0 is the top, then
y == height is the bottom. So,
height - paddleHeight is the lowest the paddle can go before it crosses the boundary. At this point, the bottom of the paddle is touching the bottom edge of the play area. If the player tries to move lower than this...
paddleRight.y(height - paddleHeight);
... set the paddle's Y position to that lowest point. If neither of these conditions are true, then
paddleRight.dy(paddleDirection * paddleSpeed);
This changes the paddle's position relative to where it currently is by calculating its instantaneous velocity.
paddleSpeed is 5, so if the player wants to go up, the paddle gets shifted by -5 pixels, bringing it towards the top.