Java配置,需要返回函数7

问题描述 投票:0回答:1

我有一个像下面这样的config.yml文件:我怎么写一个函数来返回spwn,lol,xd,Warpa,Warphei?我知道,比如说如果我想在spwn里面得到X,我可以这样做plugin.getConfig().getString("spwn.X");我只是不知道如何列出所有的名字。

spawn:
  World: world
  X: 80.96770114181192
  Y: 72.0
  Z: -377.6790770077272
  Pitch: 14.682037
  Yaw: 113.62133
lol:
  World: world
  X: 109.60479547630788
  Y: 71.0
  Z: -353.9986813646272
  Pitch: 2.6992812
  Yaw: 102.31512
xd:
  World: world
  X: 106.59929856356823
  Y: 71.0
  Z: -354.65178849406584
  Pitch: 2.6992812
  Yaw: 102.31512
Warpa:
  World: world
  X: 188.43198209818965
  Y: 70.5998614967549
  Z: -331.69999998807907
  Pitch: 15.525846
  Yaw: -129.82843
Warphei:
  World: world
  X: 190.8221960506558
  Y: 70.5998614967549
  Z: -341.26133473481616
  Pitch: 15.525846
  Yaw: -129.82843
java config bukkit
1个回答
1
投票

我假设config.yml在服务器上已经有了。如你所知,你可以得到 FileConfiguration 缺省配置的实例,调用 JavaPlugin#getConfig().

要获得配置部分的所有元素,你可以调用 ConfigurationSection#getKeys(boolean deep). 作为 FileConfiguration 实施 ConfigurationSection你可以在你的FileConfiguration实例上调用getkeys方法。布林值表示你是否也想获得所有的深层路径。

例子:"spawn

FileConfiguration#getKeys(false)

  • "spawn"
  • "呵呵"
  • "XD"
  • ...

FileConfiguration#getKeys(true)

  • "产卵"
  • "spawn.World"
  • "spawn.X"
  • ...
  • "lol"
  • "lol.World"
  • ...
© www.soinside.com 2019 - 2024. All rights reserved.