Should fix broken config generation some people have been getting

This commit is contained in:
zml2008 2011-09-28 19:01:46 -07:00 committed by Wizjany
parent 94c794de6f
commit 38c30f5ecd
3 changed files with 17 additions and 6 deletions

View File

@ -102,7 +102,7 @@ public ConfigurationManager(WorldGuardPlugin plugin) {
*/ */
public void load() { public void load() {
// Create the default configuration file // Create the default configuration file
WorldGuardPlugin.createDefaultConfiguration( plugin.createDefaultConfiguration(
new File(plugin.getDataFolder(), "config.yml"), "config.yml"); new File(plugin.getDataFolder(), "config.yml"), "config.yml");
Configuration config = plugin.getConfiguration(); Configuration config = plugin.getConfiguration();

View File

@ -170,8 +170,8 @@ public WorldConfiguration(WorldGuardPlugin plugin, String worldName) {
this.worldName = worldName; this.worldName = worldName;
this.parentConfig = plugin.getConfiguration(); this.parentConfig = plugin.getConfiguration();
WorldGuardPlugin.createDefaultConfiguration(configFile, "config_world.yml"); plugin.createDefaultConfiguration(configFile, "config_world.yml");
WorldGuardPlugin.createDefaultConfiguration(blacklistFile, "blacklist.txt"); plugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");
config = new Configuration(this.configFile); config = new Configuration(this.configFile);
loadConfiguration(); loadConfiguration();

View File

@ -20,6 +20,7 @@
package com.sk89q.worldguard.bukkit; package com.sk89q.worldguard.bukkit;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -27,8 +28,10 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.jar.JarFile;
import java.util.logging.Filter; import java.util.logging.Filter;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -669,7 +672,7 @@ public LocalPlayer wrapPlayer(Player player) {
* @param actual * @param actual
* @param defaultName * @param defaultName
*/ */
public static void createDefaultConfiguration(File actual, public void createDefaultConfiguration(File actual,
String defaultName) { String defaultName) {
// Make parent directories // Make parent directories
@ -682,8 +685,16 @@ public static void createDefaultConfiguration(File actual,
return; return;
} }
InputStream input = WorldGuardPlugin.class InputStream input =
.getResourceAsStream("/defaults/" + defaultName); null;
try {
JarFile file = new JarFile(getFile());
ZipEntry copy = file.getEntry("defaults" + File.separator + defaultName);
if (copy == null) throw new FileNotFoundException();
input = file.getInputStream(copy);
} catch (IOException e) {
logger.severe(getDescription().getName() + ": Unable to read default configuration: " + defaultName);
}
if (input != null) { if (input != null) {
FileOutputStream output = null; FileOutputStream output = null;