From 6dfee484a66aa32ba8ba1df84b3b58a2b0060a18 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 3 Oct 2022 23:31:35 +0100 Subject: [PATCH] Fixed a couple bugs --- .../willfp/ecoenchants/enchants/EnchantGUI.kt | 15 +++++++++++--- .../mechanics/EnchantingTableSupport.kt | 20 +++++++++++++++++-- .../src/main/resources/enchants/aura.yml | 2 +- .../enchants/ecoskills/stimulating.yml | 2 +- .../main/resources/enchants/soul_storm.yml | 2 +- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt index 96c22bf6..1fc73b4a 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/EnchantGUI.kt @@ -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()) + } 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>(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 -> diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt index d229ceab..8844b125 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/mechanics/EnchantingTableSupport.kt @@ -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 diff --git a/eco-core/core-plugin/src/main/resources/enchants/aura.yml b/eco-core/core-plugin/src/main/resources/enchants/aura.yml index 7cd70dca..594d33e4 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/aura.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/aura.yml @@ -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" diff --git a/eco-core/core-plugin/src/main/resources/enchants/ecoskills/stimulating.yml b/eco-core/core-plugin/src/main/resources/enchants/ecoskills/stimulating.yml index e1055412..56c29865 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/ecoskills/stimulating.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/ecoskills/stimulating.yml @@ -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%" diff --git a/eco-core/core-plugin/src/main/resources/enchants/soul_storm.yml b/eco-core/core-plugin/src/main/resources/enchants/soul_storm.yml index 5a76f02e..d27fc6c7 100644 --- a/eco-core/core-plugin/src/main/resources/enchants/soul_storm.yml +++ b/eco-core/core-plugin/src/main/resources/enchants/soul_storm.yml @@ -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%"