How to get a player's bed re-spawn location if it exists?

I’ve just come to Sponge as I suddenly require a plugin for my server, I previously came from Bukkit.
(I must say, this is far more flexible and user friendly than Bukkit).

I require to check if a player has a set bed respawn location, and if that exists, retrieve that location.
Otherwise, retrieve the default world’s spawn location.

(I’ve noticed that Locations are no longer simply stored as a Location, but there are Vector3i, Vector3d, Transforms, etc… and is a little overwhelming, I must say).

Call .get(Keys.RESPAWN_LOCATION), and check if it isForced. Then call getSpawnLocation on the World.

As for locations, it’s pretty simple to remember.

Vector3i is simply a 3-int vector, as Vector3d is for double. Location is for the actual location within a world, and fulfills the functionality of both Bukkit’s Location and Block. And Transform combines Location, rotation, and scale, for use with entities.

If you never care enough, you’ll never have to use anything but Location.

I have managed to retrieve the default world’s spawn location, however I am still unable to retrieve the Player’s bed respawn location.

Where you state to call .get(Keys.RESPAWN_LOCATION), this is invalid when called on both the player, and event. It states to use .get(Keys.RESPAWN_LOCATIONS), which returns a Map of UUIDs and RespawnLocations. How am I able to find the bed respawn with UUIDs?

EDIT: I just looked at the documention and noticed the UUID is the world UUID to obtain their spawn location.
https://jd.spongepowered.org/5.0.0/org/spongepowered/api/data/key/Keys.html#RESPAWN_LOCATIONS

Cheers!

Okay, so I’ve done some testing and it appears that my event isn’t even being triggered!
Could you please revise my code?

https://github.com/Axiom1999/Bed-Enforcer/blob/master/src/me/axiom/spl/bedenforcer/BedEnforcer.java

need to register your listener with Sponge.

Sponge.getEventManager().registerListeners();

what? it’s his main class, why would he need to register it?

Good point. My bad

That is correct. However when I respawn, nothing is sent to the log… And it just spawns me at the regular world spawn every time.

I am using the HermitPack modpack to test this on since, HermitPack is the server were having issues on.

Essentially, every time a player dies it’ll send then to the world spawn (not their bed). Alongside this, if they die in another dimension, it’ll spawn them at 0,64,0 in that dimension… very frustrating, hence this plugin ahould override everything!

Have you verified the plugin is actually loading? Looking at your overall project it looks like you manually create the mcmod.info and doesn’t look like you’re using gradle or maven for dependency handling. It’s possible something did not compile correctly.

If the annotation is correct, then even javac should be able to compile the plugin in such a way that it works. And mcmod.info is only required for Ore.

Works fine in all my plugins. Has been for quite a while

I’m just saying, it opens up the doors for human error

No, not really. The annotation is the only thing that matters when loading the plugin. Meanwhile, is it possible that something in HermitPack is cancelling the event?

Try adding @IsCancelled(Tristate.UNDEFINED) to your listener. I think something’s cancelling the event.

The plugin does load, followed by logs in the console. However, I must add that it states that it cannot find the mcmod.info file and says that this is okay when testing, but is recommended for release.

@pie_flavor I’ve added the annotation you suggested and the results were, well you can’t filter an event that isn’t cancellable.

In the end, I’ve managed to solve the event not triggering (silly mistake on my behalf; was exporting mod to wrong place).

Now I face a new error, I’ve narrowed this bug down to two Sponge plugins: Project Worlds or Nucleus.

My plugin also will try to spawn the player at the default spawn every time. It’s as though the Keys.RESPAWN_LOCATIONS is invalid or something.

Try setting the listener Order to POST.

@Listener(order = Order.POST)

Also make sure the spawnOnDeath gamerule added by Project Worlds is set to default. If it does not allow you to set to default you’re probably not running the latest version

This is the same Bukkit’s @EventHandler(priority = Priority.HIGHEST) correct?

That’s neat to know for future purposes.

However, I believe I have found the culprit to be Project Worlds.

EDIT Are you serious! It’s a gamerule that has to be edited! Wow… All this effort and there’s a gamerule for Project Worlds.

Thank you so much.

I think so but I’m not hugely informed with Bukkit logic so I couldn’t say for sure.

It was something added a week ago by request to stop Project Worlds from always overriding default behavior so it’s understandable that it was missed. New worlds will be set to default by default so in the future you don’t need to worry about it, however if the plugin was updated from an older version existing worlds are set to something else.

Yeah, I just set the Nether and The End to the default (hence, I must be using an older version [I’m on v0.11.3]).

Also, when dying in the Overworld, it does spawn me in my bed. However, as soon as I leave the overworld, I am required to reset my bed spawn (otherwise, it’ll spawn me in the default spawn).

Oh…well the mechanic I described wasn’t added until 0.11.4. You should update.