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

View File

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

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

View File

@ -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<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
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.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<Material>()
@ -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..<amount) {
minion.damageTool()
}
}
}

View File

@ -12,6 +12,12 @@ tool:
- "DIAMOND_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:
type: "player_head"
texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDAxZTAzNWEzZDhkNjEyNjA3MmJjYmU1MmE5NzkxM2FjZTkzNTUyYTk5OTk1YjVkNDA3MGQ2NzgzYTMxZTkwOSJ9fX0="
@ -136,3 +142,5 @@ upgrades:
type: LEATHER_BOOTS
color: "0, 200, 0"
glow: true
config-version: 1