config.getstring 仅当配置有超过 3 个“点”时才返回 null

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

这是我的

config.yml
:

gui:
  title: "This is the GUI's name"
items:
  feather: "This is item feather"
  cookie:
    hello: "Hello, here's a cookie"

这是代码部分:

        String guiTitle = config.getString("gui.title");
        String itemsFeather = config.getString("items.feather"); 
        String itemsOnTest = config.getString("items.cookie.hello");

        getLogger().info("Gui title: " + guiTitle);
        getLogger().info("Items feather: " + itemsFeather);
        getLogger().info("Items on test: " + itemsOnTest);

前 2 个

getLogger
显示配置中的正确文本,而
itemsOnTest
返回
null
。只要我在配置中使用 2 个“名称”,例如:

Example 1:
  test: "This is a test"

它可以工作并显示“这是一个测试”,而如果它超过 2 个,如下所示:

items:
  on:
    test: "hello"

然后

items.on.test
不会显示
"hello"
而是
null

java minecraft bukkit
1个回答
0
投票

Key as

on
/
off
/
true
/
false
似乎是保留关键字,并产生问题。不是因为3个步骤。

我只是建议您将使用的关键字更改为

enabled
之类的内容,这应该可以正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.