Integrations work, fixes

This commit is contained in:
TomTom 2023-10-12 18:37:08 +02:00
parent 0b5716820e
commit 4e29f59035
17 changed files with 307 additions and 6 deletions

View File

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

View File

@ -0,0 +1,3 @@
package com.artillexstudios.axminions.api.exception
class InvalidIntegrationException(message: String? = null, cause: Throwable? = null) : RuntimeException(message, cause)

View File

@ -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<Runnable>
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() {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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