mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-16 04:31:22 +01:00
Added sort-by-type
This commit is contained in:
parent
ce0345c3ae
commit
4c1b5fb497
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* All methods and fields pertaining to showing players the enchantments on their items.
|
||||
@ -69,6 +70,7 @@ public final class EnchantDisplay {
|
||||
static int shrinkThreshold;
|
||||
static int shrinkPerLine;
|
||||
static boolean useShrink;
|
||||
static boolean sortByType;
|
||||
|
||||
/**
|
||||
* Update config values
|
||||
@ -90,6 +92,7 @@ public final class EnchantDisplay {
|
||||
shrinkThreshold = ConfigManager.getConfig().getInt("lore.shrink.after-lines");
|
||||
useShrink = ConfigManager.getConfig().getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
||||
sortByType = ConfigManager.getConfig().getBool("lore.sort-by-type");
|
||||
|
||||
EnchantmentCache.update();
|
||||
}
|
||||
@ -210,7 +213,28 @@ public final class EnchantDisplay {
|
||||
});
|
||||
|
||||
HashMap<Enchantment, Integer> tempEnchantments = new HashMap<>(enchantments);
|
||||
unsorted.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
if(sortByType) {
|
||||
List<Enchantment> normalEnchants = unsorted.stream().filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(EcoEnchant.EnchantmentType.NORMAL)).collect(Collectors.toList());
|
||||
List<Enchantment> specialEnchants = unsorted.stream().filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(EcoEnchant.EnchantmentType.SPECIAL)).collect(Collectors.toList());
|
||||
List<Enchantment> artifactEnchants = unsorted.stream().filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(EcoEnchant.EnchantmentType.ARTIFACT)).collect(Collectors.toList());
|
||||
List<Enchantment> spellEnchants = unsorted.stream().filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(EcoEnchant.EnchantmentType.SPELL)).collect(Collectors.toList());
|
||||
List<Enchantment> curseEnchants = unsorted.stream().filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(EcoEnchant.EnchantmentType.CURSE)).collect(Collectors.toList());
|
||||
|
||||
normalEnchants.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
specialEnchants.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
artifactEnchants.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
spellEnchants.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
curseEnchants.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
|
||||
unsorted.clear();
|
||||
unsorted.addAll(normalEnchants);
|
||||
unsorted.addAll(specialEnchants);
|
||||
unsorted.addAll(artifactEnchants);
|
||||
unsorted.addAll(spellEnchants);
|
||||
unsorted.addAll(curseEnchants);
|
||||
} else {
|
||||
unsorted.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
}
|
||||
|
||||
enchantments.clear();
|
||||
unsorted.forEach(enchantment -> {
|
||||
|
@ -20,7 +20,7 @@ public class EnchantmentCache {
|
||||
|
||||
public static CacheEntry getEntry(Enchantment enchantment) {
|
||||
Optional<CacheEntry> matching = CACHE.stream().filter(entry -> entry.getEnchantment().getKey().getKey().equals(enchantment.getKey().getKey())).findFirst();
|
||||
return matching.orElse(new CacheEntry(enchantment, EnchantDisplay.PREFIX + "§7" + enchantment.getKey().getKey(), enchantment.getKey().getKey(), Collections.singletonList(EnchantDisplay.PREFIX + "No Description Found")));
|
||||
return matching.orElse(new CacheEntry(enchantment, EnchantDisplay.PREFIX + "§7" + enchantment.getKey().getKey(), enchantment.getKey().getKey(), Collections.singletonList(EnchantDisplay.PREFIX + "No Description Found"), EcoEnchant.EnchantmentType.NORMAL));
|
||||
}
|
||||
|
||||
public static Set<CacheEntry> getCache() {
|
||||
@ -83,7 +83,7 @@ public class EnchantmentCache {
|
||||
String rawName = name;
|
||||
name = color + name;
|
||||
description.replaceAll(line -> EnchantDisplay.PREFIX + EnchantDisplay.descriptionColor + line);
|
||||
CACHE.add(new CacheEntry(enchantment, name, rawName, description));
|
||||
CACHE.add(new CacheEntry(enchantment, name, rawName, description, type));
|
||||
});
|
||||
}
|
||||
|
||||
@ -94,12 +94,14 @@ public class EnchantmentCache {
|
||||
private final String rawName;
|
||||
private final List<String> description;
|
||||
private final String stringDescription;
|
||||
private final EcoEnchant.EnchantmentType type;
|
||||
|
||||
public CacheEntry(Enchantment enchantment, String name, String rawName, List<String> description) {
|
||||
public CacheEntry(Enchantment enchantment, String name, String rawName, List<String> description, EcoEnchant.EnchantmentType type) {
|
||||
this.enchantment = enchantment;
|
||||
this.name = name;
|
||||
this.rawName = rawName;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
|
||||
|
||||
StringBuilder descriptionBuilder = new StringBuilder();
|
||||
@ -134,6 +136,10 @@ public class EnchantmentCache {
|
||||
return stringDescription;
|
||||
}
|
||||
|
||||
public EcoEnchant.EnchantmentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CacheEntry{" +
|
||||
|
@ -24,6 +24,7 @@ anvil:
|
||||
lore:
|
||||
use-numerals: true
|
||||
use-numbers-above-threshold: 10 #After level 10, enchantments will display as Name Number, eg: Sharpness 25 instead of Sharpness XXV
|
||||
sort-by-type: false # Sort enchantments by type
|
||||
|
||||
describe: # Describe enchantments in lore
|
||||
enabled: false
|
||||
|
Loading…
Reference in New Issue
Block a user