Fixed sorting by rarity not showing enchantments sometimes

This commit is contained in:
Auxilor 2021-01-08 22:17:12 +00:00
parent 8595083db5
commit 42283117c8
5 changed files with 28 additions and 20 deletions

View File

@ -215,7 +215,6 @@ public class EnchantDisplay {
forRemoval.add(enchantment);
}
});
forRemoval.forEach(enchantment -> {
enchantments.remove(enchantment);
if (meta instanceof EnchantmentStorageMeta) {

View File

@ -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<Enchantment> toSort) {
List<Enchantment> sorted = new ArrayList<>();
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
List<Enchantment> 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<Enchantment> 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);
});

View File

@ -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<Enchantment> toSort) {
List<Enchantment> sorted = new ArrayList<>();
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
List<Enchantment> rarityEnchants = toSort.stream()
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity))
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
.collect(Collectors.toList());
List<Enchantment> 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);
});

View File

@ -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<Enchantment> 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<Enchantment> 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);
});
});

View File

@ -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<Enchantment> 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<Enchantment> 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()));
});
});