我开发了一个Minecraft Bukkit插件,我想在配置文件中保存信息。我想在我的yaml配置文件中保存一个数组并加载数据。这是我的yaml文件:
# Locations
Locations:
- name: "Survival"
position: 5
-
- name: "PVP"
position: 3
这是尝试加载数组的代码:
List<String> locations = config.getConfig().getStringList("Locations");
for(int i = 0; i < locations.size(); i++) {
String[] location = locations.toArray(new String[0]);
player.sendMessage("Name" + location[0] + ", Position" + location[1]);
}
但我没有收到聊天消息。如果我通过for
发送消息,我会收到一条消息。
答案 0 :(得分:0)
你可以用这个:
__dict__
并拥有此Location.class
FileUtil.loadYamlFromResource("myLocationFile.yml", Location.class);
Location.getLocation("location1").getSomething()
在FileUtil.class中
public class Location implements Serializable {
private static final long serialVersionUID = -2360488391508732184L;
private Map<String, Map<String, Double>> locations = new HashMap<>();
public Float getLocation(String location) throws LocationNotFoundException {
return locations.get(location);
}
/**
* @return the locations
*/
public Map<String, Map<String, Double>> getLocations() {
return locations ;
}
public void setLocations (Map<String, Map<String, Double>> locations ) {
this.locations = locations ;
}
}