diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/IslandIntegration.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/IslandIntegration.kt index 11bc3b8..9900227 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/IslandIntegration.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/integrations/types/IslandIntegration.kt @@ -1,9 +1,12 @@ package com.artillexstudios.axminions.api.integrations.types import com.artillexstudios.axminions.api.integrations.Integration +import org.bukkit.block.Block import org.bukkit.entity.Player interface IslandIntegration : Integration { fun getIslandPlaced(player: Player): Int + + fun handleBlockBreak(block: Block) } \ No newline at end of file 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 12e70ad..da87d51 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/Integrations.kt @@ -133,6 +133,7 @@ class Integrations : Integrations { if (Bukkit.getPluginManager().getPlugin("SuperiorSkyblock2") != null) { register(SuperiorSkyBlock2Integration()) + register(com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration()) Bukkit.getConsoleSender() .sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into SuperiorSkyblock2!")) Bukkit.getPluginManager().registerEvents(SuperiorSkyBlock2Listener(), AxMinionsPlugin.INSTANCE) @@ -164,6 +165,7 @@ class Integrations : Integrations { if (Bukkit.getPluginManager().getPlugin("IridiumSkyBlock") != null) { register(IridiumSkyBlockIntegration()) + register(com.artillexstudios.axminions.integrations.island.IridiumSkyBlockIntegration()) Bukkit.getConsoleSender() .sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into IridiumSkyBlock!")) } @@ -199,12 +201,6 @@ class Integrations : Integrations { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { PlaceholderAPIIntegration().register() } - - if (Config.ISLAND_LIMIT() > 0) { - if (Bukkit.getPluginManager().getPlugin("SuperiorSkyBlock2") != null) { - register(com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration()) - } - } } override fun register(integration: Integration) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/island/IridiumSkyBlockIntegration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/island/IridiumSkyBlockIntegration.kt new file mode 100644 index 0000000..332052d --- /dev/null +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/island/IridiumSkyBlockIntegration.kt @@ -0,0 +1,34 @@ +package com.artillexstudios.axminions.integrations.island + +import com.artillexstudios.axminions.api.AxMinionsAPI +import com.artillexstudios.axminions.api.integrations.types.IslandIntegration +import com.artillexstudios.axminions.api.utils.fastFor +import com.iridium.iridiumskyblock.IridiumSkyblock +import com.iridium.iridiumskyblock.api.IridiumSkyblockAPI +import org.bukkit.block.Block +import org.bukkit.entity.Player + +class IridiumSkyBlockIntegration : IslandIntegration { + + override fun getIslandPlaced(player: Player): Int { + val island = IridiumSkyblockAPI.getInstance().getUser(player).island + if (island.isEmpty) { + return 0 + } + + var amount = 0 + IridiumSkyblock.getInstance().teamManager.getTeamMembers(island.get()).fastFor { + amount += AxMinionsAPI.INSTANCE.getDataHandler().getMinionAmount(it.uuid) + } + + return amount + } + + override fun handleBlockBreak(block: Block) { + + } + + override fun register() { + + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/island/SuperiorSkyBlock2Integration.kt b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/island/SuperiorSkyBlock2Integration.kt index 67fa575..296a8da 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/integrations/island/SuperiorSkyBlock2Integration.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/integrations/island/SuperiorSkyBlock2Integration.kt @@ -1,6 +1,7 @@ package com.artillexstudios.axminions.integrations.island import com.artillexstudios.axminions.api.AxMinionsAPI +import com.artillexstudios.axminions.api.config.Config import com.artillexstudios.axminions.api.integrations.types.IslandIntegration import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI import org.bukkit.block.Block @@ -11,14 +12,25 @@ class SuperiorSkyBlock2Integration : IslandIntegration { override fun getIslandPlaced(player: Player): Int { var placed = 0 SuperiorSkyblockAPI.getPlayer(player.uniqueId).island?.getIslandMembers(true)?.forEach { + if (Config.DEBUG()) { + println("Member: ${it.name}") + } placed += AxMinionsAPI.INSTANCE.getDataHandler().getMinionAmount(it.uniqueId) } return placed } - fun handleBlockBreak(block: Block) { - SuperiorSkyblockAPI.getIslandAt(block.location)?.handleBlockBreak(block) + override fun handleBlockBreak(block: Block) { + val island = SuperiorSkyblockAPI.getIslandAt(block.location) + + if (island == null) { + if (Config.DEBUG()) { + println("Island is null at location: ${block.location}") + } + } else { + island.handleBlockBreak(block) + } } override fun register() { 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 ecb2180..19c1af4 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 @@ -11,13 +11,16 @@ import com.artillexstudios.axminions.api.warnings.Warnings import com.artillexstudios.axminions.minions.MinionTicker import dev.lone.itemsadder.api.CustomBlock import org.bukkit.Bukkit +import org.bukkit.Location import kotlin.math.roundToInt import org.bukkit.Material +import org.bukkit.block.BlockFace import org.bukkit.block.data.Ageable import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.ItemStack -class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResource("minions/farmer.yml")!!) { +class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResource("minions/farmer.yml")!!, true) { + private val faces = arrayOf(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST) override fun shouldRun(minion: Minion): Boolean { return MinionTicker.getTick() % minion.getNextAction() == 0L @@ -61,7 +64,21 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour var size = 0 val drops = arrayListOf() - LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location -> + val blocks = when (getConfig().getString("mode")) { + "face" -> { + LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing) + } + "line" -> { + val list = arrayListOf() + faces.fastFor { + list.addAll(LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing)) + } + list + } + else -> LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false) + } + + blocks.fastFor { location -> val block = location.block if (AxMinionsPlugin.integrations.itemsAdderIntegration) { diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt index 16902e6..189e221 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/minions/miniontype/MinerMinionType.kt @@ -10,22 +10,19 @@ import com.artillexstudios.axminions.api.utils.LocationUtils import com.artillexstudios.axminions.api.utils.MinionUtils import com.artillexstudios.axminions.api.utils.fastFor import com.artillexstudios.axminions.api.warnings.Warnings -import com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration import com.artillexstudios.axminions.minions.MinionTicker import com.artillexstudios.axminions.nms.NMSHandler import dev.lone.itemsadder.api.CustomBlock -import java.util.Locale -import java.util.concurrent.ExecutorService -import java.util.concurrent.Executors -import kotlin.math.roundToInt import me.kryniowesegryderiusz.kgenerators.Main -import me.kryniowesegryderiusz.kgenerators.generators.locations.handlers.enums.InteractionType import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.block.BlockFace import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.FurnaceRecipe -import org.bukkit.inventory.ItemStack +import java.util.* +import java.util.concurrent.ExecutorService +import java.util.concurrent.Executors +import kotlin.math.roundToInt class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource("minions/miner.yml")!!, true) { companion object { @@ -41,6 +38,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource } } } + private var generatorMode = false private val whitelist = arrayListOf() @@ -95,14 +93,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource when (getConfig().getString("mode").lowercase(Locale.ENGLISH)) { "sphere" -> { LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location -> - if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() - .isChunkFullyLoaded(location) - ) { + if (AxMinionsPlugin.integrations.kGeneratorsIntegration) { val gen = Main.getPlacedGenerators().getLoaded(location) if (gen != null) { val possible = gen.isBlockPossibleToMine(location) if (possible) { + minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor) gen.scheduleGeneratorRegeneration() return@fastFor } else { @@ -127,9 +124,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource minion.addToContainerOrDrop(drops) block.type = Material.AIR val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() - if (integration is SuperiorSkyBlock2Integration) { - integration.handleBlockBreak(block) - } + integration?.handleBlockBreak(block) } } } @@ -143,14 +138,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource asyncExecutor!!.execute { LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false) .fastFor { location -> - if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() - .isChunkFullyLoaded(location) - ) { + if (AxMinionsPlugin.integrations.kGeneratorsIntegration) { val gen = Main.getPlacedGenerators().getLoaded(location) if (gen != null) { val possible = gen.isBlockPossibleToMine(location) if (possible) { + minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor) gen.scheduleGeneratorRegeneration() return@fastFor } else { @@ -176,9 +170,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource minion.addToContainerOrDrop(drops) block.type = Material.AIR val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() - if (integration is SuperiorSkyBlock2Integration) { - integration.handleBlockBreak(block) - } + integration?.handleBlockBreak(block) } } } @@ -186,14 +178,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource } else { LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false) .fastFor { location -> - if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() - .isChunkFullyLoaded(location) - ) { + if (AxMinionsPlugin.integrations.kGeneratorsIntegration) { val gen = Main.getPlacedGenerators().getLoaded(location) if (gen != null) { val possible = gen.isBlockPossibleToMine(location) if (possible) { + minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor) gen.scheduleGeneratorRegeneration() return@fastFor } else { @@ -218,9 +209,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource minion.addToContainerOrDrop(drops) block.type = Material.AIR val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() - if (integration is SuperiorSkyBlock2Integration) { - integration.handleBlockBreak(block) - } + integration?.handleBlockBreak(block) } } } @@ -229,14 +218,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource "line" -> { faces.fastFor { LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), it).fastFor { location -> - if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() - .isChunkFullyLoaded(location) - ) { + if (AxMinionsPlugin.integrations.kGeneratorsIntegration) { val gen = Main.getPlacedGenerators().getLoaded(location) if (gen != null) { val possible = gen.isBlockPossibleToMine(location) if (possible) { + minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor) gen.scheduleGeneratorRegeneration() return@fastFor } else { @@ -261,9 +249,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource minion.addToContainerOrDrop(drops) block.type = Material.AIR val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() - if (integration is SuperiorSkyBlock2Integration) { - integration.handleBlockBreak(block) - } + integration?.handleBlockBreak(block) } } } @@ -272,14 +258,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource "face" -> { LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing) .fastFor { location -> - if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() - .isChunkFullyLoaded(location) - ) { + if (AxMinionsPlugin.integrations.kGeneratorsIntegration) { val gen = Main.getPlacedGenerators().getLoaded(location) if (gen != null) { val possible = gen.isBlockPossibleToMine(location) if (possible) { + minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor) gen.scheduleGeneratorRegeneration() return@fastFor } else { @@ -287,7 +272,6 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource } } } - if (AxMinionsPlugin.integrations.itemsAdderIntegration) { val block = CustomBlock.byAlreadyPlaced(location.block) if (block !== null) { @@ -318,9 +302,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource minion.addToContainerOrDrop(drops) block.type = Material.AIR val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() - if (integration is SuperiorSkyBlock2Integration) { - integration.handleBlockBreak(block) - } + integration?.handleBlockBreak(block) } } } @@ -330,6 +312,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource (minion.getStorage() + xp).coerceIn(0.0, minion.getType().getLong("storage", minion.getLevel()).toDouble()) minion.setStorage(coerced) minion.setActions(minion.getActionAmount() + amount) - minion.damageTool(amount) + + for (i in 0..