1414import java .io .*;
1515import java .util .ArrayList ;
1616import java .util .List ;
17+ import java .util .Locale ;
1718import java .util .logging .Level ;
1819
1920public class Config {
2021 public static int SessionTime = 120 ;
22+ public enum StorageType {
23+ Mysql , H2
24+ }
25+ public static StorageType storageType ;
2126
2227 public static List <ServerInfo > lobbies = new ArrayList <ServerInfo >();
2328 public static List <ServerInfo > auths = new ArrayList <ServerInfo >();
2429 public static List <String > whitelistedCommands ;
2530
26- public static String pluginMsgConf ;
2731 public static int serverCheckInterval = 30 ,
28- maxPremiumAccounts , maxCrackedAccounts , maxTotalAccounts ;
29- public static String backupServer , secondAttempt ;
30- public static boolean forceBackupServer , convertOldCrackedToPremium , backupServerEnabled , secondAttemptEnabled ;
32+ maxPremiumAccounts , maxCrackedAccounts , maxTotalAccounts , authTime ;
33+
34+ public static String backupServer , secondAttempt , pluginMsgConf ;
35+
36+ public static boolean forceBackupServer , convertOldCrackedToPremium , backupServerEnabled , secondAttemptEnabled , disconnectOnWrongPass ;
3137 public static class Messages {
3238 public static String registerError , loginAndRegisterSuccess , alreadyLoggedIn , loginNotRegistered ,
3339 loginWrongPass , loginError , alreadyRegistered , noServersAvailable , registerMessage ,
3440 loginMessage , logoutMessage , changePassError , genericPremiumError , successfulChangePass ,
35- tooManyAccounts ;
41+ tooManyAccounts , loginRegisterBossBar , authTimeExceeded ;
3642 public static Title loginAndRegisterSuccessTitle , registerTitle , loginTitle ;
3743 }
3844 public enum MYSQL {
@@ -45,12 +51,15 @@ public enum MYSQL {
4551
4652
4753 public static Configuration config ;
54+ private static Configuration defaultConf ;
4855
4956
5057 public static void load () {
5158 saveDefaultConf ();
5259 try {
53- config = ConfigurationProvider .getProvider (YamlConfiguration .class ).load (new File (AdiAuth .instance .getDataFolder (), "config.yml" ));
60+ //Loading the default config
61+ defaultConf = ConfigurationProvider .getProvider (YamlConfiguration .class ).load (AdiAuth .instance .getResourceAsStream ("bungeeconfig.yml" ));
62+ config = ConfigurationProvider .getProvider (YamlConfiguration .class ).load (new File (AdiAuth .instance .getDataFolder (), "config.yml" ), defaultConf );
5463 Configuration mysqlConf = config .getSection ("mysql" );
5564 for (MYSQL x : MYSQL .values ()) {
5665 x .value = mysqlConf .getString (x .name ());
@@ -95,14 +104,28 @@ public static void load() {
95104 Messages .tooManyAccounts = getMsgString ("tooManyAccounts" );
96105 secondAttempt = tools .getColoured (config .getString ("secondAttempt" ));
97106 Config .secondAttemptEnabled = !secondAttempt .equals ("" );
107+ disconnectOnWrongPass = config .getBoolean ("disconnectOnWrongPass" );
108+ authTime = config .getInt ("authTime" );
109+ Messages .loginRegisterBossBar = getMsgString ("loginRegisterBossBar" );
110+ Messages .authTimeExceeded = getMsgString ("authTimeExceeded" );
111+ String database = config .getString ("database" ).toLowerCase ();
112+ switch (database ){
113+ case "mysql" :
114+ storageType = StorageType .Mysql ;
115+ break ;
116+ case "h2" :
117+ storageType = StorageType .H2 ;
118+ break ;
119+ default :
120+ storageType = StorageType .H2 ;
121+ break ;
122+ }
98123
99124 }
100125 catch (Exception e ){
101126 e .printStackTrace ();
102127 tools .log (Level .SEVERE , "Config wasnt loaded properly!" );
103128 }
104-
105-
106129 }
107130
108131
@@ -115,11 +138,16 @@ private static Title createTitle(String msg){
115138 title .fadeIn (50 );
116139 return title ;
117140 }
141+
118142 private static void saveDefaultConf (){
119143 File configFile = new File (AdiAuth .instance .getDataFolder (), "config.yml" );
120144 if (!AdiAuth .instance .getDataFolder ().exists ()) {
121145 AdiAuth .instance .getDataFolder ().mkdir ();
122146 }
147+ File libFolder = new File (configFile .getParentFile ().toString ()+"/libs" );
148+ if (!libFolder .exists ()){
149+ libFolder .mkdir ();
150+ }
123151 if (!configFile .exists ()) {
124152 try {
125153 configFile .createNewFile ();
0 commit comments