diff --git a/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java index 2029a45..ae18dff 100644 --- a/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java +++ b/Plugin/src/main/java/net/seanomik/tamablefoxes/TamableFoxes.java @@ -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());