From 42283117c80f995dc250efcff8998c3ccc8bd699 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 8 Jan 2021 22:17:12 +0000 Subject: [PATCH] Fixed sorting by rarity not showing enchantments sometimes --- .../willfp/ecoenchants/display/EnchantDisplay.java | 1 - .../implementations/RarityAlphabeticSorter.java | 12 +++++++----- .../sorting/implementations/RarityLengthSorter.java | 12 +++++++----- .../implementations/RarityTypeAlphabeticSorter.java | 11 +++++++---- .../implementations/RarityTypeLengthSorter.java | 12 +++++++----- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index 8d16b778..d02cdaff 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -215,7 +215,6 @@ public class EnchantDisplay { forRemoval.add(enchantment); } }); - forRemoval.forEach(enchantment -> { enchantments.remove(enchantment); if (meta instanceof EnchantmentStorageMeta) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java index 3ef67e3d..c45b7258 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityAlphabeticSorter.java @@ -9,17 +9,19 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class RarityAlphabeticSorter implements EnchantmentSorter { @Override public void sortEnchantments(final @NotNull List toSort) { List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { - List rarityEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) - .sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())) - .collect(Collectors.toList()); + List rarityEnchants = new ArrayList<>(); + toSort.forEach(enchantment -> { + if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + rarityEnchants.add(enchantment); + } + }); + rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); sorted.addAll(rarityEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java index e5ad5385..21c256d5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityLengthSorter.java @@ -10,17 +10,19 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; public class RarityLengthSorter implements EnchantmentSorter { @Override public void sortEnchantments(final @NotNull List toSort) { List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { - List rarityEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) - .sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())) - .collect(Collectors.toList()); + List rarityEnchants = new ArrayList<>(); + toSort.forEach(enchantment -> { + if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + rarityEnchants.add(enchantment); + } + }); + rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); sorted.addAll(rarityEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java index 5edd65a9..925ccd6a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeAlphabeticSorter.java @@ -21,10 +21,13 @@ public class RarityTypeAlphabeticSorter implements EnchantmentSorter { .sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())) .collect(Collectors.toList()); EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { - List rarityEnchants = typeEnchants.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) - .sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())) - .collect(Collectors.toList()); + List rarityEnchants = new ArrayList<>(); + typeEnchants.forEach(enchantment -> { + if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + rarityEnchants.add(enchantment); + } + }); + rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); sorted.addAll(rarityEnchants); }); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java index 0b022197..f49a3fce 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/RarityTypeLengthSorter.java @@ -22,11 +22,13 @@ public class RarityTypeLengthSorter implements EnchantmentSorter { .sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())) .collect(Collectors.toList()); EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { - List rarityEnchants = typeEnchants.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) - .sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())) - .collect(Collectors.toList()); - sorted.addAll(rarityEnchants); + List rarityEnchants = new ArrayList<>(); + typeEnchants.forEach(enchantment -> { + if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + rarityEnchants.add(enchantment); + } + }); + rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); }); });