Перейти к основному содержанию

Config

Json configuration file reading/writing utility.

Index

Constructors

constructor

  • new Config(file: File): Config
  • new Config(path: string): Config
  • Creates new Config instance using specified file.


    Parameters

    • file: File

      java.io.File instance of the file to use

    Returns Config

Methods

access

  • access<T>(name: string): T
  • Same as Config.get.


    Type parameters

    • T = string | number | boolean | Config | JSONArray

    Parameters

    • name: string

    Returns T

checkAndRestore

  • checkAndRestore(jsonstr: string): void
  • checkAndRestore(jsonobj: Scriptable): void
  • checkAndRestore(json: JSONObject): void
  • Ensures that config has all the properties the data pattern contains, if not, puts default values to match the pattern.


    Parameters

    • jsonstr: string

      string representation of JSON object representing the data pattern

    Returns void

get

  • get<T>(name: string): T
  • Gets property from the config.

    @example
    config.get("generation.ore_copper.max_height");

    Type parameters

    • T = string | number | boolean | Config | JSONArray

    Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    Returns T

    Config instance with current config as parent if the property is object, org.json.JSONArray instance if the property is an array, raw type if the property is of that raw type, null otherwise.

getBool

  • getBool(name: string): boolean

  • Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    Returns boolean

    Boolean config value specified in config or false if no value was specified.

getDouble

  • getDouble(name: string): number

  • Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    Returns number

    Double number of value by given name from the config, or 0.0 if no value was specified.

getFloat

  • getFloat(name: string): number

  • Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    Returns number

    Floating-point number of value by given name from the config, or 0.0 if no value was specified.

getInteger

  • getInteger(name: string): number

  • Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    Returns number

    Integer of value by given name from the config, or 0 if no value was specified.

getNames

  • getNames(): ArrayList<string>

  • Returns ArrayList<string>

    Read-only ArrayList instance containing all the names in the current config file.

getNumber

  • getNumber(name: string): Number

  • Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    Returns Number

    Number object instance, containing numeric value by given name from the config, or 0 if no value was specified.

getPath

  • getPath(): string
  • @since

    2.2.1b96


    Returns string

getString

  • getString(name: string): string

  • Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    Returns string

    String by given name from the config, or null if no value was specified.

getValue


  • Parameters

    • path: string

      option name, supports multi-layer calls, separated by '.'

    Returns ConfigValue

    Editable Config.ConfigValue instance that can be used to manipulate this config option separately.

reload

  • reload(): void
  • @since

    2.2.1b96


    Returns void

save

  • save(): void
  • Writes configuration JSON to the file.


    Returns void

set

  • set<T>(name: string, val: T): boolean
  • Sets config value. Do not use org.json.JSONObject instances to create nested objects, consider using dot-separated names instead.


    Type parameters

    • T = string | number | boolean | JSONArray | JSONObject

    Parameters

    • name: string

      option name, supports multi-layer calls, separated by '.'

    • val: T

      value, may be org.json.JSONArray instance, org.json.JSONObject instance or raw data type

    Returns boolean