Get Dimension ID

Hey everyone, I was wondering if it was possible to get the Dimension ID of a certian world using the sponge api. If you dont understand it, Forge gives every Dimension an ID for Example Overworld = 1.
Thanks in advance for all help

Sponge typically doesn’t support magic values. You can get the String dimension ID (something like minecraft:overworld) by getting the Dimension type and then getting the id from there.

However you maybe in luck, not tried it myself, but this may produce the magic numerical id of the dimension.

Dimension dim;
String sID = dim.getContext().getValue(); //not sure if this will come out with the string id, dimension name, or numeric id
int id = Integer.parseInt(sID);

Ive not tested the code, hence my unsure notes. But like i say, you maybe in luck

That’s for use with permission plugins and will contain the string name. So no, that won’t work.

We don’t expose the numeric Dimenion ID - it should not be required at all. However, if you really need it, it is kind of available by doing something like this. This is implementation specific - it may not work on all platforms, or between versions. Always prefer the world UUID.

Thanks for all the help. In the end the Code that dualspiral sent worked for me but you have to make some slight changes to it. What I’m using now for anyone asking this question in the future is this:

World w;
w.getProperties().getAdditionalProperties().getInt(DataQuery.of("SpongeData", "dimensionId"));

This gives you the world ID but what you need to do is remove Optional[] from the string to just have the ID itself.