1.16.5 Get Namespaced Key of World

Discussion in 'Spigot Plugin Development' started by repeater64, May 3, 2021.

  1. Hey,

    I'm trying to get the namespaced ID of a world from the World object, ready for use in Minecraft's "/execute in <world>" command.

    For example, minecraft:nether or minecraft:the_end

    Anyone know how to do this?
    #1 repeater64, May 3, 2021
    Last edited: May 3, 2021
  2. Code (Text):

    String dimension = "";
    switch (world.getEnvironment()) {
       case NETHER:
           dimension = "minecraft:nether";
       case THE_END:
           dimension = "minecraft:the_end";
       case NORMAL:
           dimension = "minecraft:overworld";
          // custom dimension
    #2 eccentric, May 4, 2021
    Last edited: May 5, 2021
  3. I'm not sure if Spigot actually supports that. Paper has a patch regarding Keyed implementation for World tho, but I'm not sure if it works for vanilla commands too.
  4. Code (Text):

    public String getDimensionNamespaceKey(org.bukkit.World world) {
        net.minecraft.server.v1_16_R3.World w = ((CraftWorld) world).getHandle();
        return w.getDimensionKey().a().toString();