diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopSellEvent.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopSellEvent.java new file mode 100644 index 00000000..3885e523 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopSellEvent.java @@ -0,0 +1,104 @@ +package com.willfp.eco.core.integrations.shop; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Unified event for shop plugins to fire in order to have sell multipliers. + */ +public class ShopSellEvent extends PlayerEvent { + /** + * The event handler list. + */ + private static final HandlerList HANDLER_LIST = new HandlerList(); + + /** + * The sell price. + */ + private double price; + + /** + * The item to be sold. + */ + @Nullable + private final ItemStack item; + + /** + * Create new shop sell event. + * + * @param who The player. + * @param price The price. + * @param item The item. + */ + public ShopSellEvent(@NotNull final Player who, + final double price, + @Nullable final ItemStack item) { + super(who); + + this.price = price; + this.item = item; + } + + /** + * Get the price. + * + * @return The price. + */ + public double getPrice() { + return this.price; + } + + /** + * Set the price. + * + * @param price The price. + */ + public void setPrice(final double price) { + this.price = price; + } + + /** + * Get the item to be sold. + * + * @return The item. Can be null for some plugins, so check hasKnownItem first! + */ + @Nullable + public ItemStack getItem() { + return item; + } + + /** + * Get if the item is known. Some shop plugins are lacking this in their event, + * so always check this before getItem(), as getItem() may be null. + * + * @return If the item is known. + */ + public boolean hasKnownItem() { + return item != null; + } + + /** + * Bukkit parity. + * + * @return The handlers. + */ + @NotNull + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + /** + * Bukkit parity. + * + * @return The handlers. + */ + @NotNull + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index bb53d93b..b50b6b98 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -44,6 +44,7 @@ dependencies { compileOnly 'com.github.WhipDevelopment:CrashClaim:f9cd7d92eb' compileOnly 'com.wolfyscript.wolfyutilities:wolfyutilities:3.16.0.0' compileOnly 'com.github.decentsoftware-eu:decentholograms:2.1.2' + compileOnly 'com.github.Gypopo:EconomyShopGUI-API:1.1.0' // MythicMobs compileOnly 'io.lumine:Mythic:5.0.1' 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 f9f36603..6470f2b9 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 @@ -105,7 +105,10 @@ import com.willfp.eco.internal.spigot.integrations.hologram.HologramDecentHologr import com.willfp.eco.internal.spigot.integrations.hologram.HologramHolographicDisplays import com.willfp.eco.internal.spigot.integrations.mcmmo.McmmoIntegrationImpl import com.willfp.eco.internal.spigot.integrations.multiverseinventories.MultiverseInventoriesIntegration +import com.willfp.eco.internal.spigot.integrations.shop.ShopDeluxeSellwands +import com.willfp.eco.internal.spigot.integrations.shop.ShopEconomyShopGUI import com.willfp.eco.internal.spigot.integrations.shop.ShopShopGuiPlus +import com.willfp.eco.internal.spigot.integrations.shop.ShopZShop import com.willfp.eco.internal.spigot.math.evaluateExpression import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy import com.willfp.eco.internal.spigot.proxy.SkullProxy @@ -276,7 +279,10 @@ abstract class EcoSpigotPlugin : EcoPlugin() { IntegrationLoader("MythicMobs") { CustomItemsManager.register(CustomItemsMythicMobs(this)) }, // Shop - IntegrationLoader("ShopGUIPlus") { ShopManager.register(ShopShopGuiPlus()) }, + IntegrationLoader("ShopGUIPlus") { ShopManager.register(ShopShopGuiPlus(this)) }, + IntegrationLoader("zShop") { ShopManager.register(ShopZShop(this)) }, + IntegrationLoader("DeluxeSellwands") { ShopManager.register(ShopDeluxeSellwands(this)) }, + IntegrationLoader("EconomyShopGUI") { ShopManager.register(ShopEconomyShopGUI(this)) }, // 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 new file mode 100644 index 00000000..7ce35b39 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopDeluxeSellwands.kt @@ -0,0 +1,38 @@ +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 +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. + } + + object DeluxeSellwandsSellEventListeners : Listener { + @EventHandler + fun shopEventToEcoEvent(event: DeluxeSellwandSellEvent) { + if (event.isCancelled) { + return + } + + val ecoEvent = ShopSellEvent(event.player, event.money, null) + Bukkit.getPluginManager().callEvent(ecoEvent) + event.money = ecoEvent.price + } + } + + override fun getPluginName(): String { + return "DeluxeSellwands" + } +} \ No newline at end of file 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 new file mode 100644 index 00000000..c56680fb --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopEconomyShopGUI.kt @@ -0,0 +1,38 @@ +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 +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. + } + + object EconomyShopGUISellEventListeners : Listener { + @EventHandler + fun shopEventToEcoEvent(event: PreTransactionEvent) { + if (event.isCancelled) { + return + } + + val ecoEvent = ShopSellEvent(event.player, event.price, event.itemStack) + Bukkit.getPluginManager().callEvent(ecoEvent) + event.price = ecoEvent.price + } + } + + override fun getPluginName(): String { + return "EconomyShopGUI" + } +} \ No newline at end of file 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 7887b0b0..ff76f713 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,13 +1,26 @@ 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 import net.brcdev.shopgui.ShopGuiPlusApi +import net.brcdev.shopgui.event.ShopPreTransactionEvent import net.brcdev.shopgui.provider.item.ItemProvider +import net.brcdev.shopgui.shop.ShopManager +import org.bukkit.Bukkit import org.bukkit.configuration.ConfigurationSection +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener import org.bukkit.inventory.ItemStack -class ShopShopGuiPlus : ShopWrapper { +class ShopShopGuiPlus( + plugin: EcoPlugin +) : ShopWrapper { + init { + plugin.eventManager.registerListener(ShopGuiPlusSellEventListeners) + } + override fun registerEcoProvider() { ShopGuiPlusApi.registerItemProvider(EcoShopGuiPlusProvider()) } @@ -29,6 +42,23 @@ class ShopShopGuiPlus : ShopWrapper { } } + object ShopGuiPlusSellEventListeners : Listener { + @EventHandler + fun shopEventToEcoEvent(event: ShopPreTransactionEvent) { + if (event.isCancelled) { + return + } + + if (event.shopAction == ShopManager.ShopAction.BUY) { + return + } + + val ecoEvent = ShopSellEvent(event.player, event.price, event.shopItem.item) + Bukkit.getPluginManager().callEvent(ecoEvent) + event.price = ecoEvent.price + } + } + override fun getPluginName(): String { return "ShopGUIPlus" } 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 new file mode 100644 index 00000000..4162edb2 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/shop/ShopZShop.kt @@ -0,0 +1,38 @@ +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 +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. + } + + object ZShopSellEventListeners : Listener { + @EventHandler + fun shopEventToEcoEvent(event: ZShopSellEvent) { + if (event.isCancelled) { + return + } + + val ecoEvent = ShopSellEvent(event.player, event.price, event.button.itemStack) + Bukkit.getPluginManager().callEvent(ecoEvent) + event.price = ecoEvent.price + } + } + + override fun getPluginName(): String { + return "zShop" + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index b91ee11b..243af535 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -42,4 +42,7 @@ softdepend: - MythicMobs - CustomCrafting - ExecutableItems - - RPGHorses \ No newline at end of file + - RPGHorses + - EconomyShopGUI + - zShop + - DeluxeSellwands \ No newline at end of file diff --git a/lib/DeluxeSellwands Build 22e.jar b/lib/DeluxeSellwands Build 22e.jar new file mode 100644 index 00000000..f290560c Binary files /dev/null and b/lib/DeluxeSellwands Build 22e.jar differ diff --git a/lib/zShop.jar b/lib/zShop.jar new file mode 100644 index 00000000..e9e09399 Binary files /dev/null and b/lib/zShop.jar differ