Added ShopSellEvent as well as integrations for zShop, EconomyShopGUI, and DeluxeSellwands

This commit is contained in:
Auxilor
2022-04-25 10:03:23 +01:00
parent be25f2f4fc
commit fe6b7805c7
10 changed files with 261 additions and 3 deletions

View File

@@ -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;
}
}

View File

@@ -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'

View File

@@ -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)) },

View File

@@ -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"
}
}

View File

@@ -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"
}
}

View File

@@ -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"
}

View File

@@ -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"
}
}

View File

@@ -42,4 +42,7 @@ softdepend:
- MythicMobs
- CustomCrafting
- ExecutableItems
- RPGHorses
- RPGHorses
- EconomyShopGUI
- zShop
- DeluxeSellwands

Binary file not shown.

BIN
lib/zShop.jar Normal file

Binary file not shown.