org.bukkit.plugin.Plugin.saveDefaultConfig()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(2.5k)|赞(0)|评价(0)|浏览(198)

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

Plugin.saveDefaultConfig介绍

[英]Saves the raw contents of the default config.yml file to the location retrievable by #getConfig(). If there is no default config.yml embedded in the plugin, an empty config.yml file is saved. This should fail silently if the config.yml already exists.
[中]保存默认配置的原始内容。yml文件到可通过#getConfig()检索的位置。如果没有默认配置。插件中嵌入的yml是一个空配置。yml文件已保存。如果配置失败,这应该会悄无声息地失败。yml已经存在。

代码示例

代码示例来源:origin: games647/ScoreboardStats

public Settings(Plugin plugin, Logger logger) {
  super(logger, plugin.getDataFolder().toPath());
  plugin.saveDefaultConfig();
}

代码示例来源:origin: com.github.drepic26/couponcodes

public BukkitConfigHandler(Plugin plugin) {
  this.config = plugin.getConfig();
  if (!(new File("plugins/CouponCodes/config.yml").exists()))
    plugin.saveDefaultConfig();
  if (!config.options().copyDefaults(true).configuration().equals(config))
    plugin.saveConfig();
}

代码示例来源:origin: aadnk/ProtocolLib

/**
 * Load data sections.
 * 
 * @param copyDefaults - whether or not to copy configuration defaults.
 */
private void loadSections(boolean copyDefaults) {
  if (config != null) {
    global = config.getConfigurationSection(SECTION_GLOBAL);
  }
  if (global != null) {
    updater = global.getConfigurationSection(SECTION_AUTOUPDATER);
    if (updater.getValues(true).isEmpty()) {
      plugin.getLogger().warning("Updater section is missing, regenerate your config!");
    }
  }
  // Automatically copy defaults
  if (copyDefaults && (!getFile().exists() || global == null || updater == null)) {
    loadingSections = true;
    if (config != null)
      config.options().copyDefaults(true);
    plugin.saveDefaultConfig();
    plugin.reloadConfig();
    loadingSections = false;
    // Inform the user
    plugin.getLogger().info("Created default configuration.");
  }
}

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

/**
 * This function loads our custom config with comments, and includes changes
 */
private Configuration getCustomConfig(Plugin plugin) {
  File file = new File(plugin.getDataFolder(), "config.yml");
  if (!file.exists()) {
    plugin.saveDefaultConfig();
    Configuration newConfig = new Configuration(file);
    newConfig.reload(true);
    return newConfig;
  } else {
    Configuration oldConfig = new Configuration(file);
    oldConfig.reload(false);
    file.delete();
    plugin.saveDefaultConfig();
    Configuration newConfig = new Configuration(file);
    newConfig.reload(true);
    for (String key : oldConfig.getKeys(false)) {
      if (newConfig.contains(key)) {
        newConfig.set(key, oldConfig.get(key));
      }
    }
    newConfig.save();
    return newConfig;
  }
}

相关文章