Avoids error if locale name is empty

https://github.com/BentoBoxWorld/BentoBox/issues/883
This commit is contained in:
tastybento 2019-08-07 18:28:13 -07:00
parent 0ddae268f7
commit 6dca821d74

View File

@ -2,6 +2,7 @@ package world.bentobox.bentobox.panels;
import java.util.Locale;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -18,7 +19,7 @@ import world.bentobox.bentobox.managers.LocalesManager;
* @author Poslovitch
*/
public class LanguagePanel {
private LanguagePanel() {}
/**
@ -42,14 +43,14 @@ public class LanguagePanel {
} else {
localeIcon.icon(new ItemStack(Material.WHITE_BANNER, 1)); // Set to a blank banner.
}
localeIcon.name(ChatColor.WHITE + fancyLocaleDisplayName(user, locale))
.clickHandler((panel, u, click, slot) -> {
BentoBox.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag());
u.sendMessage("language.edited", "[lang]", fancyLocaleDisplayName(u, locale));
openPanel(u);
return true;
});
String lang = WordUtils.capitalize(locale.getDisplayName(user.getLocale()));
localeIcon.name(ChatColor.WHITE + lang)
.clickHandler((panel, u, click, slot) -> {
BentoBox.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag());
u.sendMessage("language.edited", "[lang]", lang);
openPanel(u);
return true;
});
if (user.getLocale().toLanguageTag().equals(locale.toLanguageTag())) {
localeIcon.description(user.getTranslation("language.description.selected"), "");
@ -68,19 +69,4 @@ public class LanguagePanel {
panelBuilder.build().open(user);
}
/**
* Returns a properly capitalized String based on locale's display name from user's current locale.
* @param user - the User
* @param locale - the Locale to get the display name from
* @return properly capitalized String of the locale's display name in user's current locale
*/
private static String fancyLocaleDisplayName(User user, Locale locale) {
// Get the display name of the locale based on current user's locale
String localeDisplayName = locale.getDisplayName(user.getLocale());
// Set the first letter to an uppercase, to make it nice and fancy :D
localeDisplayName = localeDisplayName.substring(0,1).toUpperCase() + localeDisplayName.substring(1);
return localeDisplayName;
}
}