Configuration.java 3.57 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
package emu.grasscutter;

3
import emu.grasscutter.utils.ConfigContainer;
KingRainbow44's avatar
KingRainbow44 committed
4
import emu.grasscutter.utils.ConfigContainer.*;
KingRainbow44's avatar
KingRainbow44 committed
5
6

import java.util.Locale;
7
import java.nio.file.Paths;
KingRainbow44's avatar
KingRainbow44 committed
8

9
10
import static emu.grasscutter.Grasscutter.config;

11

KingRainbow44's avatar
KingRainbow44 committed
12
13
/**
 * A data container for the server's configuration.
14
15
16
 * 
 * Use `import static emu.grasscutter.Configuration.*;`
 * to import all configuration constants.
KingRainbow44's avatar
KingRainbow44 committed
17
 */
18
public final class Configuration extends ConfigContainer {
19
20
21
22
23
24
    
    /*
     * Constants
     */
    
    // 'c' is short for 'config' and makes code look 'cleaner'.
25
    public static final ConfigContainer c = config;
26
27
28
    
    public static final Locale LANGUAGE = config.language.language;
    public static final Locale FALLBACK_LANGUAGE = config.language.fallback;
xtaodada's avatar
xtaodada committed
29
    public static final String DOCUMENT_LANGUAGE = config.language.document;
30
31
32
33
34
    private static final String DATA_FOLDER = config.folderStructure.data;
    private static final String RESOURCES_FOLDER = config.folderStructure.resources;
    private static final String PLUGINS_FOLDER = config.folderStructure.plugins;
    private static final String SCRIPTS_FOLDER = config.folderStructure.scripts;
    private static final String PACKETS_FOLDER = config.folderStructure.packets;
35
36
37
38
39
    
    public static final Server SERVER = config.server;
    public static final Database DATABASE = config.databaseInfo;
    public static final Account ACCOUNT = config.account;
    
40
    public static final HTTP HTTP_INFO = config.server.http;
41
    public static final Game GAME_INFO = config.server.game;
42
    public static final Dispatch DISPATCH_INFO = config.server.dispatch;
43
    
44
45
    public static final Encryption HTTP_ENCRYPTION = config.server.http.encryption;
    public static final Policies HTTP_POLICIES = config.server.http.policies;
KingRainbow44's avatar
KingRainbow44 committed
46
    public static final Files HTTP_STATIC_FILES = config.server.http.files;
47
48
49
50
51
52
53
    
    public static final GameOptions GAME_OPTIONS = config.server.game.gameOptions;
    public static final GameOptions.InventoryLimits INVENTORY_LIMITS = config.server.game.gameOptions.inventoryLimits;
    
    /*
     * Utilities
     */
54
55
56
57
    public static String DATA() {
        return DATA_FOLDER;
    }

58
    public static String DATA(String path) {
59
        return Paths.get(DATA_FOLDER, path).toString();
60
61
62
    }
    
    public static String RESOURCE(String path) {
63
64
        return Paths.get(RESOURCES_FOLDER, path).toString();
    }
65
    
66
67
68
69
70
71
72
73
    public static String PLUGIN() {
        return PLUGINS_FOLDER;
    }

    public static String PLUGIN(String path) {
        return Paths.get(PLUGINS_FOLDER, path).toString();
    }

74
    public static String SCRIPT(String path) {
75
76
77
78
79
        return Paths.get(SCRIPTS_FOLDER, path).toString();
    }

    public static String PACKET(String path) {
        return Paths.get(PACKETS_FOLDER, path).toString();
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    }

    /**
     * Fallback method.
     * @param left Attempt to use.
     * @param right Use if left is undefined.
     * @return Left or right.
     */
    public static <T> T lr(T left, T right) {
        return left == null ? right : left;
    }

    /**
     * {@link Configuration#lr(Object, Object)} for {@link String}s.
     * @param left Attempt to use.
     * @param right Use if left is empty.
     * @return Left or right.
     */
    public static String lr(String left, String right) {
        return left.isEmpty() ? right : left;
    }

    /**
     * {@link Configuration#lr(Object, Object)} for {@link Integer}s.
     * @param left Attempt to use.
     * @param right Use if left is 0.
     * @return Left or right.
     */
    public static int lr(int left, int right) {
        return left == 0 ? right : left;
    }
111
}