1.16.x Get Namespaced Key of World

Discussion in 'Spigot Plugin Development' started by repeater64, May 3, 2021 at 6:28 PM.

  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 at 6:28 PM
    Last edited: May 3, 2021 at 6:35 PM
  2. Code (Text):

    String dimension = "";
    switch (world.getEnvironment()) {
       case NETHER:
           dimension = "minecraft:nether";
           break;
       case THE_END:
           dimension = "minecraft:the_end";
           break;
       case NORMAL:
           dimension = "minecraft:overworld";
           break;
       default:
          // custom dimension
          break;
    }
     
     
    #2 eccentric, May 4, 2021 at 5:48 AM
    Last edited: May 5, 2021 at 6:07 AM
  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();
    }