Search in sources :

Example 1 with ValidatorMessageSink

use of watson.yaml.ValidatorMessageSink in project watson by totemo.

the class Configuration method load.

// --------------------------------------------------------------------------
/**
   * Load the configuration file.
   */
public void load() {
    configureValidator();
    Log.info("Loading \"" + CONFIG_FILE + "\" from file.");
    File config = new File(Controller.getModDirectory(), CONFIG_FILE);
    BufferedInputStream in;
    try {
        in = new BufferedInputStream(new FileInputStream(config));
        ValidatorMessageSink logSink = new ValidatorMessageSink() {

            @Override
            public void message(String text) {
                Log.config(text);
            }
        };
        @SuppressWarnings("unchecked") HashMap<String, Object> dom = (HashMap<String, Object>) _validator.loadAndValidate(in, logSink);
        // Avoid calling setEnabled() at startup.
        // It would crash in Controller.getBlockEditSet() because server is not
        // set.
        _enabled = (Boolean) dom.get("enabled");
        // Avoid outputting a message in the client here:
        Log.setDebug((Boolean) dom.get("debug"));
        _autoPage = (Boolean) dom.get("auto_page");
        _regionInfoTimeoutSeconds = ((Number) dom.get("region_info_timeout")).doubleValue();
        _vectorsShown = (Boolean) dom.get("vectors_shown");
        _billboardBackground = (Integer) dom.get("billboard_background");
        _billboardForeground = (Integer) dom.get("billboard_foreground");
        _groupingOresInCreative = (Boolean) dom.get("group_ores_in_creative");
        _teleportCommand = (String) dom.get("teleport_command");
        _chatTimeoutSeconds = (Double) dom.get("chat_timeout");
        _maxAutoPages = (Integer) dom.get("max_auto_pages");
        _preCount = (Integer) dom.get("pre_count");
        _postCount = (Integer) dom.get("post_count");
        _watsonPrefix = (String) dom.get("watson_prefix");
        _ssPlayerDirectory = (Boolean) dom.get("ss_player_directory");
        _ssPlayerSuffix = (Boolean) dom.get("ss_player_suffix");
        setSsDateDirectoryImp((String) dom.get("ss_date_directory"));
        _reformatQueryResults = (Boolean) dom.get("reformat_query_results");
        _recolourQueryResults = (Boolean) dom.get("recolour_query_results");
        _timeOrderedDeposits = (Boolean) dom.get("time_ordered_deposits");
        _vectorLength = ((Double) dom.get("vector_length")).floatValue();
        for (Entry<String, ModifiedKeyBinding> entry : getKeyBindingsMap().entrySet()) {
            entry.getValue().parse((String) dom.get(entry.getKey()));
        }
    } catch (Exception ex) {
        Log.config("Missing configuration file (" + config + "). Using defaults.");
        // So save a default config.
        save();
    }
}
Also used : ValidatorMessageSink(watson.yaml.ValidatorMessageSink) BufferedInputStream(java.io.BufferedInputStream) HashMap(java.util.HashMap) File(java.io.File) FileInputStream(java.io.FileInputStream) ModifiedKeyBinding(watson.gui.ModifiedKeyBinding) IOException(java.io.IOException)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ModifiedKeyBinding (watson.gui.ModifiedKeyBinding)1 ValidatorMessageSink (watson.yaml.ValidatorMessageSink)1