diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/Integration.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/Integration.kt new file mode 100644 index 0000000..51d9915 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/Integration.kt @@ -0,0 +1,6 @@ +package com.artillexstudios.axminions.api.integrations + +interface Integration { + + fun register() +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/Integrations.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/Integrations.kt new file mode 100644 index 0000000..42e3a22 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/Integrations.kt @@ -0,0 +1,23 @@ +package com.artillexstudios.axminions.api.integrations + +import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration +import com.artillexstudios.axminions.api.integrations.types.PricesIntegration +import com.artillexstudios.axminions.api.integrations.types.ProtectionIntegrations +import com.artillexstudios.axminions.api.integrations.types.StackerIntegration + +interface Integrations { + + fun getStackerIntegration(): StackerIntegration + + fun getPricesIntegration(): PricesIntegration + + fun getEconomyIntegration(): EconomyIntegration + + fun getProtectionIntegration(): ProtectionIntegrations + + fun reload() + + fun register(integration: Integration) + + fun deregister(integration: Integration) +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/EconomyIntegration.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/EconomyIntegration.kt new file mode 100644 index 0000000..8614d75 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/EconomyIntegration.kt @@ -0,0 +1,13 @@ +package com.artillexstudios.axminions.api.integrations.types + +import com.artillexstudios.axminions.api.integrations.Integration +import org.bukkit.entity.Player + +interface EconomyIntegration : Integration { + + fun getBalance(player: Player): Double + + fun giveBalance(player: Player, amount: Double) + + fun takeBalance(player: Player, amount: Double) +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/PricesIntegration.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/PricesIntegration.kt new file mode 100644 index 0000000..fb17306 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/PricesIntegration.kt @@ -0,0 +1,9 @@ +package com.artillexstudios.axminions.api.integrations.types + +import com.artillexstudios.axminions.api.integrations.Integration +import org.bukkit.inventory.ItemStack + +interface PricesIntegration : Integration { + + fun getPrice(itemStack: ItemStack): Double +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/ProtectionIntegration.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/ProtectionIntegration.kt new file mode 100644 index 0000000..f3463e5 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/ProtectionIntegration.kt @@ -0,0 +1,10 @@ +package com.artillexstudios.axminions.api.integrations.types + +import com.artillexstudios.axminions.api.integrations.Integration +import org.bukkit.Location +import org.bukkit.entity.Player + +interface ProtectionIntegration : Integration { + + fun canBuildAt(player: Player, location: Location): Boolean +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/ProtectionIntegrations.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/ProtectionIntegrations.kt new file mode 100644 index 0000000..779d7f5 --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/ProtectionIntegrations.kt @@ -0,0 +1,11 @@ +package com.artillexstudios.axminions.api.integrations.types + +import org.bukkit.Location +import org.bukkit.entity.Player + +interface ProtectionIntegrations { + + fun getProtectionIntegrations(): List + + fun canBuildAt(player: Player, location: Location): Boolean +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/StackerIntegration.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/StackerIntegration.kt new file mode 100644 index 0000000..9f1742d --- /dev/null +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/StackerIntegration.kt @@ -0,0 +1,16 @@ +package com.artillexstudios.axminions.api.integrations.types + +import com.artillexstudios.axminions.api.integrations.Integration +import org.bukkit.Location +import org.bukkit.entity.Item +import org.bukkit.entity.LivingEntity +import org.bukkit.inventory.ItemStack + +interface StackerIntegration : Integration { + + fun getStackSize(entity: LivingEntity): Long + + fun getStackSize(item: Item): Long + + fun dropItemAt(itemStack: ItemStack, amount: Int, location: Location) +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/Minion.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/Minion.kt index 06c5171..0efa974 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/Minion.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/minions/Minion.kt @@ -97,4 +97,8 @@ interface Minion : InventoryHolder { fun isTicking(): Boolean fun setTicking(ticking: Boolean) + + fun setRange(range: Double) + + fun setNextAction(nextAction: Int) } \ No newline at end of file diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/warnings/Warning.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/warnings/Warning.kt index b4bf4a2..1269685 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/warnings/Warning.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/warnings/Warning.kt @@ -15,9 +15,10 @@ abstract class Warning(private val name: String) { fun display(minion: Minion) { if (minion.getWarning() == null) { val hologram = HologramFactory.get() - .spawnHologram(minion.getLocation().clone().add(0.0, 1.5, 0.0), minion.getLocation().toString()) + .spawnHologram(minion.getLocation().clone().add(0.0, 1.15, 0.0), minion.getLocation().toString()) hologram.addLine(getContent()) minion.setWarning(this) + minion.setWarningHologram(hologram) } } } \ 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 eb740e7..8435c18 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt @@ -34,7 +34,7 @@ class AxMinionsPlugin : AxPlugin() { } init { - val manager = BukkitLibraryManager(this) + val manager = BukkitLibraryManager(this, "../../libraries") val stdLib = Library.builder().groupId("org{}jetbrains{}kotlin").artifactId("kotlin-stdlib").version("1.9.0").relocate("org{}jetbrains{}kotlin", "com{}artillexstudios{}axminions{}libs{}kotlin").build() val h2 = Library.builder().groupId("com{}h2database").artifactId("h2").version("2.2.220").relocate("org{}h2", "com{}artillexstudios{}axminions{}libs{}h2").build() manager.addMavenCentral() diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt new file mode 100644 index 0000000..15106f5 --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt @@ -0,0 +1,60 @@ +package com.artillexstudios.axminions.integrations + +import com.artillexstudios.axminions.api.integrations.types.EconomyIntegration +import com.artillexstudios.axminions.api.integrations.Integration +import com.artillexstudios.axminions.api.integrations.Integrations +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 + +class Integrations : Integrations { + private lateinit var stackerIntegration: StackerIntegration + private lateinit var pricesIntegration: PricesIntegration + private lateinit var economyIntegration: EconomyIntegration + private lateinit var protectionIntegrations: ProtectionIntegrations + + override fun getStackerIntegration(): StackerIntegration { + return stackerIntegration + } + + override fun getPricesIntegration(): PricesIntegration { + return pricesIntegration + } + + override fun getEconomyIntegration(): EconomyIntegration { + return economyIntegration + } + + override fun getProtectionIntegration(): ProtectionIntegrations { + return protectionIntegrations + } + + override fun reload() { + TODO("Not yet implemented") + } + + override fun register(integration: Integration) { + when (integration) { + is StackerIntegration -> { + stackerIntegration = integration + } + + is ProtectionIntegration -> { + // Hook into protection + } + + is EconomyIntegration -> { + economyIntegration = integration + } + + is PricesIntegration -> { + pricesIntegration = integration + } + } + } + + override fun deregister(integration: Integration) { + TODO("Not yet implemented") + } +} \ No newline at end of file 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 5ae1cb8..2613754 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/Minion.kt @@ -11,6 +11,7 @@ import com.artillexstudios.axapi.utils.EquipmentSlot import com.artillexstudios.axapi.utils.ItemBuilder import com.artillexstudios.axapi.utils.RotationType import com.artillexstudios.axapi.utils.StringUtils +import com.artillexstudios.axminions.AxMinionsPlugin import com.artillexstudios.axminions.api.AxMinionsAPI import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.config.Messages @@ -50,8 +51,8 @@ class Minion( private var chestLocationId: Int ) : Minion { private lateinit var entity: PacketArmorStand - internal var nextAction = 0 - internal var range = 0.0 + private var nextAction = 0 + private var range = 0.0 private var dirty = true private var armTick = 2.0 private var warning: Warning? = null @@ -59,7 +60,6 @@ class Minion( private val extraData = hashMapOf() private var linkedInventory: Inventory? = null private val openInventories = mutableListOf() - @Volatile private var ticking = false init { @@ -136,7 +136,8 @@ 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")) { - item = ItemBuilder(tool?.clone() ?: ItemStack(Material.AIR)).get() + println("Setting item! $tool") + item = tool?.clone() ?: ItemStack(Material.AIR) } else { val rotation = Placeholder.unparsed("direction", Messages.ROTATION_NAME(direction)) val linked = Placeholder.unparsed("linked", when (linkedChest) { @@ -213,6 +214,10 @@ class Minion( } else { entity.setItem(EquipmentSlot.MAIN_HAND, tool) } + + AxMinionsPlugin.dataQueue.submit { + AxMinionsPlugin.dataHandler.saveMinion(this) + } } override fun getTool(): ItemStack? { @@ -264,7 +269,7 @@ class Minion( override fun setLinkedChest(location: Location?) { this.linkedChest = location?.clone() - linkedInventory = (linkedChest?.block?.blockData as? Container)?.inventory + linkedInventory = (linkedChest?.block?.state as? Container)?.inventory updateInventories() } @@ -348,6 +353,14 @@ class Minion( this.ticking = ticking } + override fun setRange(range: Double) { + this.range = range + } + + override fun setNextAction(nextAction: Int) { + this.nextAction = nextAction + } + override fun getInventory(): Inventory { return Bukkit.createInventory(this, 9) } diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt index 49c93db..27cc053 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/CollectorMinionType.kt @@ -18,9 +18,9 @@ class CollectorMinionType : MinionType("collector", AxMinionsPlugin.INSTANCE.get override fun onToolDirty(minion: Minion) { val minionImpl = minion as com.artillexstudios.axminions.minions.Minion - minionImpl.range = getDouble("range", minion.getLevel()) + minionImpl.setRange(getDouble("range", minion.getLevel())) val efficiency = 1.0 - (minion.getTool()?.getEnchantmentLevel(Enchantment.DIG_SPEED)?.div(10.0) ?: 0.1) - minionImpl.nextAction = (getLong("speed", minion.getLevel()) * efficiency).roundToInt() + minionImpl.setNextAction((getLong("speed", minion.getLevel()) * efficiency).roundToInt()) } override fun run(minion: Minion) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt index 8b9e9d5..36e5504 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/FarmerMinionType.kt @@ -20,12 +20,13 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour override fun onToolDirty(minion: Minion) { val minionImpl = minion as com.artillexstudios.axminions.minions.Minion - minionImpl.range = getDouble("range", minion.getLevel()) + minionImpl.setRange(getDouble("range", minion.getLevel())) val efficiency = 1.0 - (minion.getTool()?.getEnchantmentLevel(Enchantment.DIG_SPEED)?.div(10.0) ?: 0.1) - minionImpl.nextAction = (getLong("speed", minion.getLevel()) * efficiency).roundToInt() + minionImpl.setNextAction((getLong("speed", minion.getLevel()) * efficiency).roundToInt()) } override fun run(minion: Minion) { + minion.resetAnimation() LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location -> val block = location.block val drops = arrayListOf() diff --git a/libs/AxAPI-1.0-SNAPSHOT.jar b/libs/AxAPI-1.0-SNAPSHOT.jar index 368398c..8fb9c2a 100644 Binary files a/libs/AxAPI-1.0-SNAPSHOT.jar and b/libs/AxAPI-1.0-SNAPSHOT.jar differ