mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-21 08:37:50 +01:00
Language Panel: sorts the languages differently
This commit is contained in:
parent
e5cfab50f7
commit
c68c8d26cb
@ -4,11 +4,7 @@ import java.io.File;
|
|||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.localization.BSBLocale;
|
import us.tastybento.bskyblock.api.localization.BSBLocale;
|
||||||
@ -21,7 +17,7 @@ import us.tastybento.bskyblock.util.FileLister;
|
|||||||
public class LocalesManager {
|
public class LocalesManager {
|
||||||
|
|
||||||
private BSkyBlock plugin;
|
private BSkyBlock plugin;
|
||||||
private HashMap<Locale, BSBLocale> languages = new HashMap<>();
|
private Map<Locale, BSBLocale> languages = new HashMap<>();
|
||||||
private static final String LOCALE_FOLDER = "locales";
|
private static final String LOCALE_FOLDER = "locales";
|
||||||
|
|
||||||
public LocalesManager(BSkyBlock plugin) {
|
public LocalesManager(BSkyBlock plugin) {
|
||||||
@ -60,7 +56,6 @@ public class LocalesManager {
|
|||||||
// Files must be 9 chars long
|
// Files must be 9 chars long
|
||||||
FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase().endsWith(".yml") && name.length() == 9;
|
FilenameFilter ymlFilter = (dir, name) -> name.toLowerCase().endsWith(".yml") && name.length() == 9;
|
||||||
|
|
||||||
|
|
||||||
// Run through the files and store the locales
|
// Run through the files and store the locales
|
||||||
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
|
File localeDir = new File(plugin.getDataFolder(), LOCALE_FOLDER + File.separator + parent);
|
||||||
// If the folder does not exist, then make it and fill with the locale files from the jar
|
// If the folder does not exist, then make it and fill with the locale files from the jar
|
||||||
@ -79,7 +74,6 @@ public class LocalesManager {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.logError("Could not copy locale files from jar " + e.getMessage());
|
plugin.logError("Could not copy locale files from jar " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store all the locales available
|
// Store all the locales available
|
||||||
@ -105,8 +99,21 @@ public class LocalesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Locale> getAvailableLocales() {
|
public List<Locale> getAvailableLocales(boolean sort) {
|
||||||
return languages.keySet();
|
if (sort) {
|
||||||
|
List<Locale> locales = new LinkedList<>(languages.keySet());
|
||||||
|
|
||||||
|
locales.sort((locale1, locale2) -> {
|
||||||
|
if (locale1.toLanguageTag().equals(plugin.getSettings().getDefaultLanguage())) return -2;
|
||||||
|
else if (locale1.toLanguageTag().startsWith("en")) return -1;
|
||||||
|
else if (locale1.toLanguageTag().equals(locale2.toLanguageTag())) return 0;
|
||||||
|
else return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return locales;
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>(languages.keySet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Locale, BSBLocale> getLanguages() {
|
public Map<Locale, BSBLocale> getLanguages() {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package us.tastybento.bskyblock.panels;
|
package us.tastybento.bskyblock.panels;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import us.tastybento.bskyblock.BSkyBlock;
|
import us.tastybento.bskyblock.BSkyBlock;
|
||||||
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
||||||
@ -22,7 +24,7 @@ public class LanguagePanel {
|
|||||||
PanelBuilder panelBuilder = new PanelBuilder()
|
PanelBuilder panelBuilder = new PanelBuilder()
|
||||||
.name(user.getTranslation("language.panel-title"));
|
.name(user.getTranslation("language.panel-title"));
|
||||||
|
|
||||||
for (Locale locale : BSkyBlock.getInstance().getLocalesManager().getAvailableLocales()) {
|
for (Locale locale : BSkyBlock.getInstance().getLocalesManager().getAvailableLocales(true)) {
|
||||||
PanelItemBuilder localeIcon = new PanelItemBuilder().icon(BSkyBlock.getInstance().getLocalesManager().getLanguages().get(locale).getBanner())
|
PanelItemBuilder localeIcon = new PanelItemBuilder().icon(BSkyBlock.getInstance().getLocalesManager().getLanguages().get(locale).getBanner())
|
||||||
.name(fancyLocaleDisplayName(user, locale))
|
.name(fancyLocaleDisplayName(user, locale))
|
||||||
.clickHandler((panel, u, click, slot) -> {
|
.clickHandler((panel, u, click, slot) -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user