diff options
Diffstat (limited to 'Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java')
-rw-r--r-- | Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java | 82 |
1 files changed, 59 insertions, 23 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java index 409250a00..9070e25ac 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsUpgrade.java @@ -1,21 +1,11 @@ package com.earth2me.essentials; -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; +import static com.earth2me.essentials.I18n._; +import java.io.*; import java.math.BigInteger; import java.security.DigestInputStream; import java.security.MessageDigest; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Bukkit; @@ -78,7 +68,51 @@ public class EssentialsUpgrade } catch (Throwable e) { - LOGGER.log(Level.SEVERE, Util.i18n("upgradingFilesError"), e); + LOGGER.log(Level.SEVERE, _("upgradingFilesError"), e); + } + } + + private void moveMotdRulesToFile(String name) + { + if (doneFile.getBoolean("move" + name + "ToFile", false)) + { + return; + } + try + { + final File file = new File(ess.getDataFolder(), name + ".txt"); + if (file.exists()) + { + return; + } + final File configFile = new File(ess.getDataFolder(), "config.yml"); + if (!configFile.exists()) + { + return; + } + final EssentialsConf conf = new EssentialsConf(configFile); + conf.load(); + List<String> lines = conf.getStringList(name, null); + if (lines != null && !lines.isEmpty()) + { + if (!file.createNewFile()) + { + throw new IOException("Failed to create file " + file); + } + PrintWriter writer = new PrintWriter(file); + + for (String line : lines) + { + writer.println(line); + } + writer.close(); + } + doneFile.setProperty("move" + name + "ToFile", true); + doneFile.save(); + } + catch (Throwable e) + { + LOGGER.log(Level.SEVERE, _("upgradingFilesError"), e); } } @@ -128,11 +162,11 @@ public class EssentialsUpgrade { if (!file.renameTo(new File(file.getParentFile(), file.getName().concat("." + System.currentTimeMillis() + ".upgradebackup")))) { - throw new Exception(Util.i18n("configFileMoveError")); + throw new Exception(_("configFileMoveError")); } if (!tempFile.renameTo(file)) { - throw new Exception(Util.i18n("configFileRenameError")); + throw new Exception(_("configFileRenameError")); } } else @@ -187,7 +221,7 @@ public class EssentialsUpgrade ((Number)vals.get(3)).floatValue(), ((Number)vals.get(4)).floatValue()); - final String worldName = world.getName().toLowerCase(); + final String worldName = world.getName().toLowerCase(Locale.ENGLISH); if (worldName != null && !worldName.isEmpty()) { config.removeProperty("home"); @@ -314,7 +348,7 @@ public class EssentialsUpgrade { continue; } - worldName = loc.getWorld().getName().toLowerCase(); + worldName = loc.getWorld().getName().toLowerCase(Locale.ENGLISH); if (worldName != null && !worldName.isEmpty()) { config.setProperty("homes." + worldName, loc); @@ -460,7 +494,7 @@ public class EssentialsUpgrade ess.getWarps().setWarp(filename.substring(0, filename.length() - 4), loc); if (!listOfFiles[i].renameTo(new File(warpsFolder, filename + ".old"))) { - throw new Exception(Util.format("fileRenameError", filename)); + throw new Exception(_("fileRenameError", filename)); } } catch (Exception ex) @@ -508,7 +542,7 @@ public class EssentialsUpgrade ess.getWarps().setWarp(name, loc); if (!warpFile.renameTo(new File(ess.getDataFolder(), "warps.txt.old"))) { - throw new Exception(Util.format("fileRenameError", "warps.txt")); + throw new Exception(_("fileRenameError", "warps.txt")); } } } @@ -552,17 +586,17 @@ public class EssentialsUpgrade final File newFile = new File(listOfFiles[i].getParentFile(), sanitizedFilename); if (!listOfFiles[i].renameTo(tmpFile)) { - LOGGER.log(Level.WARNING, Util.format("userdataMoveError", filename, sanitizedFilename)); + LOGGER.log(Level.WARNING, _("userdataMoveError", filename, sanitizedFilename)); continue; } if (newFile.exists()) { - LOGGER.log(Level.WARNING, Util.format("duplicatedUserdata", filename, sanitizedFilename)); + LOGGER.log(Level.WARNING, _("duplicatedUserdata", filename, sanitizedFilename)); continue; } if (!tmpFile.renameTo(newFile)) { - LOGGER.log(Level.WARNING, Util.format("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); + LOGGER.log(Level.WARNING, _("userdataMoveBackError", sanitizedFilename, sanitizedFilename)); } } doneFile.setProperty("sanitizeAllUserFilenames", true); @@ -654,6 +688,8 @@ public class EssentialsUpgrade ess.getDataFolder().mkdirs(); } moveWorthValuesToWorthYml(); + moveMotdRulesToFile("motd"); + moveMotdRulesToFile("rules"); } public void afterSettings() |