diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java index 0d70bbc3..3e0118fa 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java @@ -1,5 +1,8 @@ package com.willfp.eco.core.integrations.shop; +import com.willfp.eco.core.EcoPlugin; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import java.util.HashSet; @@ -23,6 +26,22 @@ public final class ShopManager { REGISTERED.add(integration); } + /** + * Register the events with eco. + * + * @param plugin Instance of eco. + */ + @ApiStatus.Internal + public static void registerEvents(@NotNull final EcoPlugin plugin) { + for (ShopWrapper wrapper : REGISTERED) { + Listener listener = wrapper.getSellEventAdapter(); + + if (listener != null) { + plugin.getEventManager().registerListener(listener); + } + } + } + /** * Register eco item provider for shop plugins. */ diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopWrapper.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopWrapper.java index 310380e7..9acdb719 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopWrapper.java +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopWrapper.java @@ -1,6 +1,8 @@ package com.willfp.eco.core.integrations.shop; import com.willfp.eco.core.integrations.Integration; +import org.bukkit.event.Listener; +import org.jetbrains.annotations.Nullable; /** * Wrapper class for shop integrations. @@ -9,5 +11,16 @@ public interface ShopWrapper extends Integration { /** * Register eco item provider for shop plugins. */ - void registerEcoProvider(); + default void registerEcoProvider() { + // Do nothing unless overridden. + } + + /** + * Register sell event adapters. + */ + @Nullable + default Listener getSellEventAdapter() { + // Do nothing unless overridden. + return null; + } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt index 6470f2b9..d54e2fe0 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt @@ -193,6 +193,9 @@ abstract class EcoSpigotPlugin : EcoPlugin() { override fun handleEnable() { CollatedRunnable(this) + // Register events for ShopSellEvent + ShopManager.registerEvents(this) + if (!Prerequisite.HAS_PAPER.isMet) { (Eco.getHandler() as EcoHandler).setAdventure(BukkitAudiences.create(this)) } @@ -279,10 +282,10 @@ abstract class EcoSpigotPlugin : EcoPlugin() { IntegrationLoader("MythicMobs") { CustomItemsManager.register(CustomItemsMythicMobs(this)) }, // Shop - IntegrationLoader("ShopGUIPlus") { ShopManager.register(ShopShopGuiPlus(this)) }, - IntegrationLoader("zShop") { ShopManager.register(ShopZShop(this)) }, - IntegrationLoader("DeluxeSellwands") { ShopManager.register(ShopDeluxeSellwands(this)) }, - IntegrationLoader("EconomyShopGUI") { ShopManager.register(ShopEconomyShopGUI(this)) }, + IntegrationLoader("ShopGUIPlus") { ShopManager.register(ShopShopGuiPlus()) }, + IntegrationLoader("zShop") { ShopManager.register(ShopZShop()) }, + IntegrationLoader("DeluxeSellwands") { ShopManager.register(ShopDeluxeSellwands()) }, + IntegrationLoader("EconomyShopGUI") { ShopManager.register(ShopEconomyShopGUI()) }, // Hologram IntegrationLoader("HolographicDisplays") { HologramManager.register(HologramHolographicDisplays(this)) }, diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopDeluxeSellwands.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopDeluxeSellwands.kt index 7ce35b39..222a00ec 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopDeluxeSellwands.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopDeluxeSellwands.kt @@ -1,6 +1,5 @@ package com.willfp.eco.internal.spigot.integrations.shop -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.integrations.shop.ShopSellEvent import com.willfp.eco.core.integrations.shop.ShopWrapper import dev.norska.dsw.api.DeluxeSellwandSellEvent @@ -8,15 +7,9 @@ import org.bukkit.Bukkit import org.bukkit.event.EventHandler import org.bukkit.event.Listener -class ShopDeluxeSellwands( - plugin: EcoPlugin -) : ShopWrapper { - init { - plugin.eventManager.registerListener(DeluxeSellwandsSellEventListeners) - } - - override fun registerEcoProvider() { - // Do nothing. +class ShopDeluxeSellwands : ShopWrapper { + override fun getSellEventAdapter(): Listener { + return DeluxeSellwandsSellEventListeners } object DeluxeSellwandsSellEventListeners : Listener { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopEconomyShopGUI.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopEconomyShopGUI.kt index c56680fb..8fee5a9b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopEconomyShopGUI.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopEconomyShopGUI.kt @@ -1,6 +1,5 @@ package com.willfp.eco.internal.spigot.integrations.shop -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.integrations.shop.ShopSellEvent import com.willfp.eco.core.integrations.shop.ShopWrapper import me.gypopo.economyshopgui.api.events.PreTransactionEvent @@ -8,15 +7,9 @@ import org.bukkit.Bukkit import org.bukkit.event.EventHandler import org.bukkit.event.Listener -class ShopEconomyShopGUI( - plugin: EcoPlugin -) : ShopWrapper { - init { - plugin.eventManager.registerListener(EconomyShopGUISellEventListeners) - } - - override fun registerEcoProvider() { - // Do nothing. +class ShopEconomyShopGUI : ShopWrapper { + override fun getSellEventAdapter(): Listener { + return EconomyShopGUISellEventListeners } object EconomyShopGUISellEventListeners : Listener { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopShopGuiPlus.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopShopGuiPlus.kt index ff76f713..043d5e30 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopShopGuiPlus.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopShopGuiPlus.kt @@ -1,6 +1,5 @@ package com.willfp.eco.internal.spigot.integrations.shop -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.integrations.shop.ShopSellEvent import com.willfp.eco.core.integrations.shop.ShopWrapper import com.willfp.eco.core.items.Items @@ -14,17 +13,15 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.inventory.ItemStack -class ShopShopGuiPlus( - plugin: EcoPlugin -) : ShopWrapper { - init { - plugin.eventManager.registerListener(ShopGuiPlusSellEventListeners) - } - +class ShopShopGuiPlus : ShopWrapper { override fun registerEcoProvider() { ShopGuiPlusApi.registerItemProvider(EcoShopGuiPlusProvider()) } + override fun getSellEventAdapter(): Listener { + return ShopGuiPlusSellEventListeners + } + class EcoShopGuiPlusProvider : ItemProvider("eco") { override fun isValidItem(itemStack: ItemStack?): Boolean { itemStack ?: return false diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopZShop.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopZShop.kt index 4162edb2..8c901bba 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopZShop.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopZShop.kt @@ -1,6 +1,5 @@ package com.willfp.eco.internal.spigot.integrations.shop -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.integrations.shop.ShopSellEvent import com.willfp.eco.core.integrations.shop.ShopWrapper import fr.maxlego08.shop.api.events.ZShopSellEvent @@ -8,15 +7,9 @@ import org.bukkit.Bukkit import org.bukkit.event.EventHandler import org.bukkit.event.Listener -class ShopZShop( - plugin: EcoPlugin -) : ShopWrapper { - init { - plugin.eventManager.registerListener(ZShopSellEventListeners) - } - - override fun registerEcoProvider() { - // Do nothing. +class ShopZShop : ShopWrapper { + override fun getSellEventAdapter(): Listener { + return ZShopSellEventListeners } object ZShopSellEventListeners : Listener {