Skip to content

Commit c698ced

Browse files
committed
Fix DBProperties not writing to disk
1 parent 31b0a8a commit c698ced

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

2 Bytes
Binary file not shown.

src/main/java/mc/unraveled/reforged/plugin/Traverse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public StaffChat getStaffChat() {
102102

103103
@Override
104104
public void onEnable() {
105-
this.SQLManager = new DBConnectionHandler(new DBProperties("db.properties"));
105+
this.SQLManager = new DBConnectionHandler(new DBProperties(this, "db.properties"));
106106
this.commandLoader = new CommandLoader(this, "TRAVERSE");
107107
this.dataManager = new DataManager(this);
108108
this.banManager = new BanManager(this);

src/main/java/mc/unraveled/reforged/storage/DBProperties.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package mc.unraveled.reforged.storage;
22

33
import org.bukkit.Bukkit;
4+
import org.bukkit.plugin.Plugin;
45

6+
import java.io.File;
57
import java.io.FileInputStream;
8+
import java.io.FileOutputStream;
69
import java.io.IOException;
710
import 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

Comments
 (0)