Further improve lang file saving

This commit is contained in:
HappyPikachu 2018-01-15 19:50:16 -05:00
parent 8b7ee565b9
commit 861eb41852
2 changed files with 12 additions and 6 deletions

View File

@ -3,7 +3,7 @@
<groupId>me.blackvein.quests</groupId>
<artifactId>quests</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
<name>quests</name>
<url>https://github.com/FlyingPikachu/Quests/</url>
<packaging>jar</packaging>

View File

@ -228,6 +228,13 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
/**
* Save a Quests plugin resource to a specific path in the filesystem
*
* @param resourcePath jar file location starting from resource folder, i.e. "lang/el-GR/strings.yml"
* @param outputPath file destination starting from Quests folder, i.e. "lang/el-GR/strings.yml"
* @param replace whether or not to replace the destination file
*/
public void saveResourceAs(String resourcePath, String outputPath, boolean replace) {
if (resourcePath == null || resourcePath.equals("")) {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
@ -238,12 +245,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (in == null) {
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in Quests jar");
}
String outPath = outputPath.replaceAll("/", File.separator);
String outPath = outputPath.replace('/', File.separatorChar).replace('\\', File.separatorChar);
File outFile = new File(getDataFolder(), outPath);
int lastIndex = resourcePath.lastIndexOf(File.separator);
File outDir = new File(getDataFolder(), outPath.substring(0, lastIndex >= 0 ? lastIndex : 0));
File outDir = new File(outFile.getPath().replace(outFile.getName(), ""));
if (!outDir.exists()) {
outDir.mkdirs();
}