Fixed a couple bugs

This commit is contained in:
Auxilor 2022-10-03 23:31:35 +01:00
parent 7180da57df
commit 6dfee484a6
5 changed files with 33 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import com.willfp.eco.core.gui.GUIComponent
import com.willfp.eco.core.gui.menu
import com.willfp.eco.core.gui.menu.Menu
import com.willfp.eco.core.gui.menu.MenuLayer
import com.willfp.eco.core.gui.page.Page
import com.willfp.eco.core.gui.page.PageChanger
import com.willfp.eco.core.gui.slot
import com.willfp.eco.core.gui.slot.ConfigSlot
@ -74,9 +75,15 @@ object EnchantGUI {
val atCaptive = menu.getCaptiveItem(player, captiveRow, captiveColumn)
if (atCaptive.isEmpty || atCaptive == null) {
menu.addState(player, "enchants", emptyList<EcoEnchant>())
} else if (atCaptive.type == Material.BOOK) {
menu.addState(player, "enchants", EcoEnchants.values().sortForDisplay())
} else {
menu.addState(player, "enchants", atCaptive.applicableEnchantments.sortForDisplay())
}
if (menu.getPage(player) > menu.getMaxPage(player)) {
menu.addState(player, Page.PAGE_KEY, 1)
}
}
val pane = EnchantmentScrollPane(plugin)
@ -105,11 +112,13 @@ object EnchantGUI {
val enchants = menu.getState<List<EcoEnchant>>(player, "enchants") ?: emptyList()
val total = enchants.size
val perPage = pane.size
if (total == 0) {
1
val pages = if (total == 0) {
0
} else {
ceil(total.toDouble() / perPage).toInt()
}
pages
}
onClose { event, menu ->
@ -229,7 +238,7 @@ private fun EcoEnchant.getInformationSlot(plugin: EcoEnchantsPlugin): Slot {
)
}
.flatMap {
WordUtils.wrap(it, 40, "\n", false)
WordUtils.wrap(it, 60, "\n", false)
.lines()
.map { s -> s.replace("{_}", " ") }
.mapIndexed { index, s ->

View File

@ -18,7 +18,8 @@ import org.bukkit.event.Listener
import org.bukkit.event.enchantment.EnchantItemEvent
import org.bukkit.event.enchantment.PrepareItemEnchantEvent
import org.bukkit.event.player.PlayerQuitEvent
import java.util.*
import org.bukkit.inventory.meta.EnchantmentStorageMeta
import java.util.UUID
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.min
@ -35,7 +36,7 @@ class EnchantingTableSupport(
@EventHandler
fun onEnchant(event: EnchantItemEvent) {
val player = event.enchanter
val item = event.item
val item = event.item.clone()
val cost = event.expLevelCost
val toAdd = event.enchantsToAdd
@ -138,6 +139,21 @@ class EnchantingTableSupport(
ExtraItemSupport.currentlyEnchantingExtraItem[player.uniqueId]!![event.whichButton()]
ExtraItemSupport.currentlyEnchantingExtraItem.remove(player.uniqueId)
}
// I remember writing this back in 8.x.x and deleting it during the recode
// It's here because books don't work with this event, for some reason
if (item.type == Material.ENCHANTED_BOOK) {
plugin.scheduler.run {
if (!event.isCancelled) {
val postEnchantItem = event.inventory.getItem(0)
val meta = postEnchantItem?.itemMeta as? EnchantmentStorageMeta
for ((enchant, level) in event.enchantsToAdd) {
meta?.addStoredEnchant(enchant, level, true)
}
postEnchantItem?.itemMeta = meta
}
}
}
}
@EventHandler

View File

@ -1,5 +1,5 @@
display-name: "Aura"
description: "Players within &a%blocks%%&r blocks of you take &a%reduction%%&r less damage"
description: "Players within &a%radius%&r blocks of you take &a%reduction%%&r less damage"
placeholders:
reduction: "%level% * 10"
radius: "3 + %level% * 2"

View File

@ -1,5 +1,5 @@
display-name: "Stimulating"
description: "Gives a &a%bonus%%&r bonus to all stats for &a%seconds%%&r seconds"
description: "Gives a &a%bonus%%&r bonus to all stats for &a%seconds%&r seconds"
placeholders:
bonus: "10 * %level%"
seconds: "3 * %level%"

View File

@ -1,5 +1,5 @@
display-name: "Soul Storm"
description: "Gives a &a%bonus%% bonus&r to attack damage for &a%seconds%&r seconds at the expense of &a3&r hearts"
description: "Gives a &a%bonus%%&r bonus to attack damage for &a%seconds%&r seconds at the expense of &a3&r hearts"
placeholders:
bonus: "150 + 50 * %level%"
seconds: "15 + 5 * %level%"