Skip to content

Commit

Permalink
Cache currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-van-dijkhuizen committed Jul 1, 2021
1 parent 3bc4899 commit b8ced8a
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package nl.timvandijkhuizen.spigotutils.config.types;

import java.util.Currency;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
Expand All @@ -19,6 +21,10 @@

public class ConfigTypeCurrency implements ConfigType<Currency> {

private static final Set<Currency> CURRENCIES = Currency.getAvailableCurrencies().stream() //
.sorted((a, b) -> a.getDisplayName().compareTo(b.getDisplayName())) //
.collect(Collectors.toSet());

@Override
public Currency getValue(OptionConfig config, ConfigOption<Currency> option) {
try {
Expand Down Expand Up @@ -55,7 +61,7 @@ public void getValueInput(OptionConfig config, ConfigOption<Currency> option, Me
Player player = event.getPlayer();
Currency selected = getValue(config, option);

for (Currency currency : Currency.getAvailableCurrencies()) {
for (Currency currency : CURRENCIES) {
MenuItemBuilder item = new MenuItemBuilder(XMaterial.SUNFLOWER);

item.setName(UI.color(currency.getDisplayName(), UI.COLOR_PRIMARY, ChatColor.BOLD));
Expand Down

0 comments on commit b8ced8a

Please sign in to comment.