This commit is contained in:
SeanOMik 2021-08-14 16:43:52 -04:00
parent afb0bfdf1f
commit 2a1e9a6211
No known key found for this signature in database
GPG Key ID: CA09E5BE1F32728A
1 changed files with 43 additions and 0 deletions

View File

@ -18,6 +18,9 @@ import org.bukkit.*;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.util.logging.Level;
public final class TamableFoxes extends JavaPlugin implements Listener {
private static TamableFoxes plugin;
public static final int BSTATS_PLUGIN_ID = 11944;
@ -92,6 +95,46 @@ public final class TamableFoxes extends JavaPlugin implements Listener {
saveConfig();
}
@Override
public void saveResource(String resourcePath, boolean replace) {
if (resourcePath == null || resourcePath.equals("")) {
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
}
resourcePath = resourcePath.replace('\\', '/');
InputStream in = getResource(resourcePath);
if (in == null) {
throw new IllegalArgumentException("The embedded resource '" + resourcePath + "' cannot be found in " + getFile());
}
File outFile = new File(getDataFolder(), resourcePath);
int lastIndex = resourcePath.lastIndexOf('/');
File outDir = new File(getDataFolder(), resourcePath.substring(0, lastIndex >= 0 ? lastIndex : 0));
if (!outDir.exists()) {
outDir.mkdirs();
}
try {
if (!outFile.exists() || replace) {
OutputStream out = new FileOutputStream(outFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
in.close();
}
// Ignore could not save because it already exists.
/* else {
getLogger().log(Level.WARNING, "Could not save " + outFile.getName() + " to " + outFile + " because " + outFile.getName() + " already exists.");
}*/
} catch (IOException ex) {
getLogger().log(Level.SEVERE, "Could not save " + outFile.getName() + " to " + outFile, ex);
}
}
@Override
public void onDisable() {
getServer().getConsoleSender().sendMessage(Config.getPrefix() + ChatColor.YELLOW + LanguageConfig.getSavingFoxMessage());