Merge branch 'master' into master
This commit is contained in:
@@ -40,9 +40,20 @@ import com.willfp.eco.internal.spigot.data.ProfileHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.HandlerType
|
||||
import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler
|
||||
import com.willfp.eco.internal.spigot.math.evaluateExpression
|
||||
import com.willfp.eco.internal.spigot.proxy.*
|
||||
import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.ExtendedPersistentDataContainerFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.MiniMessageTranslatorProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.SkullProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.TPSProxy
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandMap
|
||||
import org.bukkit.configuration.ConfigurationSection
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.entity.Mob
|
||||
@@ -296,5 +307,11 @@ class EcoImpl : EcoSpigotPlugin(), Eco {
|
||||
player.renderedInventory?.menu
|
||||
|
||||
override fun syncCommands() =
|
||||
this.getProxy(SyncCommandsProxy::class.java).syncCommands()
|
||||
this.getProxy(BukkitCommandsProxy::class.java).syncCommands()
|
||||
|
||||
override fun getCommandMap(): CommandMap =
|
||||
this.getProxy(BukkitCommandsProxy::class.java).getCommandMap()
|
||||
|
||||
override fun unregisterCommand(command: PluginCommand) =
|
||||
this.getProxy(BukkitCommandsProxy::class.java).unregisterCommand(command)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,6 @@ import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogX
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCombatLogXV11
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefCrashClaim
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefDeluxeCombat
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFabledSkyBlock
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefFactionsUUID
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefGriefPrevention
|
||||
import com.willfp.eco.internal.spigot.integrations.antigrief.AntigriefIridiumSkyblock
|
||||
@@ -115,6 +114,7 @@ import com.willfp.eco.internal.spigot.integrations.hologram.HologramHolographicD
|
||||
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.placeholder.PlaceholderIntegrationPAPI
|
||||
import com.willfp.eco.internal.spigot.integrations.price.PriceFactoryUltraEconomy
|
||||
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
|
||||
@@ -126,6 +126,7 @@ import com.willfp.eco.internal.spigot.recipes.listeners.ComplexInComplex
|
||||
import com.willfp.eco.internal.spigot.recipes.listeners.ComplexInVanilla
|
||||
import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapedCraftingRecipeStackHandler
|
||||
import com.willfp.eco.internal.spigot.recipes.stackhandlers.ShapelessCraftingRecipeStackHandler
|
||||
import me.TechsCode.UltraEconomy.UltraEconomy
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences
|
||||
import net.milkbowl.vault.economy.Economy
|
||||
import org.bukkit.Bukkit
|
||||
@@ -263,7 +264,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
IntegrationLoader("IridiumSkyblock") { AntigriefManager.register(AntigriefIridiumSkyblock()) },
|
||||
IntegrationLoader("DeluxeCombat") { AntigriefManager.register(AntigriefDeluxeCombat()) },
|
||||
IntegrationLoader("SuperiorSkyblock2") { AntigriefManager.register(AntigriefSuperiorSkyblock2()) },
|
||||
IntegrationLoader("FabledSkyBlock") { AntigriefManager.register(AntigriefFabledSkyBlock()) },
|
||||
IntegrationLoader("BentoBox") { AntigriefManager.register(AntigriefBentoBox()) },
|
||||
IntegrationLoader("WorldGuard") { AntigriefManager.register(AntigriefWorldGuard()) },
|
||||
IntegrationLoader("GriefPrevention") { AntigriefManager.register(AntigriefGriefPrevention()) },
|
||||
@@ -333,6 +333,13 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
}
|
||||
},
|
||||
|
||||
// Price
|
||||
IntegrationLoader("UltraEconomy") {
|
||||
for (currency in UltraEconomy.getAPI().currencies) {
|
||||
Prices.registerPriceFactory(PriceFactoryUltraEconomy(currency))
|
||||
}
|
||||
},
|
||||
|
||||
// Placeholder
|
||||
IntegrationLoader("PlaceholderAPI") { PlaceholderManager.addIntegration(PlaceholderIntegrationPAPI()) },
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.bukkit.event.Listener
|
||||
import org.bukkit.event.inventory.ClickType
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent
|
||||
import org.bukkit.event.inventory.InventoryDragEvent
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent
|
||||
import org.bukkit.inventory.PlayerInventory
|
||||
|
||||
@@ -73,6 +74,33 @@ class GUIListener(private val plugin: EcoPlugin) : Listener {
|
||||
menu.getSlot(row, column, player).handle(player, event, menu)
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.HIGH
|
||||
)
|
||||
fun handleSlotClick(event: InventoryDragEvent) {
|
||||
val rendered = event.view.topInventory.asRenderedInventory() ?: return
|
||||
|
||||
val player = event.whoClicked as? Player ?: return
|
||||
|
||||
val menu = rendered.menu
|
||||
|
||||
val slots = event.inventorySlots
|
||||
|
||||
for (slotID in slots) {
|
||||
val (row, column) = MenuUtils.convertSlotToRowColumn(slotID, menu.columns)
|
||||
|
||||
val slot = menu.getSlot(row, column, player)
|
||||
|
||||
if (slot.isCaptive(player, menu)) {
|
||||
if (!slot.isAllowedCaptive(player, menu, event.oldCursor)) {
|
||||
event.isCancelled = true
|
||||
}
|
||||
} else {
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.HIGH
|
||||
)
|
||||
@@ -95,7 +123,11 @@ class GUIListener(private val plugin: EcoPlugin) : Listener {
|
||||
|
||||
val slot = menu.getSlot(row, column, player)
|
||||
|
||||
if (!slot.isCaptive(player, menu)) {
|
||||
if (slot.isCaptive(player, menu)) {
|
||||
if (!slot.isAllowedCaptive(player, menu, event.currentItem)) {
|
||||
event.isCancelled = true
|
||||
}
|
||||
} else {
|
||||
event.isCancelled = true
|
||||
}
|
||||
}
|
||||
@@ -115,6 +147,12 @@ class GUIListener(private val plugin: EcoPlugin) : Listener {
|
||||
player.renderActiveMenu()
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
fun forceRender(event: InventoryDragEvent) {
|
||||
val player = event.whoClicked as? Player ?: return
|
||||
player.renderActiveMenu()
|
||||
}
|
||||
|
||||
@EventHandler(
|
||||
priority = EventPriority.HIGHEST
|
||||
)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.willfp.eco.internal.spigot.integrations.price
|
||||
|
||||
import com.willfp.eco.core.math.MathContext
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.PriceFactory
|
||||
import com.willfp.eco.util.toSingletonList
|
||||
import me.TechsCode.UltraEconomy.UltraEconomy
|
||||
import me.TechsCode.UltraEconomy.objects.Account
|
||||
import me.TechsCode.UltraEconomy.objects.Currency
|
||||
import org.bukkit.entity.Player
|
||||
import java.util.UUID
|
||||
import java.util.function.Function
|
||||
|
||||
class PriceFactoryUltraEconomy(private val currency: Currency) : PriceFactory {
|
||||
override fun getNames(): List<String> {
|
||||
return currency.name.lowercase().toSingletonList()
|
||||
}
|
||||
|
||||
override fun create(baseContext: MathContext, function: Function<MathContext, Double>): Price {
|
||||
return PriceUltraEconomy(currency, baseContext) { function.apply(it) }
|
||||
}
|
||||
|
||||
private class PriceUltraEconomy(
|
||||
private val currency: Currency,
|
||||
private val baseContext: MathContext,
|
||||
private val function: (MathContext) -> Double
|
||||
) : Price {
|
||||
private val multipliers = mutableMapOf<UUID, Double>()
|
||||
private val api = UltraEconomy.getAPI()
|
||||
|
||||
private val Player.account: Account?
|
||||
get() = api.accounts.uuid(this.uniqueId).orElse(null)
|
||||
|
||||
override fun canAfford(player: Player, multiplier: Double): Boolean {
|
||||
return (player.account?.getBalance(currency)?.onHand ?: 0f) >= getValue(player, multiplier)
|
||||
}
|
||||
|
||||
override fun pay(player: Player, multiplier: Double) {
|
||||
player.account?.getBalance(currency)?.removeHand(getValue(player, multiplier).toFloat())
|
||||
}
|
||||
|
||||
override fun giveTo(player: Player, multiplier: Double) {
|
||||
player.account?.getBalance(currency)?.addHand(getValue(player, multiplier).toFloat())
|
||||
}
|
||||
|
||||
override fun getValue(player: Player, multiplier: Double): Double {
|
||||
return function(MathContext.copyWithPlayer(baseContext, player)) * getMultiplier(player) * multiplier
|
||||
}
|
||||
|
||||
override fun getMultiplier(player: Player): Double {
|
||||
return multipliers[player.uniqueId] ?: 1.0
|
||||
}
|
||||
|
||||
override fun setMultiplier(player: Player, multiplier: Double) {
|
||||
multipliers[player.uniqueId] = multiplier
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.internal.spigot.integrations.shop
|
||||
|
||||
import com.willfp.eco.core.integrations.shop.ShopIntegration
|
||||
import com.willfp.eco.core.integrations.shop.ShopSellEvent
|
||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
||||
import dev.norska.dsw.api.DeluxeSellwandSellEvent
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.EventHandler
|
||||
@@ -19,9 +20,9 @@ class ShopDeluxeSellwands : ShopIntegration {
|
||||
return
|
||||
}
|
||||
|
||||
val ecoEvent = ShopSellEvent(event.player, event.money, null)
|
||||
val ecoEvent = ShopSellEvent(event.player, PriceEconomy(event.money), null)
|
||||
Bukkit.getPluginManager().callEvent(ecoEvent)
|
||||
event.money = ecoEvent.price
|
||||
event.money = ecoEvent.value.getValue(event.player) * ecoEvent.multiplier
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.willfp.eco.internal.spigot.integrations.shop
|
||||
|
||||
import com.willfp.eco.core.integrations.shop.ShopIntegration
|
||||
import com.willfp.eco.core.integrations.shop.ShopSellEvent
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
||||
import me.gypopo.economyshopgui.api.EconomyShopGUIHook
|
||||
import me.gypopo.economyshopgui.api.events.PreTransactionEvent
|
||||
import org.bukkit.Bukkit
|
||||
@@ -15,12 +17,16 @@ class ShopEconomyShopGUI : ShopIntegration {
|
||||
return EconomyShopGUISellEventListeners
|
||||
}
|
||||
|
||||
override fun getPrice(itemStack: ItemStack, player: Player): Double {
|
||||
return EconomyShopGUIHook.getItemSellPrice(player, itemStack)
|
||||
override fun getUnitValue(itemStack: ItemStack, player: Player): Price {
|
||||
return PriceEconomy(
|
||||
EconomyShopGUIHook.getItemSellPrice(player, itemStack.clone().apply {
|
||||
amount = 1
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
override fun getPrice(itemStack: ItemStack): Double {
|
||||
return EconomyShopGUIHook.getItemSellPrice(itemStack)
|
||||
override fun isSellable(itemStack: ItemStack, player: Player): Boolean {
|
||||
return EconomyShopGUIHook.getItemSellPrice(player, itemStack) > 0
|
||||
}
|
||||
|
||||
object EconomyShopGUISellEventListeners : Listener {
|
||||
@@ -30,9 +36,9 @@ class ShopEconomyShopGUI : ShopIntegration {
|
||||
return
|
||||
}
|
||||
|
||||
val ecoEvent = ShopSellEvent(event.player, event.price, event.itemStack)
|
||||
val ecoEvent = ShopSellEvent(event.player, PriceEconomy(event.price), event.itemStack)
|
||||
Bukkit.getPluginManager().callEvent(ecoEvent)
|
||||
event.price = ecoEvent.price
|
||||
event.price = ecoEvent.value.getValue(event.player) * ecoEvent.multiplier
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.willfp.eco.internal.spigot.integrations.shop
|
||||
import com.willfp.eco.core.integrations.shop.ShopIntegration
|
||||
import com.willfp.eco.core.integrations.shop.ShopSellEvent
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
||||
import net.brcdev.shopgui.ShopGuiPlusApi
|
||||
import net.brcdev.shopgui.event.ShopPreTransactionEvent
|
||||
import net.brcdev.shopgui.provider.item.ItemProvider
|
||||
@@ -23,12 +25,16 @@ class ShopShopGuiPlus : ShopIntegration {
|
||||
return ShopGuiPlusSellEventListeners
|
||||
}
|
||||
|
||||
override fun getPrice(itemStack: ItemStack): Double {
|
||||
return ShopGuiPlusApi.getItemStackPriceSell(itemStack)
|
||||
override fun getUnitValue(itemStack: ItemStack, player: Player): Price {
|
||||
return PriceEconomy(
|
||||
ShopGuiPlusApi.getItemStackPriceSell(player, itemStack.clone().apply {
|
||||
amount = 1
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
override fun getPrice(itemStack: ItemStack, player: Player): Double {
|
||||
return ShopGuiPlusApi.getItemStackPriceSell(player, itemStack)
|
||||
override fun isSellable(itemStack: ItemStack, player: Player): Boolean {
|
||||
return ShopGuiPlusApi.getItemStackPriceSell(player, itemStack) > 0
|
||||
}
|
||||
|
||||
class EcoShopGuiPlusProvider : ItemProvider("eco") {
|
||||
@@ -59,9 +65,9 @@ class ShopShopGuiPlus : ShopIntegration {
|
||||
return
|
||||
}
|
||||
|
||||
val ecoEvent = ShopSellEvent(event.player, event.price, event.shopItem.item)
|
||||
val ecoEvent = ShopSellEvent(event.player, PriceEconomy(event.price), event.shopItem.item)
|
||||
Bukkit.getPluginManager().callEvent(ecoEvent)
|
||||
event.price = ecoEvent.price
|
||||
event.price = ecoEvent.value.getValue(event.player) * ecoEvent.multiplier
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.internal.spigot.integrations.shop
|
||||
|
||||
import com.willfp.eco.core.integrations.shop.ShopIntegration
|
||||
import com.willfp.eco.core.integrations.shop.ShopSellEvent
|
||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
||||
import fr.maxlego08.shop.api.events.ZShopSellEvent
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.event.EventHandler
|
||||
@@ -19,13 +20,13 @@ class ShopZShop : ShopIntegration {
|
||||
return
|
||||
}
|
||||
|
||||
val ecoEvent = ShopSellEvent(event.player, event.price, event.button.itemStack)
|
||||
val ecoEvent = ShopSellEvent(event.player, PriceEconomy(event.price), event.button.itemStack)
|
||||
Bukkit.getPluginManager().callEvent(ecoEvent)
|
||||
event.price = ecoEvent.price
|
||||
event.price = ecoEvent.value.getValue(event.player) * ecoEvent.multiplier
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPluginName(): String {
|
||||
return "zShop"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ object ComplexInComplex : RecipeListener {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.inventory.size == 5) {
|
||||
event.deny()
|
||||
return
|
||||
}
|
||||
|
||||
val player = event.inventory.viewers.getOrNull(0) as? Player ?: return
|
||||
|
||||
val matrix = event.inventory.matrix
|
||||
|
||||
Reference in New Issue
Block a user