Making a single character immortal in a minecraft server

Solution 1:

I am answering my own question here with a somewhat OK solution, but i would still very much like to hear better/alternative solutions.

It is possible to use the /effect command to give resistance 5 to a player. Resistance reduces damage by 20% pr level, so it SHOULD make characters invulnerable at level 5. The effect can be made semi-permanent as far as I can see, by giving a long duration. A /kill command will still kill the player, as will void damage.

https://minecraft.fandom.com/wiki/Resistance

https://www.digminecraft.com/game_commands/effect_command.php

Solution 2:

You can run the command /effect [Username] resistance 255 600 to make the player take no damage for 10 minutes, and the command /effect [Username] weakness 255 600 for the player to do no damage for 10 minutes