private void validateTemplateNode(String key, YamlConfiguration yaml) { List<?> list = yaml.getList(key); if (list == null) { String msg = "Template " + key + " in " + TemplateStore.FILENAME + " is not a list!"; throw new IllegalStateException(msg); } list.forEach(element -> { if (!(element instanceof String)) { String msg = "Template " + key + " in " + TemplateStore.FILENAME + " is not a valid list of strings!"; throw new IllegalStateException(msg); } }); }
SignStore load() { YamlConfiguration yaml = new YamlConfiguration(); try { File data = new File(plugin.getDataFolder(), "data"); yaml.load(new File(data, SignStore.FILENAME)); } catch (FileNotFoundException e) { return new SignStore(Collections.emptyList()); } catch (InvalidConfigurationException e) { String msg = SignStore.FILENAME + " is invalid! You may have to delete it."; throw new IllegalStateException(msg, e); } catch (IOException e) { throw new IllegalStateException(e); } List<ArenaSign> signs = yaml.getList("signs").stream() .filter(raw -> raw instanceof ArenaSign) .map(raw -> (ArenaSign) raw) .collect(Collectors.toList()); plugin.getLogger().info("Loaded " + signs.size() + " arena signs."); return new SignStore(signs); }
public List<Long> getSetLongList(String path, List<Long> defaultList) throws InvalidConfigurationException { if (config.isList(path)) { List<?> unknownList = config.getList(path); List<Long> longList = new ArrayList<>(unknownList.size()); for (Object obj : unknownList) { if (obj instanceof Number) { longList.add(((Number) obj).longValue()); } else { throw new InvalidConfigurationException("Object " + obj + " found in list " + path + " in file " + configFile.toAbsolutePath() + " is not a number"); } } return longList; } else if (config.contains(path)) { throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile + " is not a list"); } else { logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultList, configFile}); config.set(path, defaultList); return defaultList; } }
public List<String> getSetStringList(String path, List<String> defaultList) throws InvalidConfigurationException { if (config.isList(path)) { List<?> unknownList = config.getList(path); List<String> stringList = new ArrayList<>(unknownList.size()); for (Object obj : unknownList) { if (obj instanceof String) { stringList.add((String) obj); } else if (obj instanceof Double || obj instanceof Integer || obj instanceof Boolean) { stringList.add(obj.toString()); } else { throw new InvalidConfigurationException("Object " + obj + " found in list " + path + " in file " + configFile.toAbsolutePath() + " is not a string"); } } return stringList; } else if (config.contains(path)) { throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile + " is not a list"); } else { logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultList, configFile}); config.set(path, defaultList); return defaultList; } }
public static boolean restoreFromFile(MobArena plugin, Player p) { try { File inventories = new File(plugin.getDataFolder(), "inventories"); File file = new File(inventories, p.getUniqueId().toString()); if (!file.exists()) { return false; } YamlConfiguration config = new YamlConfiguration(); config.load(file); ItemStack[] contents = config.getList("contents").toArray(new ItemStack[0]); p.getInventory().setContents(contents); file.delete(); return true; } catch (Exception e) { plugin.getLogger().log(Level.SEVERE, "Failed to restore inventory for " + p.getName(), e); return false; } } }
public String[] getSetFixedArray(final String path, final String[] defaultValues) throws InvalidConfigurationException { if (config.isList(path)) { List<?> list = config.getList(path); if (list.isEmpty()) { config.set(path, Arrays.asList(defaultValues)); return defaultValues.clone(); } else if (list.size() < defaultValues.length) { throw new InvalidConfigurationException("Too few strings in list " + path + " in file " + configFile + ": expected " + defaultValues.length + ", found " + list.size() + "."); } else if (list.size() > defaultValues.length) { throw new InvalidConfigurationException("Too many strings in list " + path + " in file " + configFile + ": expected " + defaultValues.length + ", found " + list.size() + "."); } String[] result = new String[defaultValues.length]; for (int i = 0; i < defaultValues.length; i++) { result[i] = String.valueOf(list.get(i)); } return result; } else if (config.contains(path)) { throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile + " is not an array."); } else { config.set(path, Arrays.asList(defaultValues)); return defaultValues.clone(); } }
if (config.getList(storageLocation) != null) { for (Object listValue: config.getList(storageLocation)) { value.add(deserialize(listValue,Class.forName(setType.getTypeName()))); if (config.getList(storageLocation) != null) { for (Object listValue: config.getList(storageLocation)) { value.add(deserialize(listValue,Class.forName(setType.getTypeName())));