diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java index 25a88a8b..48e7005c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/AlphabeticSorter.java @@ -10,7 +10,7 @@ import java.util.List; public class AlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java index 9e01e55d..81372897 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/LengthSorter.java @@ -11,7 +11,7 @@ import java.util.List; public class LengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); } 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 c45b7258..5f91b225 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 @@ -12,15 +12,20 @@ import java.util.List; public class RarityAlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); + EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - toSort.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { 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 21c256d5..600d4071 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 @@ -13,15 +13,19 @@ import java.util.List; public class RarityLengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - toSort.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { 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 925ccd6a..b1097f27 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 @@ -9,24 +9,31 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class RarityTypeAlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); + EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - typeEnchants.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : typeEnchants) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { 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 f49a3fce..ecc7a71e 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 @@ -10,24 +10,32 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; public class RarityTypeLengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + + typeEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); + EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> { List rarityEnchants = new ArrayList<>(); - typeEnchants.forEach(enchantment -> { - if (EnchantmentCache.getEntry(enchantment).getRarity().getName().equals(enchantmentRarity.getName())) { + for (Enchantment enchantment : typeEnchants) { + if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) { rarityEnchants.add(enchantment); } - }); + } rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())); }); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java index e6150d15..f002b8cd 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeAlphabeticSorter.java @@ -9,17 +9,24 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; public class TypeAlphabeticSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + + typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())); sorted.addAll(typeEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java index 5ef087d0..2811a789 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/implementations/TypeLengthSorter.java @@ -8,19 +8,24 @@ import org.bukkit.enchantments.Enchantment; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; -import java.util.stream.Collectors; public class TypeLengthSorter implements EnchantmentSorter { @Override - public void sortEnchantments(final @NotNull List toSort) { + public void sortEnchantments(@NotNull final List toSort) { + if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) { + EnchantDisplay.update(); + } + List sorted = new ArrayList<>(); EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> { - List typeEnchants = toSort.stream() - .filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) - .sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length())) - .collect(Collectors.toList()); + List typeEnchants = new ArrayList<>(); + for (Enchantment enchantment : toSort) { + if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) { + typeEnchants.add(enchantment); + } + } + sorted.addAll(typeEnchants); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java index 7a750305..a7e2de54 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java @@ -5,7 +5,6 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.ItemStack; @@ -97,7 +96,7 @@ public class Soulbound extends EcoEnchant { } @EventHandler(priority = EventPriority.HIGHEST) - public void onDeath(@NotNull final EntityDeathEvent event) { + public void onDeath(@NotNull final PlayerDeathEvent event) { event.getDrops().removeIf(itemStack -> itemStack.getItemMeta().getPersistentDataContainer().has(this.getPlugin().getNamespacedKeyFactory().create("soulbound"), PersistentDataType.INTEGER)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java index f035eaad..8ab2cc4c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashSet; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -119,6 +120,23 @@ public class EnchantmentRarity implements Registerable { return this.customColor != null; } + @Override + public boolean equals(@NotNull final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof EnchantmentRarity)) { + return false; + } + EnchantmentRarity that = (EnchantmentRarity) o; + return Objects.equals(getName(), that.getName()); + } + + @Override + public int hashCode() { + return Objects.hash(getName()); + } + /** * Get EnchantmentRarity matching name. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java index 6679f522..7091fc4d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentType.java @@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.function.Supplier; public class EnchantmentType { @@ -200,6 +201,23 @@ public class EnchantmentType { this.singular = singularSupplier.get(); } + @Override + public boolean equals(@NotNull final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof EnchantmentType)) { + return false; + } + EnchantmentType that = (EnchantmentType) o; + return Objects.equals(getName(), that.getName()); + } + + @Override + public int hashCode() { + return Objects.hash(getName()); + } + /** * Update suppliers of all types. */