This commit is contained in:
TomTom 2024-06-10 15:55:35 +02:00
parent 0674b36fbf
commit 9545841935
7 changed files with 105 additions and 50 deletions

View File

@ -1,9 +1,12 @@
package com.artillexstudios.axminions.api.integrations.types package com.artillexstudios.axminions.api.integrations.types
import com.artillexstudios.axminions.api.integrations.Integration import com.artillexstudios.axminions.api.integrations.Integration
import org.bukkit.block.Block
import org.bukkit.entity.Player import org.bukkit.entity.Player
interface IslandIntegration : Integration { interface IslandIntegration : Integration {
fun getIslandPlaced(player: Player): Int fun getIslandPlaced(player: Player): Int
fun handleBlockBreak(block: Block)
} }

View File

@ -133,6 +133,7 @@ class Integrations : Integrations {
if (Bukkit.getPluginManager().getPlugin("SuperiorSkyblock2") != null) { if (Bukkit.getPluginManager().getPlugin("SuperiorSkyblock2") != null) {
register(SuperiorSkyBlock2Integration()) register(SuperiorSkyBlock2Integration())
register(com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration())
Bukkit.getConsoleSender() Bukkit.getConsoleSender()
.sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into SuperiorSkyblock2!")) .sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into SuperiorSkyblock2!"))
Bukkit.getPluginManager().registerEvents(SuperiorSkyBlock2Listener(), AxMinionsPlugin.INSTANCE) Bukkit.getPluginManager().registerEvents(SuperiorSkyBlock2Listener(), AxMinionsPlugin.INSTANCE)
@ -164,6 +165,7 @@ class Integrations : Integrations {
if (Bukkit.getPluginManager().getPlugin("IridiumSkyBlock") != null) { if (Bukkit.getPluginManager().getPlugin("IridiumSkyBlock") != null) {
register(IridiumSkyBlockIntegration()) register(IridiumSkyBlockIntegration())
register(com.artillexstudios.axminions.integrations.island.IridiumSkyBlockIntegration())
Bukkit.getConsoleSender() Bukkit.getConsoleSender()
.sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into IridiumSkyBlock!")) .sendMessage(StringUtils.formatToString("<#33FF33>[AxMinions] Hooked into IridiumSkyBlock!"))
} }
@ -199,12 +201,6 @@ class Integrations : Integrations {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
PlaceholderAPIIntegration().register() 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) { override fun register(integration: Integration) {

View File

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

View File

@ -1,6 +1,7 @@
package com.artillexstudios.axminions.integrations.island package com.artillexstudios.axminions.integrations.island
import com.artillexstudios.axminions.api.AxMinionsAPI import com.artillexstudios.axminions.api.AxMinionsAPI
import com.artillexstudios.axminions.api.config.Config
import com.artillexstudios.axminions.api.integrations.types.IslandIntegration import com.artillexstudios.axminions.api.integrations.types.IslandIntegration
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI
import org.bukkit.block.Block import org.bukkit.block.Block
@ -11,14 +12,25 @@ class SuperiorSkyBlock2Integration : IslandIntegration {
override fun getIslandPlaced(player: Player): Int { override fun getIslandPlaced(player: Player): Int {
var placed = 0 var placed = 0
SuperiorSkyblockAPI.getPlayer(player.uniqueId).island?.getIslandMembers(true)?.forEach { SuperiorSkyblockAPI.getPlayer(player.uniqueId).island?.getIslandMembers(true)?.forEach {
if (Config.DEBUG()) {
println("Member: ${it.name}")
}
placed += AxMinionsAPI.INSTANCE.getDataHandler().getMinionAmount(it.uniqueId) placed += AxMinionsAPI.INSTANCE.getDataHandler().getMinionAmount(it.uniqueId)
} }
return placed return placed
} }
fun handleBlockBreak(block: Block) { override fun handleBlockBreak(block: Block) {
SuperiorSkyblockAPI.getIslandAt(block.location)?.handleBlockBreak(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() { override fun register() {

View File

@ -11,13 +11,16 @@ import com.artillexstudios.axminions.api.warnings.Warnings
import com.artillexstudios.axminions.minions.MinionTicker import com.artillexstudios.axminions.minions.MinionTicker
import dev.lone.itemsadder.api.CustomBlock import dev.lone.itemsadder.api.CustomBlock
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.Location
import kotlin.math.roundToInt import kotlin.math.roundToInt
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.block.BlockFace
import org.bukkit.block.data.Ageable import org.bukkit.block.data.Ageable
import org.bukkit.enchantments.Enchantment import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.ItemStack 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 { override fun shouldRun(minion: Minion): Boolean {
return MinionTicker.getTick() % minion.getNextAction() == 0L return MinionTicker.getTick() % minion.getNextAction() == 0L
@ -61,7 +64,21 @@ class FarmerMinionType : MinionType("farmer", AxMinionsPlugin.INSTANCE.getResour
var size = 0 var size = 0
val drops = arrayListOf<ItemStack>() val drops = arrayListOf<ItemStack>()
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<Location>()
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 val block = location.block
if (AxMinionsPlugin.integrations.itemsAdderIntegration) { if (AxMinionsPlugin.integrations.itemsAdderIntegration) {

View File

@ -10,22 +10,19 @@ import com.artillexstudios.axminions.api.utils.LocationUtils
import com.artillexstudios.axminions.api.utils.MinionUtils import com.artillexstudios.axminions.api.utils.MinionUtils
import com.artillexstudios.axminions.api.utils.fastFor import com.artillexstudios.axminions.api.utils.fastFor
import com.artillexstudios.axminions.api.warnings.Warnings import com.artillexstudios.axminions.api.warnings.Warnings
import com.artillexstudios.axminions.integrations.island.SuperiorSkyBlock2Integration
import com.artillexstudios.axminions.minions.MinionTicker import com.artillexstudios.axminions.minions.MinionTicker
import com.artillexstudios.axminions.nms.NMSHandler import com.artillexstudios.axminions.nms.NMSHandler
import dev.lone.itemsadder.api.CustomBlock 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.Main
import me.kryniowesegryderiusz.kgenerators.generators.locations.handlers.enums.InteractionType
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.Material import org.bukkit.Material
import org.bukkit.block.BlockFace import org.bukkit.block.BlockFace
import org.bukkit.enchantments.Enchantment import org.bukkit.enchantments.Enchantment
import org.bukkit.inventory.FurnaceRecipe 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) { class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource("minions/miner.yml")!!, true) {
companion object { companion object {
@ -41,6 +38,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
} }
} }
} }
private var generatorMode = false private var generatorMode = false
private val whitelist = arrayListOf<Material>() private val whitelist = arrayListOf<Material>()
@ -95,14 +93,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
when (getConfig().getString("mode").lowercase(Locale.ENGLISH)) { when (getConfig().getString("mode").lowercase(Locale.ENGLISH)) {
"sphere" -> { "sphere" -> {
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location -> LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location ->
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() if (AxMinionsPlugin.integrations.kGeneratorsIntegration) {
.isChunkFullyLoaded(location)
) {
val gen = Main.getPlacedGenerators().getLoaded(location) val gen = Main.getPlacedGenerators().getLoaded(location)
if (gen != null) { if (gen != null) {
val possible = gen.isBlockPossibleToMine(location) val possible = gen.isBlockPossibleToMine(location)
if (possible) { if (possible) {
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
gen.scheduleGeneratorRegeneration() gen.scheduleGeneratorRegeneration()
return@fastFor return@fastFor
} else { } else {
@ -127,9 +124,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
minion.addToContainerOrDrop(drops) minion.addToContainerOrDrop(drops)
block.type = Material.AIR block.type = Material.AIR
val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() 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 { asyncExecutor!!.execute {
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false) LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false)
.fastFor { location -> .fastFor { location ->
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() if (AxMinionsPlugin.integrations.kGeneratorsIntegration) {
.isChunkFullyLoaded(location)
) {
val gen = Main.getPlacedGenerators().getLoaded(location) val gen = Main.getPlacedGenerators().getLoaded(location)
if (gen != null) { if (gen != null) {
val possible = gen.isBlockPossibleToMine(location) val possible = gen.isBlockPossibleToMine(location)
if (possible) { if (possible) {
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
gen.scheduleGeneratorRegeneration() gen.scheduleGeneratorRegeneration()
return@fastFor return@fastFor
} else { } else {
@ -176,9 +170,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
minion.addToContainerOrDrop(drops) minion.addToContainerOrDrop(drops)
block.type = Material.AIR block.type = Material.AIR
val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() 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 { } else {
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false) LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false)
.fastFor { location -> .fastFor { location ->
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() if (AxMinionsPlugin.integrations.kGeneratorsIntegration) {
.isChunkFullyLoaded(location)
) {
val gen = Main.getPlacedGenerators().getLoaded(location) val gen = Main.getPlacedGenerators().getLoaded(location)
if (gen != null) { if (gen != null) {
val possible = gen.isBlockPossibleToMine(location) val possible = gen.isBlockPossibleToMine(location)
if (possible) { if (possible) {
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
gen.scheduleGeneratorRegeneration() gen.scheduleGeneratorRegeneration()
return@fastFor return@fastFor
} else { } else {
@ -218,9 +209,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
minion.addToContainerOrDrop(drops) minion.addToContainerOrDrop(drops)
block.type = Material.AIR block.type = Material.AIR
val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() 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" -> { "line" -> {
faces.fastFor { faces.fastFor {
LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), it).fastFor { location -> LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), it).fastFor { location ->
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() if (AxMinionsPlugin.integrations.kGeneratorsIntegration) {
.isChunkFullyLoaded(location)
) {
val gen = Main.getPlacedGenerators().getLoaded(location) val gen = Main.getPlacedGenerators().getLoaded(location)
if (gen != null) { if (gen != null) {
val possible = gen.isBlockPossibleToMine(location) val possible = gen.isBlockPossibleToMine(location)
if (possible) { if (possible) {
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
gen.scheduleGeneratorRegeneration() gen.scheduleGeneratorRegeneration()
return@fastFor return@fastFor
} else { } else {
@ -261,9 +249,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
minion.addToContainerOrDrop(drops) minion.addToContainerOrDrop(drops)
block.type = Material.AIR block.type = Material.AIR
val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() 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" -> { "face" -> {
LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing) LocationUtils.getAllBlocksFacing(minion.getLocation(), minion.getRange(), minion.getDirection().facing)
.fastFor { location -> .fastFor { location ->
if (AxMinionsPlugin.integrations.kGeneratorsIntegration && Main.getPlacedGenerators() if (AxMinionsPlugin.integrations.kGeneratorsIntegration) {
.isChunkFullyLoaded(location)
) {
val gen = Main.getPlacedGenerators().getLoaded(location) val gen = Main.getPlacedGenerators().getLoaded(location)
if (gen != null) { if (gen != null) {
val possible = gen.isBlockPossibleToMine(location) val possible = gen.isBlockPossibleToMine(location)
if (possible) { if (possible) {
minion.addToContainerOrDrop(gen.generator.drawGeneratedObject().customDrops?.item ?: return@fastFor)
gen.scheduleGeneratorRegeneration() gen.scheduleGeneratorRegeneration()
return@fastFor return@fastFor
} else { } else {
@ -287,7 +272,6 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
} }
} }
} }
if (AxMinionsPlugin.integrations.itemsAdderIntegration) { if (AxMinionsPlugin.integrations.itemsAdderIntegration) {
val block = CustomBlock.byAlreadyPlaced(location.block) val block = CustomBlock.byAlreadyPlaced(location.block)
if (block !== null) { if (block !== null) {
@ -318,9 +302,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
minion.addToContainerOrDrop(drops) minion.addToContainerOrDrop(drops)
block.type = Material.AIR block.type = Material.AIR
val integration = AxMinionsAPI.INSTANCE.getIntegrations().getIslandIntegration() 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.getStorage() + xp).coerceIn(0.0, minion.getType().getLong("storage", minion.getLevel()).toDouble())
minion.setStorage(coerced) minion.setStorage(coerced)
minion.setActions(minion.getActionAmount() + amount) minion.setActions(minion.getActionAmount() + amount)
minion.damageTool(amount)
for (i in 0..<amount) {
minion.damageTool()
}
} }
} }

View File

@ -12,6 +12,12 @@ tool:
- "DIAMOND_HOE" - "DIAMOND_HOE"
- "NETHERITE_HOE" - "NETHERITE_HOE"
# Can be: sphere, line, face
# If set to sphere: checks blocks in a sphere with the range of the minion as radius (Most resource intensive, the larger the radius, the worse)
# If set to line: checks blocks in all 4 directions from the minion in the range of the minion (Best performance to blocks farmed ratio)
# If set to face: checks blocks only in the facing of the minion (Least resource intensive)
mode: sphere
item: item:
type: "player_head" type: "player_head"
texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDAxZTAzNWEzZDhkNjEyNjA3MmJjYmU1MmE5NzkxM2FjZTkzNTUyYTk5OTk1YjVkNDA3MGQ2NzgzYTMxZTkwOSJ9fX0=" texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDAxZTAzNWEzZDhkNjEyNjA3MmJjYmU1MmE5NzkxM2FjZTkzNTUyYTk5OTk1YjVkNDA3MGQ2NzgzYTMxZTkwOSJ9fX0="
@ -136,3 +142,5 @@ upgrades:
type: LEATHER_BOOTS type: LEATHER_BOOTS
color: "0, 200, 0" color: "0, 200, 0"
glow: true glow: true
config-version: 1