mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-23 19:57:36 +01:00
Added error detection to sorter implementation
This commit is contained in:
parent
b9a46d5494
commit
7165e9be6e
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
public class AlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
public class LengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
}
|
||||
|
||||
|
@ -12,15 +12,20 @@ import java.util.List;
|
||||
|
||||
public class RarityAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> 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);
|
||||
});
|
||||
|
@ -13,15 +13,19 @@ import java.util.List;
|
||||
|
||||
public class RarityLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final @NotNull List<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> 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);
|
||||
});
|
||||
|
@ -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<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> 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<Enchantment> 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<Enchantment> 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);
|
||||
});
|
||||
|
@ -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<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
List<Enchantment> 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<Enchantment> 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()));
|
||||
});
|
||||
});
|
||||
|
@ -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<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> 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<Enchantment> 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);
|
||||
});
|
||||
|
||||
|
@ -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<Enchantment> toSort) {
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
||||
EnchantDisplay.update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
sorted.addAll(typeEnchants);
|
||||
});
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user