From 51ee56e54858f2a681def955e6a43eb0e44a3697 Mon Sep 17 00:00:00 2001 From: NicoNekoDev Date: Sat, 15 Jan 2022 19:24:08 +0200 Subject: [PATCH] Create lore prefix and suffix for enchanted items (except books because it looks ugly on them and makes no sense) --- .../ecoenchants/display/EnchantDisplay.java | 8 +++++++ .../display/options/DisplayOptions.java | 22 ++++++++++++++----- .../core-plugin/src/main/resources/config.yml | 4 ++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index e7507ce0..b7d453e5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -12,6 +12,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.util.ItemConversionOptions; import lombok.Getter; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -177,6 +178,13 @@ public class EnchantDisplay extends DisplayModule { } } + if (itemStack.getType() != Material.ENCHANTED_BOOK) { + if (!enchantments.isEmpty()) { + lore.addAll(0, options.getLorePrefix()); + lore.addAll(options.getLoreSuffix()); + } + } + if (this.getOptions().isAboveLore()) { lore.addAll(itemLore); } else { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java index 6d3c8e7f..85501656 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DisplayOptions.java @@ -2,6 +2,8 @@ package com.willfp.ecoenchants.display.options; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.PluginDependent; +import com.willfp.eco.core.display.Display; +import com.willfp.eco.util.StringUtils; import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter; import com.willfp.ecoenchants.display.options.sorting.SortParameters; import com.willfp.ecoenchants.display.options.sorting.SorterManager; @@ -11,11 +13,7 @@ import lombok.Getter; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; public class DisplayOptions extends PluginDependent { @@ -72,6 +70,17 @@ public class DisplayOptions extends PluginDependent { @Getter private boolean aboveLore = true; + /** + * Lore prefix (above enchantments) + */ + @Getter + private List lorePrefix; + /** + * Lore suffix (below enchantments) + */ + @Getter + private List loreSuffix; + /** * Instantiate new display options. * @@ -110,6 +119,9 @@ public class DisplayOptions extends PluginDependent { requireTarget = this.getPlugin().getConfigYml().getBool("lore.require-target"); aboveLore = this.getPlugin().getConfigYml().getBool("lore.above-other-lore"); + lorePrefix = this.getPlugin().getConfigYml().getStrings("lore.prefix").stream().map(s -> Display.PREFIX + StringUtils.format(s, StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)).collect(Collectors.toList()); + loreSuffix = this.getPlugin().getConfigYml().getStrings("lore.suffix").stream().map(s -> Display.PREFIX + StringUtils.format(s, StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)).collect(Collectors.toList()); + boolean byType = this.getPlugin().getConfigYml().getBool("lore.sort-by-type"); boolean byLength = this.getPlugin().getConfigYml().getBool("lore.sort-by-length"); boolean byRarity = this.getPlugin().getConfigYml().getBool("lore.sort-by-rarity"); diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 424aa3aa..41b7a66b 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -72,6 +72,10 @@ lore: after-lines: 9 # Collapse after number of enchantments maximum-per-line: 2 # Maximum number of enchantments to have in 1 line + prefix: # Lines used above the enchantments + - "" + suffix: [] # Lines used below the enchantments + enchanting-table: enabled: true # Enable EcoEnchants through an enchanting table book-times-less-likely: 2 # Times less likely to get an EcoEnchant on a book to balance them out. Don't recommend editing.