我在我的主类中使用它:
File locations = new File("plugins/GlobalSystem", "locations.yml");
if (!locations.exists()) {
try {
locations.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
FileConfiguration loc = YamlConfiguration.loadConfiguration(locations);
loc.set("spawn.Welt", "Welt");
loc.set("spawn.X", 0);
loc.set("spawn.Y", 100);
loc.set("spawn.Z", 0);
loc.set("spawn.Yaw", 0);
loc.set("spawn.Pitch", 0);
loc.set("reallife.Welt", "Welt");
loc.set("reallife.X", 0);
loc.set("reallife.Y", 100);
loc.set("reallife.Z", 0);
loc.set("reallife.Yaw", 0);
loc.set("reallife.Pitch", 0);
loc.set("acidisland.Welt", "Welt");
loc.set("acidisland.X", 0);
loc.set("acidisland.Y", 100);
loc.set("acidisland.Z", 0);
loc.set("acidisland.Yaw", 0);
loc.set("acidisland.Pitch", 0);
loc.set("skypvp.Welt", "Welt");
loc.set("skypvp.X", 0);
loc.set("skypvp.Y", 100);
loc.set("skypvp.Z", 0);
loc.set("skypvp.Yaw", 0);
loc.set("skypvp.Pitch", 0);
loc.set("spiele.Welt", "Welt");
loc.set("spiele.X", 0);
loc.set("spiele.Y", 100);
loc.set("spiele.Z", 0);
loc.set("spiele.Yaw", 0);
loc.set("spiele.Pitch", 0);
loc.set("silenthub.Welt", "Welt");
loc.set("silenthub.X", 0);
loc.set("silenthub.Y", 100);
loc.set("silenthub.Z", 0);
loc.set("silenthub.Yaw", 0);
loc.set("silenthub.Pitch", 0);
try {
loc.save(locations);
} catch (IOException e) {
e.printStackTrace();
}
}
如果你现在想读出一些东西,你可以使用例如这个:
FileConfiguration cfg = YamlConfiguration.loadConfiguration(new File("plugins/GlobalSystem", "locations.yml"));
Location loc = new Location(Bukkit.getWorld(cfg.getString("spawn.Welt")), cfg.getDouble("spawn.X"), cfg.getDouble("spawn.Y"), cfg.getDouble("spawn.Z"));
loc.setYaw((float) cfg.getDouble("spawn.Yaw"));
loc.setPitch((float) cfg.getDouble("spawn.Pitch"));
写入文件:
File file = new File("plugins/GlobalSystem", "locations.yml");
FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
Location loc = Player.getLocation();
cfg.set("spawn.Welt", loc.getWorld().getName());
cfg.set("spawn.X", loc.getX());
cfg.set("spawn.Y", loc.getY());
cfg.set("spawn.Z", loc.getZ());
cfg.set("spawn.Yaw", (double) loc.getYaw());
cfg.set("spawn.Pitch", (double) loc.getYaw());
try {
cfg.save(file);
} catch (IOException e) {
e.printStackTrace();
}
我希望这对您有所帮助,并为我的英语不好感到抱歉;)