Exemplo n.º 1
0
  /**
   * Build the new Config file to save.
   *
   * @param newConfig
   * @param defaults apply defaults or data from settings.
   * @return the config in a string
   */
  public String setConfigs(String newConfig, boolean defaults) {

    String global =
        "{channelTag} {worldname}{townytagoverride}{townycolor}{permprefix}{group} {townyprefix}{modplayername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}";
    String town =
        "{channelTag} {townycolor}{permprefix}{townyprefix}{playername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}";
    String nation =
        "{channelTag}{towntagoverride}{townycolor}{permprefix}{townyprefix}{playername}{townypostfix}{permsuffix}&f:{msgcolour} {msg}";
    String default_ = "{channelTag} {permprefix}{playername}{permsuffix}&f:{msgcolour} {msg}";

    String tag_world = "&f[&f%s&f] ";
    String tag_town = "&f[&3%s&f] ";
    String tag_nation = "&f[&e%s&f] ";
    String tag_both = "&f[&6%s&f|&3%s&f] ";

    String king = "&6";
    String mayor = "&b";
    String resident = "&f";

    newConfig =
        newConfig.replace(
            "[spam_time]", (defaults) ? "0.5" : Double.toString(ChatSettings.getSpam_time()));

    newConfig =
        newConfig.replace(
            "[hd_enable]",
            (defaults) ? "true" : Boolean.toString(ChatSettings.isHeroicDeathToIRC()));
    newConfig =
        newConfig.replace("[hd_tags]", (defaults) ? "admin" : ChatSettings.getHeroicDeathTags());

    newConfig =
        newConfig.replace(
            "[globalformat]",
            (defaults) ? global : ChatSettings.getFormatGroup("channel_formats").getGLOBAL());
    newConfig =
        newConfig.replace(
            "[townformat]",
            (defaults) ? town : ChatSettings.getFormatGroup("channel_formats").getTOWN());
    newConfig =
        newConfig.replace(
            "[nationformat]",
            (defaults) ? nation : ChatSettings.getFormatGroup("channel_formats").getNATION());
    newConfig =
        newConfig.replace(
            "[defaultformat]",
            (defaults) ? default_ : ChatSettings.getFormatGroup("channel_formats").getDEFAULT());

    newConfig =
        newConfig.replace("[tag_world]", (defaults) ? tag_world : ChatSettings.getWorldTag());
    newConfig = newConfig.replace("[tag_town]", (defaults) ? tag_town : ChatSettings.getTownTag());
    newConfig =
        newConfig.replace("[tag_nation]", (defaults) ? tag_nation : ChatSettings.getNationTag());
    newConfig = newConfig.replace("[tag_both]", (defaults) ? tag_both : ChatSettings.getBothTags());

    newConfig =
        newConfig.replace("[colour_king]", (defaults) ? king : ChatSettings.getKingColour());
    newConfig =
        newConfig.replace("[colour_mayor]", (defaults) ? mayor : ChatSettings.getMayorColour());
    newConfig =
        newConfig.replace(
            "[colour_resident]", (defaults) ? resident : ChatSettings.getResidentColour());

    newConfig =
        newConfig.replace(
            "[modify_enable]",
            (defaults) ? "true" : Boolean.toString(ChatSettings.isModify_chat()));
    newConfig =
        newConfig.replace(
            "[modify_per_world]",
            (defaults) ? "false" : Boolean.toString(ChatSettings.isPer_world()));

    for (String key : ChatSettings.getFormatGroups().keySet()) {
      if (!key.equalsIgnoreCase("channel_formats")) {
        channelFormats world = ChatSettings.getFormatGroup(key);

        newConfig += "    '" + key + "':" + System.getProperty("line.separator");

        newConfig +=
            "      global: '"
                + ((defaults) ? global : world.getGLOBAL())
                + "'"
                + System.getProperty("line.separator");
        newConfig +=
            "      town: '"
                + ((defaults) ? town : world.getTOWN())
                + "'"
                + System.getProperty("line.separator");
        newConfig +=
            "      nation: '"
                + ((defaults) ? nation : world.getNATION())
                + "'"
                + System.getProperty("line.separator");
        newConfig +=
            "      default: '"
                + ((defaults) ? default_ : world.getDEFAULT())
                + "'"
                + System.getProperty("line.separator");
      }
    }

    return newConfig;
  }