Skip to content

Commit

Permalink
Improves ManagerDirector#detachAsset
Browse files Browse the repository at this point in the history
Improves ManagerDirector detach assets methods
  • Loading branch information
anjoismysign committed Sep 21, 2023
1 parent a5ac8f7 commit e038d73
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions src/main/java/us/mytheria/bloblib/managers/ManagerDirector.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.anjoismysign.anjo.logger.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -430,26 +431,31 @@ public BlobPlugin getPlugin() {
* Will detach an embedded file/asset from the plugin jar to
* the corresponding directory
*
* @param fileName The name of the file to detach
* @param fileName The name of the file to detach. Needs to include the extension.
* @param debug Whether to print debug messages
* @param path The path to the directory
* @return The ManagerDirector instance for method chaining
*/
public ManagerDirector detachAsset(String fileName, boolean debug, File path) {
Logger logger = getPlugin().getAnjoLogger();
File file = new File(path + "/" + fileName + ".yml");
File file = new File(path + "/" + fileName);
boolean successful = false;
if (!file.exists()) {
try {
file.createNewFile();
successful = true;
} catch (IOException e) {
if (debug)
logger.debug(" asset " + fileName + ".yml was not detached");
logger.debug(" asset " + fileName + " was not detached");
e.printStackTrace();
return this;
}
}
ResourceUtil.updateYml(path, "/temp" + fileName + ".yml", fileName + ".yml", file, plugin);
boolean successful = MessageManager.loadAndRegisterYamlConfiguration(file, plugin);
String extenstion = FilenameUtils.getExtension(fileName);
if (extenstion.equals("yml")) {
ResourceUtil.updateYml(path, "/temp" + fileName + ".yml", fileName + ".yml", file, plugin);
successful = MessageManager.loadAndRegisterYamlConfiguration(file, plugin);
}
if (debug && successful)
logger.debug(" asset " + fileName + ".yml successfully detached");
return this;
Expand All @@ -464,24 +470,8 @@ public ManagerDirector detachAsset(String fileName, boolean debug, File path) {
* @return The ManagerDirector instance for method chaining
*/
public ManagerDirector detachMessageAsset(String fileName, boolean debug) {
Logger logger = getPlugin().getAnjoLogger();
File path = getRealFileManager().messagesDirectory();
File file = new File(path + "/" + fileName + ".yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
if (debug)
logger.debug(" message asset " + fileName + ".yml was not detached");
e.printStackTrace();
return this;
}
}
ResourceUtil.updateYml(path, "/temp" + fileName + ".yml", fileName + ".yml", file, plugin);
boolean successful = MessageManager.loadAndRegisterYamlConfiguration(file, plugin);
if (debug && successful)
logger.debug(" message asset " + fileName + ".yml successfully detached");
return this;
return detachAsset(fileName + ".yml", debug, path);
}

/**
Expand All @@ -505,24 +495,8 @@ public ManagerDirector detachMessageAsset(String fileName) {
* @return The ManagerDirector instance for method chaining
*/
public ManagerDirector detachSoundAsset(String fileName, boolean debug) {
Logger logger = getPlugin().getAnjoLogger();
File path = getRealFileManager().soundsDirectory();
File file = new File(path + "/" + fileName + ".yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
if (debug)
logger.debug(" sound asset " + fileName + ".yml was not detached");
e.printStackTrace();
return this;
}
}
ResourceUtil.updateYml(path, "/temp" + fileName + ".yml", fileName + ".yml", file, plugin);
SoundManager.loadAndRegisterYamlConfiguration(plugin, file);
if (debug)
logger.debug(" sound asset " + fileName + ".yml successfully detached");
return this;
return detachAsset(fileName + ".yml", debug, path);
}

/**
Expand Down

0 comments on commit e038d73

Please sign in to comment.