public void load() { config.load(); DataKey root = config.getKey(""); for (Setting setting : Setting.values()) if (!root.keyExists(setting.path)) root.setRaw(setting.path, setting.get()); else setting.set(root.getRaw(setting.path)); }
@Override public void loadFromKey(DataKey root) { List<String> list = new ArrayList<String>(); for (DataKey key : root.getRelative("npc.default.text").getSubKeys()) list.add(key.getString("")); value = list; }
// Save settings for this NPC. These values will be added to the citizens // saves.yml under this NPC. public void save(DataKey key) { // key.setBoolean("SomeSetting", SomeSetting); key.setString("NPCType", npcType.name()); key.setString("UnitType", unitType.name()); key.setInt("settleId", settleId); key.setInt("buildingId", buildingId); // System.out.println("[REALMS] Trait save setting : "+key.toString()); }
@Override public void save(DataKey key) { saveOrRemove(key.getRelative("hand"), equipment[0]); saveOrRemove(key.getRelative("helmet"), equipment[1]); saveOrRemove(key.getRelative("chestplate"), equipment[2]); saveOrRemove(key.getRelative("leggings"), equipment[3]); saveOrRemove(key.getRelative("boots"), equipment[4]); }
private static void saveRegions(DataKey key, Multimap<String, TaggedRegion> tags) { for (Entry<String, TaggedRegion> entry : tags.entries()) { DataKey sub = key.getRelative(entry.getKey()); int length = sub.getInt("length", 0) + 1; sub.setInt("length", length); saveRegion(sub.getRelative(length), entry.getValue()); } }
@Override public void load(DataKey key) throws NPCLoadException { if (key.keyExists("hand")) equipment[0] = ItemStorage.loadItemStack(key.getRelative("hand")); if (key.keyExists("helmet")) equipment[1] = ItemStorage.loadItemStack(key.getRelative("helmet")); if (key.keyExists("chestplate")) equipment[2] = ItemStorage.loadItemStack(key.getRelative("chestplate")); if (key.keyExists("leggings")) equipment[3] = ItemStorage.loadItemStack(key.getRelative("leggings")); if (key.keyExists("boots")) equipment[4] = ItemStorage.loadItemStack(key.getRelative("boots")); }
private static Collection<TaggedRegion> loadRegions(File file) { Collection<TaggedRegion> ret = Lists.newArrayList(); Storage storage = new NBTStorage(file, "Schematic"); storage.load(); for (DataKey sub : storage.getKey("TaggedRegions").getSubKeys()) { String name = sub.name(); for (DataKey sub2 : sub.getIntegerSubKeys()) { Location min = loadLocation(sub2.getRelative("min")); Location max = loadLocation(sub2.getRelative("max")); ret.add(new TaggedRegion(name, min, max)); } } return ret; }
public void reload() { config.load(); for (Setting setting : Setting.values()) if (root.keyExists(setting.path)) setting.loadFromKey(root); save(); }
public Settings(File folder) { config = new YamlStorage(new File(folder, "config.yml"), "Citizens Configuration"); root = config.getKey(""); config.load(); for (Setting setting : Setting.values()) { if (!root.keyExists(setting.path)) { setting.setAtKey(root); } else setting.loadFromKey(root); } save(); }
@Override public void load(DataKey key) throws NPCLoadException { for (DataKey sub : key.getRelative("list").getIntegerSubKeys()) { String[] parts = sub.getString("").split(";"); Location location; try { location = new Location( Bukkit.getServer().getWorld(parts[1]), Double.valueOf(parts[2]), Double.valueOf(parts[3]), Double.valueOf(parts[4])); anchors.add(new Anchor(parts[0], location)); } catch (NumberFormatException e) { Messaging.logTr(Messages.SKIPPING_INVALID_ANCHOR, sub.name(), e.getMessage()); } catch (NullPointerException e) { // Invalid world/location/etc. Still enough data to build an // unloaded anchor anchors.add(new Anchor(parts[0], sub.getString("").split(";", 2)[1])); } } }
@Override public void load(DataKey key) { type = EntityType.fromName(key.getString("")); if (type == null) type = EntityType.PLAYER; }
protected void setAtKey(DataKey root) { root.setRaw(path, value); }
protected void loadFromKey(DataKey root) { value = root.getRaw(path); }
private void saveOrRemove(DataKey key, ItemStack item) { if (item != null) ItemStorage.saveItem(key, item); else { if (key.keyExists("")) key.removeKey(""); } }
private static void saveRegion(DataKey key, TaggedRegion value) { saveLocation(key.getRelative("min"), value.getMin()); saveLocation(key.getRelative("max"), value.getMax()); }
private static void saveLocation(DataKey key, Location location) { key.setDouble("x", location.getX()); key.setDouble("y", location.getY()); key.setDouble("z", location.getZ()); }
@Override public void save(DataKey key) { key.setString("", type.getName()); }
private static Location loadLocation(DataKey key) { return new Location(null, key.getDouble("x"), key.getDouble("y"), key.getDouble("z")); }
public void load(DataKey key) throws NPCLoadException { shop = key.getString("shop", null); }
@Override public void save(DataKey key) { key.removeKey("list"); for (int i = 0; i < anchors.size(); i++) key.setString("list." + String.valueOf(i), anchors.get(i).stringValue()); }
public void save(DataKey key) { key.setString("shop", this.shop); }