Skip to content

Commit

Permalink
Reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericenderman committed Aug 4, 2024
1 parent c7e978e commit e037582
Showing 1 changed file with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,52 @@ public void setLanguage(Player player, String language) {
setLanguage(player.getUniqueId(), language);
}

private String getLocale(CommandSender commandSender) {
if (!(commandSender instanceof Player player)) {
return defaultLanguage;
}

Locale playerLocale = player.locale();
String localeDisplayName = playerLocale.getDisplayName();

if (!getLanguages().contains(localeDisplayName)) {
return defaultLanguage;
}

return localeDisplayName;
}

private String getLocale(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
return getLocale(player);
}

private String getLocale(PlayerProfile profile) {
return getLocale(profile.getUuid());
}

private String getProfileLanguage(PlayerProfile profile) {
if (profile == null) {
return null;
}

return profile.getLanguage();
}

private String getProfileLanguage(UUID uuid) {
return getProfileLanguage(plugin.getPlayerDataManager().getPlayerProfile(uuid));
}

private String getProfileLanguage(CommandSender commandSender) {
if (commandSender == null) {
return null;
} else if (commandSender instanceof Player player) {
return getProfileLanguage(player.getUniqueId());
} else {
return defaultLanguage;
}
}

public String getRawMessageString(Message message, String language, boolean fallbackOnDefaultLanguage) {
Map<Message, String> languageMessageMap = languages.get(language);
String miniMessageString = languageMessageMap.get(message);
Expand Down Expand Up @@ -229,52 +275,6 @@ public Component getMessage(Message message, PlayerProfile playerProfile, Object
return getMessage(message, playerProfile, true, arguments);
}

private String getLocale(CommandSender commandSender) {
if (!(commandSender instanceof Player player)) {
return defaultLanguage;
}

Locale playerLocale = player.locale();
String localeDisplayName = playerLocale.getDisplayName();

if (!getLanguages().contains(localeDisplayName)) {
return defaultLanguage;
}

return localeDisplayName;
}

private String getLocale(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
return getLocale(player);
}

private String getLocale(PlayerProfile profile) {
return getLocale(profile.getUuid());
}

private String getProfileLanguage(PlayerProfile profile) {
if (profile == null) {
return null;
}

return profile.getLanguage();
}

private String getProfileLanguage(UUID uuid) {
return getProfileLanguage(plugin.getPlayerDataManager().getPlayerProfile(uuid));
}

private String getProfileLanguage(CommandSender commandSender) {
if (commandSender == null) {
return null;
} else if (commandSender instanceof Player player) {
return getProfileLanguage(player.getUniqueId());
} else {
return defaultLanguage;
}
}

public Component[] toComponents(Object[] ...objects) {
return Stream.of(objects).map((object) -> toComponent(object)).toArray(Component[]::new);
}
Expand Down

0 comments on commit e037582

Please sign in to comment.