mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00:00
Better handle TL failover.
This commit is contained in:
parent
01d03d5d41
commit
363aee70d5
2 changed files with 39 additions and 9 deletions
|
@ -129,11 +129,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
|
||||||
}
|
}
|
||||||
i18n = new I18n(this);
|
i18n = new I18n(this);
|
||||||
i18n.onEnable();
|
i18n.onEnable();
|
||||||
|
i18n.updateLocale("en");
|
||||||
LOGGER.log(Level.INFO, tl("usingTempFolderForTesting"));
|
LOGGER.log(Level.INFO, tl("usingTempFolderForTesting"));
|
||||||
LOGGER.log(Level.INFO, dataFolder.toString());
|
LOGGER.log(Level.INFO, dataFolder.toString());
|
||||||
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
|
this.initialize(null, server, new PluginDescriptionFile(new FileReader(new File("src" + File.separator + "plugin.yml"))), dataFolder, null, null);
|
||||||
settings = new Settings(this);
|
settings = new Settings(this);
|
||||||
i18n.updateLocale("en");
|
|
||||||
userMap = new UserMap(this);
|
userMap = new UserMap(this);
|
||||||
permissionsHandler = new PermissionsHandler(this, false);
|
permissionsHandler = new PermissionsHandler(this, false);
|
||||||
Economy.setEss(this);
|
Economy.setEss(this);
|
||||||
|
@ -649,7 +649,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
|
||||||
@Override
|
@Override
|
||||||
public User getOfflineUser(final String name)
|
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)
|
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.
|
//This code should attempt to use the last known name of a user, if Bukkit returns name as null.
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import net.ess3.api.IEssentials;
|
import net.ess3.api.IEssentials;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
|
||||||
public class I18n implements net.ess3.api.II18n
|
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 customBundle;
|
||||||
private transient ResourceBundle localeBundle;
|
private transient ResourceBundle localeBundle;
|
||||||
private final transient ResourceBundle defaultBundle;
|
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 final transient IEssentials ess;
|
||||||
private static final Pattern NODOUBLEMARK = Pattern.compile("''");
|
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)
|
public I18n(final IEssentials ess)
|
||||||
{
|
{
|
||||||
this.ess = ess;
|
this.ess = ess;
|
||||||
customBundle = ResourceBundle.getBundle(MESSAGES, defaultLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess));
|
customBundle = NULL_BUNDLE;
|
||||||
localeBundle = ResourceBundle.getBundle(MESSAGES, defaultLocale);
|
localeBundle = NULL_BUNDLE;
|
||||||
defaultBundle = ResourceBundle.getBundle(MESSAGES, Locale.ENGLISH);
|
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]);
|
currentLocale = new Locale(parts[0], parts[1], parts[2]);
|
||||||
}
|
}
|
||||||
ResourceBundle.clearCache();
|
ResourceBundle.clearCache();
|
||||||
|
messageFormatCache = new HashMap<String, MessageFormat>();
|
||||||
Logger.getLogger("Essentials").log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
|
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)
|
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
|
@Override
|
||||||
|
@ -183,7 +213,7 @@ public class I18n implements net.ess3.api.II18n
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.getResourceAsStream(string);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue