From 363aee70d57bc14165e6a639ec1a03e49525bdc2 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Mon, 5 May 2014 14:48:25 +0100 Subject: [PATCH] Better handle TL failover. --- .../com/earth2me/essentials/Essentials.java | 4 +- .../src/com/earth2me/essentials/I18n.java | 44 ++++++++++++++++--- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 9a5f95f57..753484300 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -129,11 +129,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials } i18n = new I18n(this); i18n.onEnable(); + i18n.updateLocale("en"); LOGGER.log(Level.INFO, tl("usingTempFolderForTesting")); LOGGER.log(Level.INFO, dataFolder.toString()); this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null); settings = new Settings(this); - i18n.updateLocale("en"); userMap = new UserMap(this); permissionsHandler = new PermissionsHandler(this, false); Economy.setEss(this); @@ -649,7 +649,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials @Override public User getOfflineUser(final String name) { - final User user = userMap.getUser(name); + final User user = userMap.getUser(name); if (user != null && user.getBase() instanceof OfflinePlayer) { //This code should attempt to use the last known name of a user, if Bukkit returns name as null. diff --git a/Essentials/src/com/earth2me/essentials/I18n.java b/Essentials/src/com/earth2me/essentials/I18n.java index 3857c541b..507cd9b02 100644 --- a/Essentials/src/com/earth2me/essentials/I18n.java +++ b/Essentials/src/com/earth2me/essentials/I18n.java @@ -12,6 +12,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; import net.ess3.api.IEssentials; +import org.bukkit.Bukkit; public class I18n implements net.ess3.api.II18n @@ -23,15 +24,27 @@ public class I18n implements net.ess3.api.II18n private transient ResourceBundle customBundle; private transient ResourceBundle localeBundle; private final transient ResourceBundle defaultBundle; - private final transient Map messageFormatCache = new HashMap(); + private transient Map messageFormatCache = new HashMap(); private final transient IEssentials ess; private static final Pattern NODOUBLEMARK = Pattern.compile("''"); + private static final ResourceBundle NULL_BUNDLE = new ResourceBundle() + { + public Enumeration getKeys() + { + return null; + } + + protected Object handleGetObject(String key) + { + return null; + } + }; public I18n(final IEssentials ess) { this.ess = ess; - customBundle = ResourceBundle.getBundle(MESSAGES, defaultLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess)); - localeBundle = ResourceBundle.getBundle(MESSAGES, defaultLocale); + customBundle = NULL_BUNDLE; + localeBundle = NULL_BUNDLE; defaultBundle = ResourceBundle.getBundle(MESSAGES, Locale.ENGLISH); } @@ -128,9 +141,26 @@ public class I18n implements net.ess3.api.II18n currentLocale = new Locale(parts[0], parts[1], parts[2]); } ResourceBundle.clearCache(); + messageFormatCache = new HashMap(); Logger.getLogger("Essentials").log(Level.INFO, String.format("Using locale %s", currentLocale.toString())); - customBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess)); - localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale); + + try + { + localeBundle = ResourceBundle.getBundle(MESSAGES, currentLocale); + } + catch (MissingResourceException ex) + { + localeBundle = NULL_BUNDLE; + } + + try + { + customBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess)); + } + catch (MissingResourceException ex) + { + customBundle = NULL_BUNDLE; + } } public static String capitalCase(final String input) @@ -166,7 +196,7 @@ public class I18n implements net.ess3.api.II18n { } } - return super.getResource(string); + return null; } @Override @@ -183,7 +213,7 @@ public class I18n implements net.ess3.api.II18n { } } - return super.getResourceAsStream(string); + return null; } } }