mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-17 04:41:21 +01:00
Refactored display settings into internal class
This commit is contained in:
parent
31b968088f
commit
1dfee3e71a
@ -41,38 +41,21 @@ public class EnchantDisplay {
|
|||||||
*/
|
*/
|
||||||
public static final NamespacedKey KEY_V = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-v");
|
public static final NamespacedKey KEY_V = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-v");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The prefix for all enchantment lines to have in lore
|
||||||
|
*/
|
||||||
public static final String PREFIX = "§w";
|
public static final String PREFIX = "§w";
|
||||||
|
|
||||||
static String descriptionColor;
|
/**
|
||||||
|
* The configurable options for displaying enchantments
|
||||||
static int numbersThreshold;
|
*/
|
||||||
static boolean useNumerals;
|
public static final DisplayOptions OPTIONS = new DisplayOptions();
|
||||||
|
|
||||||
static int describeThreshold;
|
|
||||||
static boolean useDescribe;
|
|
||||||
|
|
||||||
static int shrinkThreshold;
|
|
||||||
static int shrinkPerLine;
|
|
||||||
static boolean useShrink;
|
|
||||||
static boolean sortByType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update config values
|
* Update config values
|
||||||
*/
|
*/
|
||||||
public static void update() {
|
public static void update() {
|
||||||
descriptionColor = StringUtils.translate(ConfigManager.getLang().getString("description-color"));
|
OPTIONS.update();
|
||||||
|
|
||||||
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
|
|
||||||
numbersThreshold = ConfigManager.getConfig().getInt("lore.use-numbers-above-threshold");
|
|
||||||
|
|
||||||
describeThreshold = ConfigManager.getConfig().getInt("lore.describe.before-lines");
|
|
||||||
useDescribe = ConfigManager.getConfig().getBool("lore.describe.enabled");
|
|
||||||
|
|
||||||
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();
|
EnchantmentCache.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +167,7 @@ public class EnchantDisplay {
|
|||||||
});
|
});
|
||||||
|
|
||||||
HashMap<Enchantment, Integer> tempEnchantments = new HashMap<>(enchantments);
|
HashMap<Enchantment, Integer> tempEnchantments = new HashMap<>(enchantments);
|
||||||
if(sortByType) {
|
if(OPTIONS.isSortByType()) {
|
||||||
List<Enchantment> sorted = new ArrayList<>();
|
List<Enchantment> sorted = new ArrayList<>();
|
||||||
EcoEnchant.EnchantmentType.getValues().forEach(enchantmentType -> {
|
EcoEnchant.EnchantmentType.getValues().forEach(enchantmentType -> {
|
||||||
List<Enchantment> typeEnchants = unsorted.stream()
|
List<Enchantment> typeEnchants = unsorted.stream()
|
||||||
@ -227,7 +210,7 @@ public class EnchantDisplay {
|
|||||||
String name = EnchantmentCache.getEntry(enchantment).getName();
|
String name = EnchantmentCache.getEntry(enchantment).getName();
|
||||||
|
|
||||||
if(!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
if(!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
||||||
if(useNumerals && item.getEnchantmentLevel(enchantment) < numbersThreshold) {
|
if(OPTIONS.isUseNumerals() && item.getEnchantmentLevel(enchantment) < OPTIONS.getNumbersThreshold()) {
|
||||||
name += " " + NumberUtils.toNumeral(level);
|
name += " " + NumberUtils.toNumeral(level);
|
||||||
} else {
|
} else {
|
||||||
name += " " + level;
|
name += " " + level;
|
||||||
@ -235,12 +218,12 @@ public class EnchantDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lore.add(PREFIX + name);
|
lore.add(PREFIX + name);
|
||||||
if(enchantments.size() <= describeThreshold && useDescribe)
|
if(enchantments.size() <= OPTIONS.getDescribeThreshold() && OPTIONS.isUseDescribe())
|
||||||
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
|
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
|
||||||
});
|
});
|
||||||
|
|
||||||
if (useShrink && (enchantments.size() > shrinkThreshold)) {
|
if (OPTIONS.isUseShrink() && (enchantments.size() > OPTIONS.getShrinkThreshold())) {
|
||||||
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, shrinkPerLine);
|
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, OPTIONS.getShrinkPerLine());
|
||||||
List<String> newLore = new ArrayList<>();
|
List<String> newLore = new ArrayList<>();
|
||||||
partitionedCombinedLoreList.forEach((list) -> {
|
partitionedCombinedLoreList.forEach((list) -> {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -266,4 +249,74 @@ public class EnchantDisplay {
|
|||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class DisplayOptions {
|
||||||
|
private String descriptionColor;
|
||||||
|
|
||||||
|
private int numbersThreshold;
|
||||||
|
private boolean useNumerals;
|
||||||
|
|
||||||
|
private int describeThreshold;
|
||||||
|
private boolean useDescribe;
|
||||||
|
|
||||||
|
private int shrinkThreshold;
|
||||||
|
private int shrinkPerLine;
|
||||||
|
private boolean useShrink;
|
||||||
|
private boolean sortByType;
|
||||||
|
|
||||||
|
private DisplayOptions() {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescriptionColor() {
|
||||||
|
return descriptionColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumbersThreshold() {
|
||||||
|
return numbersThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUseNumerals() {
|
||||||
|
return useNumerals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDescribeThreshold() {
|
||||||
|
return describeThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUseDescribe() {
|
||||||
|
return useDescribe;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getShrinkThreshold() {
|
||||||
|
return shrinkThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getShrinkPerLine() {
|
||||||
|
return shrinkPerLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUseShrink() {
|
||||||
|
return useShrink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSortByType() {
|
||||||
|
return sortByType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
descriptionColor = StringUtils.translate(ConfigManager.getLang().getString("description-color"));
|
||||||
|
|
||||||
|
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
|
||||||
|
numbersThreshold = ConfigManager.getConfig().getInt("lore.use-numbers-above-threshold");
|
||||||
|
|
||||||
|
describeThreshold = ConfigManager.getConfig().getInt("lore.describe.before-lines");
|
||||||
|
useDescribe = ConfigManager.getConfig().getBool("lore.describe.enabled");
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public class EnchantmentCache {
|
|||||||
|
|
||||||
String rawName = name;
|
String rawName = name;
|
||||||
name = color + name;
|
name = color + name;
|
||||||
description.replaceAll(line -> EnchantDisplay.PREFIX + EnchantDisplay.descriptionColor + line);
|
description.replaceAll(line -> EnchantDisplay.PREFIX + EnchantDisplay.OPTIONS.getDescriptionColor() + line);
|
||||||
CACHE.add(new CacheEntry(enchantment, name, rawName, description, type));
|
CACHE.add(new CacheEntry(enchantment, name, rawName, description, type));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ public class EnchantmentCache {
|
|||||||
|
|
||||||
String stringDescription = descriptionBuilder.toString();
|
String stringDescription = descriptionBuilder.toString();
|
||||||
stringDescription = stringDescription.replaceAll("§w", "");
|
stringDescription = stringDescription.replaceAll("§w", "");
|
||||||
this.stringDescription = stringDescription.replaceAll(EnchantDisplay.descriptionColor, "");
|
this.stringDescription = stringDescription.replaceAll(EnchantDisplay.OPTIONS.getDescriptionColor(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enchantment getEnchantment() {
|
public Enchantment getEnchantment() {
|
||||||
|
Loading…
Reference in New Issue
Block a user