diff --git a/src/main/java/com/burchard36/Api.java b/src/main/java/com/burchard36/Api.java index 6df92b5..791dfd2 100644 --- a/src/main/java/com/burchard36/Api.java +++ b/src/main/java/com/burchard36/Api.java @@ -1,16 +1,7 @@ package com.burchard36; -import com.burchard36.json.PluginDataManager; - public interface Api { - /** - * In order for the Data Management side of this plugin to work, it needs to have access to an already running - * PluginDataManager - * @return running PluginDataManager instance - */ - PluginDataManager getPluginDataManager(); - /** * If the debug mode is true, when debug is called on the * Logger#debug method a message gets logged, this also may effect other things diff --git a/src/main/java/com/burchard36/ApiLib.java b/src/main/java/com/burchard36/ApiLib.java index 7969e23..0ba6ab4 100644 --- a/src/main/java/com/burchard36/ApiLib.java +++ b/src/main/java/com/burchard36/ApiLib.java @@ -74,11 +74,6 @@ public static Api getLib(final JavaPlugin plugin) { } else return null; } - @Override - public PluginDataManager getPluginDataManager() { - return this.manager; - } - @Override public boolean isDebug() { return getLib(this.plugin).isDebug(); @@ -100,4 +95,12 @@ public static String convert(final String message) { public HologramManager getHologramManager() { return this.hologramManager; } + + /** + * Returns an instance of the PluginDataManager + * @return insstance of PluginDataManager + */ + public PluginDataManager getPluginDataManager() { + return this.manager; + } } diff --git a/src/main/java/com/burchard36/json/PluginDataManager.java b/src/main/java/com/burchard36/json/PluginDataManager.java index f6e239d..59085f6 100644 --- a/src/main/java/com/burchard36/json/PluginDataManager.java +++ b/src/main/java/com/burchard36/json/PluginDataManager.java @@ -13,7 +13,7 @@ public class PluginDataManager { public PluginDataManager(final JavaPlugin plugin) { this.mapper = new ObjectMapper(); - this.jsonWriter = new PluginJsonWriter(plugin); + this.jsonWriter = new PluginJsonWriter(this.mapper); } /** diff --git a/src/main/java/com/burchard36/json/PluginJsonWriter.java b/src/main/java/com/burchard36/json/PluginJsonWriter.java index e02deb5..439fd7c 100644 --- a/src/main/java/com/burchard36/json/PluginJsonWriter.java +++ b/src/main/java/com/burchard36/json/PluginJsonWriter.java @@ -1,40 +1,21 @@ package com.burchard36.json; -import com.burchard36.Api; -import com.burchard36.ApiLib; import com.burchard36.Logger; import com.fasterxml.jackson.databind.ObjectMapper; -import org.bukkit.Bukkit; -import org.bukkit.plugin.java.JavaPlugin; import java.io.*; -public class PluginJsonWriter { - - private final JavaPlugin plugin; - private ObjectMapper mapper = null; - - public PluginJsonWriter(final JavaPlugin plugin) { - this.plugin = plugin; - final Api apiLib = ApiLib.getLib(plugin); - if (apiLib != null) { - this.mapper = apiLib.getPluginDataManager().getMapper(); - } else Logger.error("API :: ERROR! :: Error when grabbing moshi variables from Api implementing class," + - " as it does not implement Api!"); - } +public record PluginJsonWriter(ObjectMapper mapper) { public File createFile(final JsonDataFile config) { final File file = config.getFile(); if (!file.exists()) { try { + if (!file.getParentFile().exists()) + if (file.getParentFile().mkdirs()) + Logger.log("&aAPI :: Successfully created directories"); + if (file.createNewFile()) this.mapper.writeValue(file, config); - if (!file.getParentFile().exists()) if (file.getParentFile().mkdirs()) { - Bukkit.getLogger().info("API :: Successfully created directories"); - } - - if (file.createNewFile()) { - this.mapper.writeValue(file, config); - } } catch (IOException ex) { ex.printStackTrace(); } @@ -44,9 +25,7 @@ public File createFile(final JsonDataFile config) { public void writeDataToFile(final JsonDataFile config) { File file = config.getFile(); - if (!file.exists()) { - file = this.createFile(config); - } + if (!file.exists()) file = this.createFile(config); try { this.mapper.writeValue(file, config); @@ -67,5 +46,4 @@ public JsonDataFile getDataFromFile(final JsonDataFile config) { return null; } } - }