mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-01-27 01:11:21 +01:00
Added configurable type sorting
This commit is contained in:
parent
2fea268ae6
commit
11516ee3b5
@ -1,13 +1,24 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.sorting.*;
|
||||
import com.willfp.ecoenchants.display.options.sorting.AlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.LengthSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.TypeAlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.TypeLengthSorter;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DisplayOptions {
|
||||
private EnchantmentSorter sorter;
|
||||
private final DescriptionOptions descriptionOptions = new DescriptionOptions();
|
||||
private final NumbersOptions numbersOptions = new NumbersOptions();
|
||||
private final ShrinkOptions shrinkOptions = new ShrinkOptions();
|
||||
private final List<EcoEnchant.EnchantmentType> sortedTypes = new ArrayList<>();
|
||||
|
||||
public DisplayOptions() {
|
||||
update();
|
||||
@ -45,6 +56,10 @@ public class DisplayOptions {
|
||||
return shrinkOptions.isEnabled();
|
||||
}
|
||||
|
||||
public List<EcoEnchant.EnchantmentType> getSortedTypes() {
|
||||
return sortedTypes;
|
||||
}
|
||||
|
||||
public EnchantmentSorter getSorter() {
|
||||
return sorter;
|
||||
}
|
||||
@ -54,6 +69,13 @@ public class DisplayOptions {
|
||||
numbersOptions.update();
|
||||
shrinkOptions.update();
|
||||
|
||||
sortedTypes.clear();
|
||||
sortedTypes.addAll(ConfigManager.getConfig().getStrings("lore.type-ordering").stream()
|
||||
.map(typeName -> EcoEnchant.EnchantmentType.values().stream().filter(type -> type.getName().equalsIgnoreCase(typeName)).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
sortedTypes.addAll(EcoEnchant.EnchantmentType.values().stream().filter(enchantmentType -> !sortedTypes.contains(enchantmentType)).collect(Collectors.toList()));
|
||||
|
||||
boolean byType = ConfigManager.getConfig().getBool("lore.sort-by-type");
|
||||
boolean byLength = ConfigManager.getConfig().getBool("lore.sort-by-length");
|
||||
if (byType && byLength) sorter = new TypeLengthSorter();
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -12,7 +12,7 @@ public class TypeAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EcoEnchant.EnchantmentType.getValues().forEach(enchantmentType -> {
|
||||
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()))
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -13,7 +13,7 @@ public class TypeLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EcoEnchant.EnchantmentType.getValues().forEach(enchantmentType -> {
|
||||
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()))
|
||||
|
@ -516,7 +516,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
||||
values.forEach(EnchantmentType::refresh);
|
||||
}
|
||||
|
||||
public static List<EnchantmentType> getValues() {
|
||||
public static List<EnchantmentType> values() {
|
||||
return new ArrayList<>(values);
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public class AnvilMerge {
|
||||
rightEnchants.forEach(((enchantment, integer) -> {
|
||||
AtomicBoolean doesConflict = new AtomicBoolean(false);
|
||||
|
||||
EcoEnchant.EnchantmentType.getValues().forEach(enchantmentType -> {
|
||||
EcoEnchant.EnchantmentType.values().forEach(enchantmentType -> {
|
||||
EcoEnchant enchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
if (enchant == null) return;
|
||||
if (enchant.getType().equals(enchantmentType) && EcoEnchants.hasAnyOfType(left, enchantmentType) && enchantmentType.isSingular())
|
||||
|
@ -27,6 +27,13 @@ lore:
|
||||
sort-by-type: false # Sort enchantments by type
|
||||
sort-by-length: false # Sort enchantments by length. Any combination of this and the above option is valid
|
||||
|
||||
type-ordering: # Only used if sort-by-type is enabled - top to bottom
|
||||
- normal
|
||||
- special
|
||||
- artifact
|
||||
- spell
|
||||
- curse
|
||||
|
||||
describe: # Describe enchantments in lore
|
||||
enabled: false
|
||||
before-lines: 5 # Describe before or equal to number of enchantments
|
||||
|
Loading…
Reference in New Issue
Block a user