The essence of this code, when any player appears at coordinates 120 x 20 at z and at any height, he will be teleported 2 blocks back at x and z coordinates and will write a message that other players cannot see in any way
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.StringTextComponent;
//import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
public class ClassName extends PlayerEntity{
public ClassName(World p_i241920_1_, BlockPos p_i241920_2_, float p_i241920_3_, GameProfile p_i241920_4_) {
super(p_i241920_1_, p_i241920_2_, p_i241920_3_, p_i241920_4_);
Vector3d no_escape = new Vector3d(120.000, position().y, 20.000);
Vector3d PlPos = position();
if(PlPos.x == no_escape.x && PlPos.z==no_escape.z) {
teleportTo(no_escape.x-2, no_escape.y-0, no_escape.z-2);
sendMessage(new StringTextComponent("No way!"), getUUID());
}
}
@Override
public boolean isSpectator() {
return false;
}
@Override
public boolean isCreative() {
return false;
}
}