org.bukkit.configuration.file.YamlConfiguration.getList()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中org.bukkit.configuration.file.YamlConfiguration.getList()方法的一些代码示例,展示了YamlConfiguration.getList()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlConfiguration.getList()方法的具体详情如下:
包路径:org.bukkit.configuration.file.YamlConfiguration
类名称:YamlConfiguration
方法名:getList

YamlConfiguration.getList介绍

暂无

代码示例

代码示例来源:origin: garbagemule/MobArena

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);
    }
  });
}

代码示例来源:origin: garbagemule/MobArena

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);
}

代码示例来源:origin: SkyWars/SkyWars

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;
  }
}

代码示例来源:origin: SkyWars/SkyWars

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;
  }
}

代码示例来源:origin: garbagemule/MobArena

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;
    }
  }
}

代码示例来源:origin: SkyWars/SkyWars

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();
  }
}

代码示例来源:origin: BentoBoxWorld/BentoBox

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())));

代码示例来源:origin: BedwarsRel/BedwarsRel

for (Object rs : cfg.getList("spawner")) {
  if (!(rs instanceof ResourceSpawner)) {
   continue;
List<Object> list = (List<Object>) cfg.getList("record-holders", new ArrayList<Object>());
for (Object holder : list) {
 game.addRecordHolder(holder.toString());

代码示例来源:origin: io.github.bedwarsrel/BedwarsRel-Common

for (Object rs : cfg.getList("spawner")) {
  if (!(rs instanceof ResourceSpawner)) {
   continue;
List<Object> list = (List<Object>) cfg.getList("record-holders", new ArrayList<Object>());
for (Object holder : list) {
 game.addRecordHolder(holder.toString());

相关文章