customrealms / core

Core library for the CustomRealms runtime
https://customrealms.io/core
MIT License
36 stars 14 forks source link

Method for retrieving all worlds #25

Closed FalcoG closed 2 years ago

FalcoG commented 2 years ago

This creates a function which returns all available worlds.

One use case of this would be to create a "/spawn" command which will return you to the spawn point of a specific world.

AL1L commented 2 years ago

Do you think we could add a method to get a work by name?

FalcoG commented 2 years ago

Sounds good, I've added it. Here's a code example that tests byName and byUUID:

ServerCommands.register('/spawn', (player) => {
  const worldTest = Worlds.getWorldByName('world_nether')

  if (worldTest == null) return

  // player.teleport(worldTest.getSpawnLocation())
  player.sendMessage('You have been teleported to the spawn')

  const uuid = worldTest.getUUID()
  const uuidTest = Worlds.getWorldByUUID(uuid)

  if (uuidTest != null) {
    player.teleport(uuidTest.getSpawnLocation())
  }
})