Added libreforge integration

This commit is contained in:
Auxilor
2023-09-07 15:24:05 +01:00
parent 1218221f35
commit 40f4311fa8
11 changed files with 168 additions and 9 deletions

View File

@@ -41,12 +41,13 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:6.48.0'
compileOnly 'com.willfp:eco:6.65.4'
implementation 'com.willfp:ecomponent:1.3.0'
compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6'
compileOnly 'org.jetbrains:annotations:23.0.0'
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
compileOnly 'com.willfp:libreforge:4.33.0'
}
tasks.withType(JavaCompile) {

View File

@@ -5,11 +5,13 @@ import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.eco.core.config.ConfigType
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.config.readConfig
import com.willfp.eco.core.integrations.IntegrationLoader
import com.willfp.eco.core.integrations.shop.ShopManager
import com.willfp.ecoshop.commands.CommandEcoShop
import com.willfp.ecoshop.commands.CommandSell
import com.willfp.ecoshop.config.UsermadeConfig
import com.willfp.ecoshop.integration.EcoShopAdapter
import com.willfp.ecoshop.integration.libreforge.LibreforgeIntegration
import com.willfp.ecoshop.shop.Shops
import com.willfp.ecoshop.shop.gui.SellGUI
import org.bukkit.event.Listener
@@ -93,6 +95,12 @@ class EcoShopPlugin : EcoPlugin() {
)
}
override fun loadIntegrationLoaders(): List<IntegrationLoader> {
return listOf(
IntegrationLoader("libreforge") { LibreforgeIntegration.load() }
)
}
override fun getMinimumEcoVersion(): String {
return "6.48.0"
}

View File

@@ -0,0 +1,31 @@
package com.willfp.ecoshop.event
import com.willfp.eco.core.price.Price
import com.willfp.ecoshop.shop.BuyType
import com.willfp.ecoshop.shop.ShopItem
import org.bukkit.entity.Player
import org.bukkit.event.HandlerList
import org.bukkit.event.player.PlayerEvent
class EcoShopBuyEvent(
who: Player,
override val shopItem: ShopItem,
override var price: Price,
val buyType: BuyType
) : PlayerEvent(who), ShopEvent {
// Below here is bukkit boilerplate
override fun getHandlers(): HandlerList {
return HANDLERS
}
companion object {
@JvmStatic
private val HANDLERS: HandlerList = HandlerList()
@JvmStatic
fun getHandlerList(): HandlerList {
return HANDLERS
}
}
}

View File

@@ -9,11 +9,11 @@ import org.bukkit.inventory.ItemStack
class EcoShopSellEvent @JvmOverloads constructor(
who: Player,
val shopItem: ShopItem,
var price: Price,
override val shopItem: ShopItem,
override var price: Price,
val item: ItemStack,
var multiplier: Double = 1.0
) : PlayerEvent(who) {
) : PlayerEvent(who), ShopEvent {
// Below here is bukkit boilerplate
override fun getHandlers(): HandlerList {

View File

@@ -0,0 +1,9 @@
package com.willfp.ecoshop.event
import com.willfp.eco.core.price.Price
import com.willfp.ecoshop.shop.ShopItem
interface ShopEvent {
val shopItem: ShopItem
var price: Price
}

View File

@@ -0,0 +1,20 @@
package com.willfp.ecoshop.integration.libreforge
import com.willfp.eco.core.integrations.Integration
import com.willfp.ecoshop.integration.libreforge.impl.FilterShopItem
import com.willfp.ecoshop.integration.libreforge.impl.TriggerBuyItem
import com.willfp.ecoshop.integration.libreforge.impl.TriggerSellItem
import com.willfp.libreforge.filters.Filters
import com.willfp.libreforge.triggers.Triggers
object LibreforgeIntegration: Integration {
fun load() {
Filters.register(FilterShopItem)
Triggers.register(TriggerBuyItem)
Triggers.register(TriggerSellItem)
}
override fun getPluginName(): String {
return "libreforge"
}
}

View File

@@ -0,0 +1,21 @@
package com.willfp.ecoshop.integration.libreforge.impl
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoshop.event.ShopEvent
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.filters.Filter
import com.willfp.libreforge.triggers.TriggerData
object FilterShopItem : Filter<NoCompileData, Collection<String>>("shop_item") {
override fun getValue(config: Config, data: TriggerData?, key: String): Collection<String> {
return config.getStrings(key)
}
override fun isMet(data: TriggerData, value: Collection<String>, compileData: NoCompileData): Boolean {
val event = data.event as? ShopEvent ?: return true
return value.any { shopItemName ->
shopItemName.equals(event.shopItem.id, ignoreCase = true)
}
}
}

View File

@@ -0,0 +1,30 @@
package com.willfp.ecoshop.integration.libreforge.impl
import com.willfp.ecoshop.event.EcoShopBuyEvent
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
import org.bukkit.event.EventHandler
object TriggerBuyItem : Trigger("buy_item") {
override val parameters = setOf(
TriggerParameter.PLAYER,
TriggerParameter.LOCATION,
TriggerParameter.EVENT
)
@EventHandler(ignoreCancelled = true)
fun handle(event: EcoShopBuyEvent) {
val player = event.player
this.dispatch(
player,
TriggerData(
player = player,
location = player.location,
event = event,
value = event.price.getValue(player)
)
)
}
}

View File

@@ -0,0 +1,30 @@
package com.willfp.ecoshop.integration.libreforge.impl
import com.willfp.ecoshop.event.EcoShopSellEvent
import com.willfp.libreforge.triggers.Trigger
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
import org.bukkit.event.EventHandler
object TriggerSellItem : Trigger("sell_item") {
override val parameters = setOf(
TriggerParameter.PLAYER,
TriggerParameter.LOCATION,
TriggerParameter.EVENT
)
@EventHandler(ignoreCancelled = true)
fun handle(event: EcoShopSellEvent) {
val player = event.player
this.dispatch(
player,
TriggerData(
player = player,
location = player.location,
event = event,
value = event.price.getValue(player)
)
)
}
}

View File

@@ -16,6 +16,7 @@ import com.willfp.eco.core.price.CombinedDisplayPrice
import com.willfp.eco.core.price.ConfiguredPrice
import com.willfp.eco.util.formatEco
import com.willfp.ecoshop.EcoShopPlugin
import com.willfp.ecoshop.event.EcoShopBuyEvent
import com.willfp.ecoshop.event.EcoShopSellEvent
import com.willfp.ecoshop.shop.gui.BuyMenu
import com.willfp.ecoshop.shop.gui.SellMenu
@@ -252,10 +253,15 @@ class ShopItem(
) {
require(amount in 1..getMaxBuysAtOnce(player))
when (buyType) {
BuyType.NORMAL -> buyPrice?.pay(player, amount.toDouble())
BuyType.ALT -> altBuyPrice?.pay(player, amount.toDouble())
}
val basePrice = when (buyType) {
BuyType.NORMAL -> buyPrice
BuyType.ALT -> altBuyPrice
}!!
val event = EcoShopBuyEvent(player, this, basePrice.price, buyType)
Bukkit.getPluginManager().callEvent(event)
event.price.pay(player, amount.toDouble())
if (item != null) {
val queue = DropQueue(player)
@@ -275,6 +281,7 @@ class ShopItem(
.replace("%amount%", amount.toString())
)
}
if (buyItemMessage != null) {
for (message in buyItemMessage) {
player.sendMessage(
@@ -376,6 +383,7 @@ class ShopItem(
)
}
}
if (sellItemMessage != null) {
for (message in sellItemMessage) {
player.sendMessage(
@@ -387,7 +395,7 @@ class ShopItem(
}
return amountSold
}
}
fun getAmountInPlayerInventory(player: Player): Int {
if (item == null) {

View File

@@ -13,6 +13,7 @@ softdepend:
- StatTrackers
- EcoItems
- Reforges
- libreforge
commands:
ecoshop: