summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/PropertyManager.java
blob: 9e548214db190aa340538d16d09191400e749ce5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package net.minecraft.server;

import java.io.*;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import joptsimple.OptionSet; // CraftBukkit

public class PropertyManager {

    public static Logger a = Logger.getLogger("Minecraft");
    private Properties b;
    private File c;

    public PropertyManager(File file) {
        b = new Properties();
        c = file;
        if (file.exists()) {
            try {
                b.load(((java.io.InputStream) (new FileInputStream(file))));
            } catch (Exception exception) {
                a.log(Level.WARNING, (new StringBuilder()).append("Failed to load ").append(((file))).toString(), ((Throwable) (exception)));
                a();
            }
        } else {
            a.log(Level.WARNING, (new StringBuilder()).append(((file))).append(" does not exist").toString());
            a();
        }
    }

    // Craftbukkit start
    private OptionSet options = null;

    public PropertyManager(final OptionSet options) {
        this((File)options.valueOf("config"));

        this.options = options;
    }

    private <T> T getOverride(String name, T value) {
        if ((options != null) && (options.has(name))) {
            return (T)options.valueOf(name);
        }

        return value;
    }
    // Craftbukkit end

    public void a() {
        a.log(Level.INFO, "Generating new properties file");
        b();
    }

    public void b() {
        try {
            b.store(((java.io.OutputStream) (new FileOutputStream(c))), "Minecraft server properties");
        } catch (Exception exception) {
            a.log(Level.WARNING, (new StringBuilder()).append("Failed to save ").append(((c))).toString(), ((Throwable) (exception)));
            a();
        }
    }

    public String a(String s, String s1) {
        if (!b.containsKey(((s)))) {
            b.setProperty(s, getOverride(s, s1)); // Craftbukkit
            b();
        }
        return getOverride(s, b.getProperty(s, s1)); // Craftbukkit
    }

    public int a(String s, int i) {
        try {
            return getOverride(s, Integer.parseInt(a(s, String.valueOf(i)))); // Craftbukkit
        } catch (Exception exception) {
            b.setProperty(s, getOverride(s, i).toString()); // Craftbukkit
        }
        return getOverride(s, i); // Craftbukkit
    }

    public boolean a(String s, boolean flag) {
        try {
            return getOverride(s, Boolean.parseBoolean(a(s, String.valueOf(flag)))); // Craftbukkit
        } catch (Exception exception) {
            b.setProperty(s, getOverride(s, flag).toString()); // Craftbukkit
        }
        return getOverride(s, flag); // Craftbukkit
    }
}