Exemplo n.º 1
0
  /**
   * 設定ファイルのバージョンをチェックする
   *
   * @param ver
   */
  private void checkver(final double ver) {
    double configVersion = ver;
    double nowVersion = 0.1D;

    String versionString = plugin.getDescription().getVersion();
    try {
      // Support maven and Jenkins build number
      int index = versionString.indexOf("-");
      if (index > 0) {
        versionString = versionString.substring(0, index);
      }
      nowVersion = Double.parseDouble(versionString);
    } catch (NumberFormatException ex) {
      log.warning(logPrefix + "Cannot parse version string!");
    }

    // 比較 設定ファイルのバージョンが古ければ config.yml を上書きする
    if (configVersion < nowVersion) {
      // 先に古い設定ファイルをリネームする
      String destName = "oldconfig-v" + configVersion + ".yml";
      String srcPath = new File(pluginDir, "config.yml").getPath();
      String destPath = new File(pluginDir, destName).getPath();
      try {
        copyTransfer(srcPath, destPath);
        log.info(logPrefix + "Copied old config.yml to " + destName + "!");
      } catch (Exception ex) {
        log.warning(logPrefix + "Cannot copy old config.yml!");
      }

      // config.ymlを強制コピー
      extractResource("/config.yml", pluginDir, true, false);

      log.info(logPrefix + "Deleted existing configuration file and generate a new one!");
    }
  }
Exemplo n.º 2
0
  /**
   * 設定をファイルから読み込む
   *
   * @param initialLoad 初回ロードかどうか
   */
  public void loadConfig(boolean initialLoad) throws Exception {
    // create directories
    createDirs();

    // 設定ファイルパス取得
    File file = new File(pluginDir, "config.yml");
    // 無ければデフォルトコピー
    if (!file.exists()) {
      extractResource("/config.yml", pluginDir, false, true);
      log.info(logPrefix + "config.yml is not found! Created default config.yml!");
    }

    plugin.reloadConfig();

    // check version
    double version = plugin.getConfig().getDouble("Version", 0.1D);
    checkver(version);

    /* Basic Configs */
    whiteWorlds = plugin.getConfig().getStringList("WhiteWorlds");
    useSpawnEvent = plugin.getConfig().getBoolean("CancelWitherSpawnEvent", true);
    deniedMessage =
        plugin.getConfig().getString("DeniedMessage", "You do not have permission to do this!");

    /* Other Configs */
    debug = plugin.getConfig().getBoolean("Debug", false);
  }
Exemplo n.º 3
0
 /** 必要なディレクトリ群を作成する */
 private void createDirs() {
   createDir(plugin.getDataFolder());
 }
Exemplo n.º 4
0
 /**
  * 設定ファイルに設定を書き込む (コメントが消えるため使わない)
  *
  * @throws Exception
  */
 public void save() throws Exception {
   plugin.saveConfig();
 }