diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPI.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPI.kt index 13fc07f..02bee99 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPI.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPI.kt @@ -4,6 +4,7 @@ import com.artillexstudios.axapi.AxPlugin import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.config.Messages import com.artillexstudios.axminions.api.data.DataHandler +import com.artillexstudios.axminions.api.integrations.Integrations import com.artillexstudios.axminions.api.minions.Minion import org.bukkit.entity.Player import java.io.File @@ -24,6 +25,8 @@ interface AxMinionsAPI { fun getMinionLimit(player: Player): Int + fun getIntegrations(): Integrations + companion object { @JvmStatic lateinit var INSTANCE: AxMinionsAPI diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/exception/InvalidIntegrationException.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/exception/InvalidIntegrationException.kt new file mode 100644 index 0000000..69fdeea --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/exception/InvalidIntegrationException.kt @@ -0,0 +1,3 @@ +package com.artillexstudios.axminions.api.exception + +class InvalidIntegrationException(message: String? = null, cause: Throwable? = null) : RuntimeException(message, cause) \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt b/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt index 8435c18..8631c39 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt @@ -14,6 +14,7 @@ import com.artillexstudios.axminions.api.minions.miniontype.MinionType import com.artillexstudios.axminions.api.minions.miniontype.MinionTypes import com.artillexstudios.axminions.commands.AxMinionsCommand import com.artillexstudios.axminions.data.H2DataHandler +import com.artillexstudios.axminions.integrations.Integrations import com.artillexstudios.axminions.listeners.ChunkListener import com.artillexstudios.axminions.listeners.LinkingListener import com.artillexstudios.axminions.listeners.MinionInventoryListener @@ -31,6 +32,7 @@ class AxMinionsPlugin : AxPlugin() { lateinit var config: Config lateinit var dataHandler: DataHandler lateinit var dataQueue: ThreadedQueue + lateinit var integrations: Integrations } init { @@ -45,6 +47,7 @@ class AxMinionsPlugin : AxPlugin() { override fun load() { INSTANCE = this AxMinionsAPI.INSTANCE = AxMinionsAPIImpl(this) + integrations = Integrations() } override fun enable() { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPIImpl.kt b/common/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPIImpl.kt index a651787..5bf5d81 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPIImpl.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/api/AxMinionsAPIImpl.kt @@ -5,6 +5,7 @@ import com.artillexstudios.axminions.AxMinionsPlugin import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.config.Messages import com.artillexstudios.axminions.api.data.DataHandler +import com.artillexstudios.axminions.api.integrations.Integrations import com.artillexstudios.axminions.api.minions.Minion import com.artillexstudios.axminions.minions.Minions import org.bukkit.entity.Player @@ -55,4 +56,8 @@ class AxMinionsAPIImpl(private val plugin: AxMinionsPlugin) : AxMinionsAPI { return limit } + + override fun getIntegrations(): Integrations { + TODO("Not yet implemented") + } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/data/H2DataHandler.kt b/common/src/main/kotlin/com/artillexstudios/axminions/data/H2DataHandler.kt index f286d35..6800795 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/data/H2DataHandler.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/data/H2DataHandler.kt @@ -84,6 +84,8 @@ class H2DataHandler : DataHandler { val actions = resultSet.getLong("actions") val tool = resultSet.getString("tool") + println("direction: $direction, tool: $tool chest location: $chestLocationId") + val location = getLocation(locationId) var chestLocation: Location? = null if (chestLocationId != 0) { @@ -234,7 +236,7 @@ class H2DataHandler : DataHandler { statement.setDouble(7, minion.getStorage()) statement.setLong(8, minion.getActionAmount()) if (minion.getTool() == null || minion.getTool()?.type == Material.AIR) { - statement.setNull(9, Types.CLOB); + statement.setNull(9, Types.CLOB) } else { statement.setString(9, Serializers.ITEM_STACK.serialize(minion.getTool())) } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt index 15106f5..8df2126 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt @@ -1,12 +1,26 @@ package com.artillexstudios.axminions.integrations -import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration +import com.artillexstudios.axapi.utils.StringUtils +import com.artillexstudios.axminions.api.config.Config +import com.artillexstudios.axminions.api.exception.InvalidIntegrationException import com.artillexstudios.axminions.api.integrations.Integration import com.artillexstudios.axminions.api.integrations.Integrations +import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration import com.artillexstudios.axminions.api.integrations.types.PricesIntegration import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegration import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegrations import com.artillexstudios.axminions.api.integrations.types.StackerIntegration +import com.artillexstudios.axminions.integrations.economy.PlayerPointsIntegration +import com.artillexstudios.axminions.integrations.economy.VaultIntegration +import com.artillexstudios.axminions.integrations.prices.CMIIntegration +import com.artillexstudios.axminions.integrations.prices.EconomyShopGUIIntegration +import com.artillexstudios.axminions.integrations.prices.EssentialsIntegration +import com.artillexstudios.axminions.integrations.prices.ShopGUIPlusIntegration +import com.artillexstudios.axminions.integrations.stacker.DefaultStackerIntegration +import com.artillexstudios.axminions.integrations.stacker.RoseStackerIntegration +import com.artillexstudios.axminions.integrations.stacker.WildStackerIntegration +import java.util.Locale +import org.bukkit.Bukkit class Integrations : Integrations { private lateinit var stackerIntegration: StackerIntegration @@ -31,7 +45,69 @@ class Integrations : Integrations { } override fun reload() { - TODO("Not yet implemented") + when (Config.STACKER_HOOK().lowercase(Locale.ENGLISH)) { + "rosestacker" -> { + if (isPluginLoaded("RoseStacker")) { + register(RoseStackerIntegration()) + } else { + register(DefaultStackerIntegration()) + } + } + + "wildstacker" -> { + if (isPluginLoaded("WildStacker")) { + register(WildStackerIntegration()) + } else { + register(DefaultStackerIntegration()) + } + } + + else -> { + register(DefaultStackerIntegration()) + } + } + + when (Config.PRICES_HOOK().lowercase(Locale.ENGLISH)) { + "shopguiplus", "shopgui+" -> { + if (isPluginLoaded("ShopGuiPlus")) { + register(ShopGUIPlusIntegration()) + } + } + + "essentials" -> { + if (isPluginLoaded("Essentials")) { + register(EssentialsIntegration()) + } + } + + "cmi" -> { + if (isPluginLoaded("CMI")) { + register(CMIIntegration()) + } + } + + "economyshopgui" -> { + if (isPluginLoaded("EconomoyShopGUI")) { + register(EconomyShopGUIIntegration()) + } + } + } + + when (Config.ECONOMY_HOOK().lowercase(Locale.ENGLISH)) { + "vault" -> { + if (isPluginLoaded("Vault")) { + register(VaultIntegration()) + } + } + + "playerpoints" -> { + if (isPluginLoaded("PlayerPoints")) { + register(PlayerPointsIntegration()) + } + } + } + + } override fun register(integration: Integration) { @@ -51,6 +127,22 @@ class Integrations : Integrations { is PricesIntegration -> { pricesIntegration = integration } + + else -> { + throw InvalidIntegrationException("There is no builtin integration that the following class extends: ${integration::class.java}") + } + } + } + + private fun isPluginLoaded(pluginName: String): Boolean { + if (Bukkit.getPluginManager().getPlugin(pluginName) != null) { + Bukkit.getConsoleSender() + .sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into $pluginName!")) + return true + } else { + Bukkit.getConsoleSender() + .sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] <#FF0000>$pluginName is set in the config.yml, but it isn't installed! Setting provider to the default one!")) + return false } } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/economy/PlayerPointsIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/economy/PlayerPointsIntegration.kt new file mode 100644 index 0000000..69a8a15 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/economy/PlayerPointsIntegration.kt @@ -0,0 +1,22 @@ +package com.artillexstudios.axminions.integrations.economy + +import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration +import org.bukkit.entity.Player + +class PlayerPointsIntegration : EconomyIntegration { + override fun getBalance(player: Player): Double { + TODO("Not yet implemented") + } + + override fun giveBalance(player: Player, amount: Double) { + TODO("Not yet implemented") + } + + override fun takeBalance(player: Player, amount: Double) { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/economy/VaultIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/economy/VaultIntegration.kt new file mode 100644 index 0000000..af1e308 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/economy/VaultIntegration.kt @@ -0,0 +1,22 @@ +package com.artillexstudios.axminions.integrations.economy + +import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration +import org.bukkit.entity.Player + +class VaultIntegration : EconomyIntegration { + override fun getBalance(player: Player): Double { + TODO("Not yet implemented") + } + + override fun giveBalance(player: Player, amount: Double) { + TODO("Not yet implemented") + } + + override fun takeBalance(player: Player, amount: Double) { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/CMIIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/CMIIntegration.kt new file mode 100644 index 0000000..581ecf7 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/CMIIntegration.kt @@ -0,0 +1,14 @@ +package com.artillexstudios.axminions.integrations.prices + +import com.artillexstudios.axminions.api.integrations.types.PricesIntegration +import org.bukkit.inventory.ItemStack + +class CMIIntegration : PricesIntegration { + override fun getPrice(itemStack: ItemStack): Double { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/EconomyShopGUIIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/EconomyShopGUIIntegration.kt new file mode 100644 index 0000000..7676f94 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/EconomyShopGUIIntegration.kt @@ -0,0 +1,14 @@ +package com.artillexstudios.axminions.integrations.prices + +import com.artillexstudios.axminions.api.integrations.types.PricesIntegration +import org.bukkit.inventory.ItemStack + +class EconomyShopGUIIntegration : PricesIntegration { + override fun getPrice(itemStack: ItemStack): Double { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/EssentialsIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/EssentialsIntegration.kt new file mode 100644 index 0000000..a58f064 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/EssentialsIntegration.kt @@ -0,0 +1,14 @@ +package com.artillexstudios.axminions.integrations.prices + +import com.artillexstudios.axminions.api.integrations.types.PricesIntegration +import org.bukkit.inventory.ItemStack + +class EssentialsIntegration : PricesIntegration { + override fun getPrice(itemStack: ItemStack): Double { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/ShopGUIPlusIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/ShopGUIPlusIntegration.kt new file mode 100644 index 0000000..afdc72b --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/prices/ShopGUIPlusIntegration.kt @@ -0,0 +1,15 @@ +package com.artillexstudios.axminions.integrations.prices + +import com.artillexstudios.axminions.api.integrations.types.PricesIntegration +import org.bukkit.inventory.ItemStack + +class ShopGUIPlusIntegration : PricesIntegration { + + override fun getPrice(itemStack: ItemStack): Double { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/DefaultStackerIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/DefaultStackerIntegration.kt new file mode 100644 index 0000000..93abb9e --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/DefaultStackerIntegration.kt @@ -0,0 +1,27 @@ +package com.artillexstudios.axminions.integrations.stacker + +import com.artillexstudios.axminions.AxMinionsPlugin +import com.artillexstudios.axminions.api.integrations.types.StackerIntegration +import org.bukkit.Location +import org.bukkit.entity.Item +import org.bukkit.entity.LivingEntity +import org.bukkit.inventory.ItemStack + +class DefaultStackerIntegration : StackerIntegration { + + override fun getStackSize(entity: LivingEntity): Long { + return 1 + } + + override fun getStackSize(item: Item): Long { + return item.itemStack.amount.toLong() + } + + override fun dropItemAt(itemStack: ItemStack, amount: Int, location: Location) { + location.world!!.dropItem(location, itemStack) + } + + override fun register() { + AxMinionsPlugin.integrations.register(this) + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/RoseStackerIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/RoseStackerIntegration.kt new file mode 100644 index 0000000..719282c --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/RoseStackerIntegration.kt @@ -0,0 +1,25 @@ +package com.artillexstudios.axminions.integrations.stacker + +import com.artillexstudios.axminions.api.integrations.types.StackerIntegration +import org.bukkit.Location +import org.bukkit.entity.Item +import org.bukkit.entity.LivingEntity +import org.bukkit.inventory.ItemStack + +class RoseStackerIntegration : StackerIntegration { + override fun getStackSize(entity: LivingEntity): Long { + TODO("Not yet implemented") + } + + override fun getStackSize(item: Item): Long { + TODO("Not yet implemented") + } + + override fun dropItemAt(itemStack: ItemStack, amount: Int, location: Location) { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/WildStackerIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/WildStackerIntegration.kt new file mode 100644 index 0000000..8a6fc45 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/stacker/WildStackerIntegration.kt @@ -0,0 +1,26 @@ +package com.artillexstudios.axminions.integrations.stacker + +import com.artillexstudios.axminions.api.integrations.types.StackerIntegration +import org.bukkit.Location +import org.bukkit.entity.Item +import org.bukkit.entity.LivingEntity +import org.bukkit.inventory.ItemStack + +class WildStackerIntegration : StackerIntegration { + + override fun getStackSize(entity: LivingEntity): Long { + TODO("Not yet implemented") + } + + override fun getStackSize(item: Item): Long { + TODO("Not yet implemented") + } + + override fun dropItemAt(itemStack: ItemStack, amount: Int, location: Location) { + TODO("Not yet implemented") + } + + override fun register() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt index 57ad605..f468b75 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/listeners/MinionInventoryListener.kt @@ -55,6 +55,8 @@ class MinionInventoryListener : Listener { event.currentItem!!.amount = 0 } + println("Updatng inventoeroeroere" + + "reruje9rjuaifdjhaierfhjaiofiaefioaehfioa hfiaehjirfoaehio aeifhqeaioufhaeiuofhaiefheaifhieaf") minion.updateInventories() return } @@ -73,6 +75,7 @@ class MinionInventoryListener : Listener { tool.setItemMeta(toolMeta) player.inventory.addItem(tool) + minion.updateInventories() return } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt index 2613754..e0c1e39 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt @@ -108,6 +108,7 @@ class Minion( override fun updateInventories() { openInventories.fastFor { + println(it) updateInventory(it) } } @@ -136,7 +137,6 @@ class Minion( item = ItemBuilder(type.getConfig().getSection("gui.$it"), level, nextLevel, range, nextRange, extra, nextExtra, speed, nextSpeed, price, requiredActions, stored, actions).storePersistentData( MinionTypes.getGuiKey(), PersistentDataType.STRING, it).get() } else if (it.equals("item")) { - println("Setting item! $tool") item = tool?.clone() ?: ItemStack(Material.AIR) } else { val rotation = Placeholder.unparsed("direction", Messages.ROTATION_NAME(direction)) @@ -207,12 +207,13 @@ class Minion( } override fun setTool(tool: ItemStack) { - this.tool = tool + this.tool = tool.clone() + updateInventories() if (tool.type == Material.AIR) { entity.setItem(EquipmentSlot.MAIN_HAND, null) } else { - entity.setItem(EquipmentSlot.MAIN_HAND, tool) + entity.setItem(EquipmentSlot.MAIN_HAND, tool.clone()) } AxMinionsPlugin.dataQueue.submit { @@ -271,6 +272,10 @@ class Minion( this.linkedChest = location?.clone() linkedInventory = (linkedChest?.block?.state as? Container)?.inventory updateInventories() + + AxMinionsPlugin.dataQueue.submit { + AxMinionsPlugin.dataHandler.saveMinion(this) + } } override fun getLinkedChest(): Location? { @@ -281,6 +286,10 @@ class Minion( this.direction = direction location.yaw = direction.yaw entity.teleport(location) + + AxMinionsPlugin.dataQueue.submit { + AxMinionsPlugin.dataHandler.saveMinion(this) + } } override fun getDirection(): Direction { @@ -316,6 +325,8 @@ class Minion( entity.setItem(entry, null) } + setTool(this.tool ?: ItemStack(Material.AIR)) + type.getSection("items.helmet", level)?.let { entity.setItem(EquipmentSlot.HELMET, ItemBuilder(it).get()) }