Improved GUI and command output

This commit is contained in:
Auxilor 2023-05-21 18:38:10 +01:00
parent 4b114aa6d8
commit 0e303a39e8
6 changed files with 24 additions and 48 deletions

View File

@ -2,6 +2,7 @@ package com.willfp.ecoenchants.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.savedDisplayName
import com.willfp.ecoenchants.enchants.wrap
import com.willfp.ecoenchants.rarity.EnchantmentRarities
@ -46,7 +47,7 @@ class CommandEnchant(plugin: EcoPlugin) : PluginCommand(
meta.addEnchant(enchant, level, true)
sender.sendMessage(
plugin.langYml.getMessage("added-enchant")
plugin.langYml.getMessage("added-enchant", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%enchant%", enchant.wrap().displayName)
.replace("%player%", player.savedDisplayName)
)
@ -57,11 +58,13 @@ class CommandEnchant(plugin: EcoPlugin) : PluginCommand(
meta.removeEnchant(enchant)
sender.sendMessage(
plugin.langYml.getMessage("removed-enchant")
plugin.langYml.getMessage("removed-enchant", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%enchant%", enchant.wrap().displayName)
.replace("%player%", player.savedDisplayName)
)
}
item.itemMeta = meta
}
override fun tabComplete(sender: CommandSender, rawArgs: List<String>): List<String> {

View File

@ -5,6 +5,7 @@ import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.core.items.builder.EnchantedBookBuilder
import com.willfp.eco.util.NumberUtils
import com.willfp.eco.util.StringUtils
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.enchants.EcoEnchants
import com.willfp.ecoenchants.enchants.wrap
@ -72,7 +73,7 @@ class CommandGiveRandomBook(plugin: EcoPlugin) : PluginCommand(
.push()
sender.sendMessage(
plugin.langYml.getMessage("gave-random-book")
plugin.langYml.getMessage("gave-random-book", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%player%", player.name)
.replace("%enchantment%", enchantment.wrap().getFormattedName(level))
)

View File

@ -67,7 +67,6 @@ class EnchantDisplay(private val plugin: EcoEnchantsPlugin) : DisplayModule(plug
val shouldDescribe = (plugin.configYml.getBool("display.descriptions.enabled") &&
enchants.size <= plugin.configYml.getInt("display.descriptions.threshold")
&& player?.seesEnchantmentDescriptions ?: true)
|| pdc.has(plugin.namespacedKeyFactory.create("force-describe"), PersistentDataType.INTEGER)
val formattedNames = mutableMapOf<DisplayableEnchant, String>()

View File

@ -21,14 +21,17 @@ import com.willfp.eco.core.items.builder.ItemStackBuilder
import com.willfp.eco.core.items.isEmpty
import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.formatEco
import com.willfp.eco.util.lineWrap
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.display.EnchantSorter.sortForDisplay
import com.willfp.ecoenchants.display.getFormattedDescription
import com.willfp.ecoenchants.display.getFormattedName
import com.willfp.ecoenchants.target.EnchantmentTargets.applicableEnchantments
import org.apache.commons.lang.WordUtils
import org.bukkit.ChatColor
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemFlag
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataType
import kotlin.math.ceil
@ -216,65 +219,36 @@ private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin): Slot {
slot(
EnchantedBookBuilder()
.addStoredEnchantment(enchant, level)
.writeMetaKey(
plugin.namespacedKeyFactory.create("force-describe"),
PersistentDataType.INTEGER,
1
)
.addItemFlag(ItemFlag.HIDE_ENCHANTS)
.setDisplayName(enchant.getFormattedName(level))
.addLoreLines(enchant.getFormattedDescription(level))
.addLoreLines {
// This is horrific and I should refactor it.
val wrappableMap = mutableMapOf<String, String>()
fun String.toWrappable(): String {
val unspaced = this.replace(" ", "{_}")
val uncolored = ChatColor.stripColor(unspaced)!!
wrappableMap[uncolored] = this
return uncolored
}
fun String.replaceInWrappable(): String {
var processed = this
for ((wrappable, original) in wrappableMap) {
processed = processed.replace(wrappable, original)
}
return processed
}
plugin.configYml.getStrings("enchantinfo.item.lore")
.map {
it.replace("%max_level%", enchant.maxLevel.toString())
.replace("%rarity%", enchant.enchantmentRarity.displayName.toWrappable())
.replace("%rarity%", enchant.enchantmentRarity.displayName)
.replace(
"%targets%",
enchant.targets.joinToString(", ") { target -> target.displayName.toWrappable() }
enchant.targets.joinToString(", ") { target -> target.displayName }
)
.replace(
"%conflicts%",
if (enchant.conflictsWithEverything) {
plugin.langYml.getFormattedString("all-conflicts").toWrappable()
plugin.langYml.getFormattedString("all-conflicts")
} else {
enchant.conflicts.joinToString(", ") { conflict ->
conflict.wrap().getFormattedName(0).toWrappable()
}.ifEmpty { plugin.langYml.getFormattedString("no-conflicts").toWrappable() }
conflict.wrap().getFormattedName(0)
}.ifEmpty { plugin.langYml.getFormattedString("no-conflicts") }
}
)
.replace("%tradeable%", this.isTradeable.parseYesOrNo(plugin.langYml))
.replace("%discoverable%", this.isDiscoverable.parseYesOrNo(plugin.langYml))
.replace("%enchantable%", this.isEnchantable.parseYesOrNo(plugin.langYml))
}
.flatMap {
WordUtils.wrap(it, 45, "\n", false)
.lines()
.map { s -> s.replaceInWrappable() }
.mapIndexed { index, s ->
if (index == 0) s
else StringUtils.format(
plugin.configYml.getString("enchantinfo.item.line-wrap-format") + s
)
}
}
.formatEco()
.flatMap {
it.lineWrap(32, true)
}
}
.build()
)
@ -282,5 +256,5 @@ private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin): Slot {
}
fun Boolean.parseYesOrNo(langYml: LangYml): String {
return if (this) langYml.getFormattedString("yes") else langYml.getFormattedString("no")
return if (this) langYml.getFormattedString("yes") else langYml.getFormattedString("no")
}

View File

@ -96,7 +96,6 @@ enchantinfo:
row: 2
column: 5
show-max-level: true # Whether the book should be the max level or level 1
line-wrap-format: "&a" # Color for line wrapping
lore: # The description is automatically appended
- ""
- "&fMax Level: &a%max_level%"

View File

@ -15,8 +15,8 @@ messages:
no-enchantments-found: "&cNo enchantments found!"
invalid-levels: "&cMinimum level can't be higher than maximum level!"
invalid-enchantment: "&cInvalid enchantment!"
added-enchant: "&fAdded &a%enchantment%&f to &a%player%&f's held item!"
removed-enchant: "&fRemoved &a%enchantment%&f from &a%player%&f's held item!"
added-enchant: "&fAdded &a%enchant%&f to &a%player%&f's held item!"
removed-enchant: "&fRemoved &a%enchant%&f from &a%player%&f's held item!"
all: "All"