How to create a new individual respawn point?

I tried using player.get(Keys.RESPAWN_LOCATIONS).get() to get the Map<UUID, RewspawnLocation> then using the RespawnLocation.builder to create a new respawn point, using .put() to update the map and finally player.offer(Keys.RESPAWN_LOCATIONS, map) to update the values. Player.offer returns isSuccessful = true and I can retrieve the correct value from map after using put(). But when I die I still spawn at the usual point.

Something weird: The original map retrieved is empty (shouldn’t there at least be ONE respawn point for a world?)

Feels like this would be a common and easy thing to do, but I just can’t find a solution for it.

Can you post code directly, please? Explaining what you have done always leaves open the possibility that you have missed some part of it. For example, you might have mistakenly used the player’s UUID for the map rather than the world’s.

No, the map doesn’t have to be non-empty; if the player has no specific respawn point for a world, then they’ll spawn at the world spawn.

Your version of Sponge would also be appreciated.

        Player p = (Player)src;
        if(p.getOrNull(Keys.RESPAWN_LOCATIONS) != null)
        {
        Map<UUID,RespawnLocation> map = p.get(Keys.RESPAWN_LOCATIONS).get();
        RespawnLocation newLoc = RespawnLocation.builder()
                .world(p.getWorld().getUniqueId())
                .position(vector)
                .forceSpawn(false)
                .build();
        
        map.put(p.getWorld().getUniqueId(), newLoc);
        DataTransactionResult result = p.offer(Keys.RESPAWN_LOCATIONS, map);
        }

Sponge API 5.0.0

Looks right to me, I wonder if this is supposed to be bed respawn points, or some other form of override, thus the default world spawn point is excluded?

Interestingly it removes the current bed spawn, so it seems to do something atleast. I can only guess that I use the builder wrong?

EDIT: I might add that I tried listening to RespawnPlayerEvent first and TP the player there. I had problem getting the right player entity though it seems since they never teleported. I then realised that if the user pressed “title screen” and then reconnected this event would never be called. That’s why I’m trying it this way.

EDIT 2: Ah shit. I should have used setToTransform() I guess? Would still like to know the solution to this problem. Is RespawnLocation only valid for locations with a bed? What’s the specific requirements if that’s the case?