Better handle TL failover.

This commit is contained in:
KHobbits 2014-05-05 14:48:25 +01:00
parent 01d03d5d41
commit 363aee70d5
2 changed files with 39 additions and 9 deletions

View file

@ -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.

View file

@ -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<String, MessageFormat> messageFormatCache = new HashMap<String, MessageFormat>();
private transient Map<String, MessageFormat> messageFormatCache = new HashMap<String, MessageFormat>();
private final transient IEssentials ess;
private static final Pattern NODOUBLEMARK = Pattern.compile("''");
private static final ResourceBundle NULL_BUNDLE = new ResourceBundle()
{
public Enumeration<String> 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<String, MessageFormat>();
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;
}
}
}