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

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

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

YamlConfiguration.contains介绍

暂无

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Retrieves a section as a list of maps.
 *
 * @param key the key to look up
 * @return the value as a list of maps
 */
@SuppressWarnings("unchecked")
public List<Map<?, ?>> getMapList(Key key) {
  if (parameters.containsKey(key)) {
    return (List<Map<?, ?>>) parameters.get(key);
  }
  // there's no get or default method for the getMapList method, so using contains.
  if (!config.contains(key.path)) {
    parameters.put(key, key.def);
    return (List<Map<?, ?>>) key.def;
  }
  return config.getMapList(key.path);
}

代码示例来源:origin: GlowstoneMC/Glowstone

if (!config.contains(key.path)) {
  config.set(key.path, key.def);
  changed = true;

代码示例来源:origin: GlowstoneMC/Glowstone

if (!config.contains(key.path)) {
  config.set(key.path, key.def);
  changed = true;

代码示例来源:origin: GlowstoneMC/Glowstone

if (key.migrate == Migrate.BUKKIT && bukkit.contains(key.migratePath)) {
  config.set(key.path, bukkit.get(key.migratePath));
  migrateStatus = true;

代码示例来源:origin: com.greatmancode/tools

@Override
public boolean has(String path) {
  return configFile.contains(path);
}

代码示例来源:origin: DevLeoko/AdvancedBan

@Override
public boolean contains(Object file, String path) {
  return ((YamlConfiguration) file).contains(path);
}

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

public boolean contains(String reference) {
  return config.contains(reference);
}

代码示例来源:origin: sgtcaze/NametagEdit

@Override
  public void response(UUID uuid) {
    if (players.contains("Players." + uuid.toString())) {
      players.set("Players." + uuid.toString(), priority);
      save(players, playersFile);
    }
  }
});

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

/**
 * Get text from the yml file for this locale
 * @param reference - the YAML node where the text is
 * @return Text for this locale reference or the reference if nothing has been found
 */
public String get(String reference) {
  if (config.contains(reference)) {
    return config.getString(reference);
  }
  return reference; // return reference in case nothing has been found
}

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

public void removeValue(String path) {
  if (config.contains(path)) {
    logger.log(Level.INFO, "Removing deprecated value {0} in file {1}", new Object[]{path, configFile});
    config.set(path, null);
  }
}

代码示例来源:origin: drtshock/PlayerVaults

/**
 * Checks if a vault exists.
 *
 * @param holder holder of the vault.
 * @param number vault number.
 * @return true if the vault file and vault number exist in that file, otherwise false.
 */
public boolean vaultExists(String holder, int number) {
  File file = new File(directory, holder + ".yml");
  if (!file.exists()) {
    return false;
  }
  return getPlayerVaultFile(holder, true).contains(String.format(VAULTKEY, number));
}

代码示例来源:origin: drtshock/PlayerVaults

/**
 * Checks if a vault exists.
 *
 * @param holder holder of the vault.
 * @param number vault number.
 * @return true if the vault file and vault number exist in that file, otherwise false.
 */
public boolean vaultExists(String holder, int number) {
  File file = new File(directory, holder + ".yml");
  if (!file.exists()) {
    return false;
  }
  return getPlayerVaultFile(holder).contains("vault" + number);
}

代码示例来源:origin: stackoverflow.com

YamlConfiguration config = new YamlConfiguration();
File[] files = this.getDataFolder().listFiles();
for(File file : files){
  try {
    config.load(file);
    if(config.contains("Path")){
      //What you need to do.
    }
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  } catch (InvalidConfigurationException e) {
    e.printStackTrace();
  }
}

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

public long getSetLong(String path, long defaultInt) throws InvalidConfigurationException {
  if (config.isInt(path)) {
    return config.getLong(path);
  } else if (config.contains(path)) {
    throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile.toAbsolutePath() + " is not a long");
  } else {
    logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultInt, configFile});
    config.set(path, defaultInt);
    return defaultInt;
  }
}

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

public ConfigurationSection getSetSection(String path, Map<String, String> defaultValues) throws InvalidConfigurationException {
  if (config.isConfigurationSection(path)) {
    return config.getConfigurationSection(path);
  } else if (config.contains(path)) {
    throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile + " is not a configuration section");
  } else {
    logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultValues, configFile});
    ConfigurationSection section = config.createSection(path);
    for (Map.Entry<String, String> entry : defaultValues.entrySet()) {
      section.set(entry.getKey(), entry.getValue());
    }
    return section;
  }
}

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

/**
 * Merges a language YAML file to this locale
 * @param toBeMerged the YamlConfiguration of the language file
 */
public void merge(YamlConfiguration toBeMerged) {
  for (String key : toBeMerged.getKeys(true)) {
    if (!key.startsWith("meta") && !config.contains(key)) {
      config.set(key, toBeMerged.get(key));
    }
  }
  updateAuthors(toBeMerged);
}

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

/**
 * Paste clipboard at this location
 * @param location - location
 */
public void pasteClipboard(Location location) {
  if (blockConfig.contains(BLOCKS_YAML_PREFIX)) {
    paste(location.getWorld(), null, location, null);
  } else {
    plugin.logError("Clipboard has no block data in it to paste!");
  }
}

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

public int getSetInt(String path, int defaultInt) throws InvalidConfigurationException {
  if (config.isInt(path)) {
    return config.getInt(path);
  } else if (config.contains(path)) {
    throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile.toAbsolutePath() + " is not an integer");
  } else {
    logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultInt, configFile});
    config.set(path, defaultInt);
    return defaultInt;
  }
}

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

public boolean getSetBoolean(String path, boolean defaultBoolean) throws InvalidConfigurationException {
  if (config.isBoolean(path)) {
    return config.getBoolean(path);
  } else if (config.contains(path)) {
    throw new InvalidConfigurationException("Object " + config.get(path) + " found under " + path + " in file " + configFile.toAbsolutePath() + " is not a boolean (true/false)");
  } else {
    logger.log(Level.INFO, "Setting {0} to {1} in file {2}", new Object[]{path, defaultBoolean, configFile});
    config.set(path, defaultBoolean);
    return defaultBoolean;
  }
}

代码示例来源:origin: sgtcaze/NametagEdit

public static PlayerData fromFile(String key, YamlConfiguration file) {
  if (!file.contains("Players." + key)) return null;
  PlayerData data = new PlayerData();
  data.setUuid(UUID.fromString(key));
  data.setName(file.getString("Players." + key + ".Name"));
  data.setPrefix(file.getString("Players." + key + ".Prefix", ""));
  data.setSuffix(file.getString("Players." + key + ".Suffix", ""));
  data.setSortPriority(file.getInt("Players." + key + ".SortPriority", -1));
  return data;
}

相关文章