Optimize LanguageUtils#getEnchantmentString(...)

This commit is contained in:
Eric 2020-03-01 20:17:29 +01:00
parent 4c843c7b66
commit 8ad730376d

View File

@ -23,6 +23,7 @@ import org.bukkit.potion.PotionType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.StringJoiner;
public class LanguageUtils { public class LanguageUtils {
@ -2417,21 +2418,13 @@ public class LanguageUtils {
*/ */
public static String getEnchantmentString(Map<Enchantment, Integer> enchantmentMap) { public static String getEnchantmentString(Map<Enchantment, Integer> enchantmentMap) {
if (enchantmentMap == null) return null; if (enchantmentMap == null) return null;
Enchantment[] enchantments = enchantmentMap.keySet().toArray(new Enchantment[enchantmentMap.size()]); StringJoiner joiner = new StringJoiner(", ");
StringBuilder enchantmentList = new StringBuilder();
for (int i = 0; i < enchantments.length; i++) { for (Enchantment enchantment : enchantmentMap.keySet()) {
Enchantment enchantment = enchantments[i]; joiner.add(LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment)));
if (i == enchantments.length - 1) {
enchantmentList.append(LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment)));
} else {
enchantmentList.append(LanguageUtils.getEnchantmentName(enchantment, enchantmentMap.get(enchantment)));
enchantmentList.append(", ");
}
} }
return enchantmentList.toString(); return joiner.toString();
} }
/** /**