#why does YamlConfiguraiton.getLocation() returns null?

1 messages · Page 1 of 1 (latest)

delicate swan
#

I save the locaction on stop in the config:

spawners:
  Location{world=CraftWorld{name=spawn},x=-1:
    0049623E7,y=-60:
      0,z=1:
        4479659E7,pitch=0:
          0,yaw=0:
            0}:
              location:
                ==: org.bukkit.Location
                world: spawn
                x: -1.0049623E7
                y: -60.0
                z: 1.4479659E7
                pitch: 0.0
                yaw: 0.0
              amount: 1

but when using config.getLocation("spawners.key.location") it returns null. key is declared in a foreach loop, that loops through all keys in the spawners-category

gusty bronze
#

.key?

#

oh k

#

nvm

delicate swan
#
override fun loadAllSpawners() {
        (config.getConfigurationSection("spawners") ?: return).getKeys(false).forEach { key ->
            Bukkit.broadcast(config.getLocation("spawners.$key.location").toString().toComponent())
            Spawner(config.getLocation("spawners.$key.location")!!, config.getInt("spawners.$key.amount"))
        }
    }

kotlin btw

rapid kraken
#

how are you saving that location?

#

it looks like your key is all messed up

#

looks like some .toString shenanigans are going on here

delicate swan
# rapid kraken how are you saving that location?
override fun saveAllSpawners() {
        var saved = 0
        registeredSpawners.forEach { (loc, spawner) ->
            config["spawners.$loc.location"] = spawner.location
            config["spawners.$loc.amount"] = spawner.amount
            saved++
        }
        Bukkit.getConsoleSender().sendMessage("Saved $saved spawners!")
        plugin.saveConfig()
    }
#

registeredSpawners: ```kotlin
val registeredSpawners = mutableMapOf<Location, ISpawner>()

rapid kraken
#

you are trying to stringify a location and use that as a key

#

but that location contains dots

#

which creates new sections

delicate swan
#

oh….

rapid kraken
#

also i dont really understand the point of this

#

from what i can tell loc and spawner.location is the same

delicate swan
#

ye i just needed some unique thing to safe

rapid kraken
#

i would probably just use a list instead

delicate swan
#

I could try that

#

Thanks for the help

rapid kraken
#

yeah np!