I've just been testing your 2 branches.
In 1.18.2 the thread is usually already the ServerThread so it works. But this isn't guaranteed, it could be a networking thread.
In 1.19.2 the thread is usually a networking thread so it fails.
When I wrap your handle() code inside a
ctx.get().enqueueWork(() -> {
// original code here
});
it is always on the server thread and so works.
So it looks like you didn't change your code properly, maybe you didn't save it?
NOTE: You will need to fix this for 1.18.2 as well. As I said above, this code could run on "any" thread unless you force it onto the ServerThread.