This commit is contained in:
Aubri Seebauer committed 2023-04-21 18:02:43 -04:00
1 parent 837b842c0e
commit 6176a61e05
6 files changed
+149 -163

No files matched your search

@@ -6,7 +6,6 @@ import org.yaml.snakeyaml.Yaml;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@@ -26,14 +25,15 @@ public class DataManager {
genDefaultFiles();
}
private static String dataFolder = "plugins" + File.separator + "EntityBingo" + File.separator + "data";
private final static String dataFolder = "plugins" + File.separator + "EntityBingo" + File.separator + "data";
/**
* Saves data into a .yml format
*
* @param filePath - File's path after <PLUGIN>/Data/
* @param map - Map to be saved
* @param map - Map to be saved
*/
public static void saveData(String filePath, HashMap<String,Object> map) {
public static void saveData(String filePath, HashMap<String, Object> map) {
File file = getFile(filePath);
PrintWriter writer = null;
try {
@@ -42,14 +42,14 @@ public class DataManager {
Bukkit.getLogger().info("Encountered error when creating PrintWriter for " + filePath);
return;
}
if (options == null) {
options = new DumperOptions();
options.setIndent(2);
options.setPrettyFlow(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
}
Yaml yaml = new Yaml(options);
yaml.dump(map, writer);
writer.close();
@@ -57,25 +57,27 @@ public class DataManager {
/**
* Gets the data back as a HashMap
*
* @param filePath - FilePath of data
* @return HashMap of data or null
*/
public static HashMap<String,Object> getData(String filePath) {
public static HashMap<String, Object> getData(String filePath) {
File file = getFile(filePath);
return getData(file);
}
/**
* Gets the data back as a HashMap
*
* @param file - Data file
* @return HashMap of data or null
*/
public static HashMap<String,Object> getData(File file) {
public static HashMap<String, Object> getData(File file) {
if (!file.exists()) {
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + file.getPath());
return null;
}
InputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
@@ -90,12 +92,13 @@ public class DataManager {
} catch (IOException e) {
Bukkit.getLogger().info(e.getMessage());
}
return data;
}
/**
* Deletes the specified file
*
* @param filePath - FilePath of deletion
* @return Boolean of success
*/
@@ -106,7 +109,7 @@ public class DataManager {
Bukkit.getLogger().info("Attempted to retrieve non-existant file: " + filePath + ".yml");
return false;
}
try {
return Files.deleteIfExists(file.toPath());
} catch (IOException e) {
@@ -117,12 +120,13 @@ public class DataManager {
/**
* Converts filePath into File
*
* @param path - File's path within data folder
* @return File or null
*/
private static File getFile(String path) {
path = dataFolder + File.separator + path;
File file = new File(path);
if (!file.exists()) {
try {