11package mc .unraveled .reforged .storage ;
22
33import org .bukkit .Bukkit ;
4+ import org .bukkit .plugin .Plugin ;
45
6+ import java .io .File ;
57import java .io .FileInputStream ;
8+ import java .io .FileOutputStream ;
69import java .io .IOException ;
710import java .util .Properties ;
811
@@ -17,13 +20,21 @@ public class DBProperties {
1720 private final String username ;
1821 private final String password ;
1922
20- public DBProperties (String fileName ) {
23+ public DBProperties (Plugin plugin , String fileName ) {
24+ File file = new File (plugin .getDataFolder (), fileName );
2125 properties = new Properties ();
22- try (FileInputStream fileInputStream = new FileInputStream (fileName )) {
26+
27+ try (FileInputStream fileInputStream = new FileInputStream (file )) {
28+ if (file .createNewFile ()) {
29+ Bukkit .getLogger ().info ("Created new properties file." );
30+ plugin .saveResource ("db.properties" , true );
31+ }
32+
2333 properties .load (fileInputStream );
2434 } catch (IOException e ) {
25- Bukkit .getLogger ().severe ("Could not load database properties file!" );
35+ Bukkit .getLogger ().severe ("Error loading properties file!" + e . getMessage () );
2636 }
37+
2738 driver = properties .getProperty ("driver" );
2839 databaseType = properties .getProperty ("databaseType" );
2940 databaseFile = properties .getProperty ("databaseFile" );
0 commit comments