diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethod.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethod.kt index fd9cecf..aa95213 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethod.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethod.kt @@ -1,13 +1,13 @@ package com.willfp.ecomobs.category.spawning -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.config.interfaces.Config +import com.willfp.ecomobs.EcoMobsPlugin import com.willfp.ecomobs.category.MobCategory abstract class SpawnMethod( val category: MobCategory, val config: Config, - protected val plugin: EcoPlugin + protected val plugin: EcoMobsPlugin ) { private var isStarted = false diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethodFactory.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethodFactory.kt index c2d0df1..7abd971 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethodFactory.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/SpawnMethodFactory.kt @@ -1,8 +1,8 @@ package com.willfp.ecomobs.category.spawning -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.registry.KRegistrable +import com.willfp.ecomobs.EcoMobsPlugin import com.willfp.ecomobs.category.MobCategory import com.willfp.libreforge.ViolationContext @@ -10,7 +10,7 @@ abstract class SpawnMethodFactory(override val id: String) : KRegistrable { abstract fun create( category: MobCategory, config: Config, - plugin: EcoPlugin, + plugin: EcoMobsPlugin, context: ViolationContext ): SpawnMethod } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryCustom.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryCustom.kt index 46137b5..df240bd 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryCustom.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryCustom.kt @@ -1,9 +1,8 @@ package com.willfp.ecomobs.category.spawning.impl -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.config.interfaces.Config -import com.willfp.eco.core.entities.Entities import com.willfp.eco.util.randDouble +import com.willfp.ecomobs.EcoMobsPlugin import com.willfp.ecomobs.category.MobCategory import com.willfp.ecomobs.category.spawning.SpawnMethod import com.willfp.ecomobs.category.spawning.SpawnMethodFactory @@ -16,18 +15,14 @@ import com.willfp.libreforge.conditions.Conditions import com.willfp.libreforge.enumValueOfOrNull import com.willfp.libreforge.toDispatcher import org.bukkit.Bukkit -import org.bukkit.entity.LivingEntity -import org.bukkit.event.EventHandler -import org.bukkit.event.EventPriority import org.bukkit.event.Listener -import org.bukkit.event.entity.CreatureSpawnEvent import org.bukkit.scheduler.BukkitTask object SpawnMethodFactoryCustom : SpawnMethodFactory("custom") { override fun create( category: MobCategory, config: Config, - plugin: EcoPlugin, + plugin: EcoMobsPlugin, context: ViolationContext ): SpawnMethod { return SpawnMethodCustom(category, config, plugin, context) @@ -36,7 +31,7 @@ object SpawnMethodFactoryCustom : SpawnMethodFactory("custom") { class SpawnMethodCustom( category: MobCategory, config: Config, - plugin: EcoPlugin, + plugin: EcoMobsPlugin, context: ViolationContext ) : SpawnMethod(category, config, plugin), Listener { private val spawnRate = plugin.configYml.getInt("custom-spawning.spawn-rate").toLong() diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryNone.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryNone.kt index 2d94196..f956008 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryNone.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryNone.kt @@ -1,32 +1,24 @@ package com.willfp.ecomobs.category.spawning.impl -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.config.interfaces.Config -import com.willfp.eco.core.entities.Entities +import com.willfp.ecomobs.EcoMobsPlugin import com.willfp.ecomobs.category.MobCategory import com.willfp.ecomobs.category.spawning.SpawnMethod import com.willfp.ecomobs.category.spawning.SpawnMethodFactory -import com.willfp.ecomobs.mob.SpawnReason import com.willfp.libreforge.ViolationContext -import com.willfp.libreforge.enumValueOfOrNull -import org.bukkit.entity.EntityType -import org.bukkit.event.EventHandler -import org.bukkit.event.EventPriority -import org.bukkit.event.Listener -import org.bukkit.event.entity.CreatureSpawnEvent object SpawnMethodFactoryNone : SpawnMethodFactory("replace") { override fun create( category: MobCategory, config: Config, - plugin: EcoPlugin, + plugin: EcoMobsPlugin, context: ViolationContext ): SpawnMethod { return SpawnMethodNone(category, config, plugin) } class SpawnMethodNone( - category: MobCategory, config: Config, plugin: EcoPlugin + category: MobCategory, config: Config, plugin: EcoMobsPlugin ) : SpawnMethod(category, config, plugin) { override fun onStart() { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryReplace.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryReplace.kt index d4e6e35..bcbcf8c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryReplace.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/impl/SpawnMethodFactoryReplace.kt @@ -1,8 +1,8 @@ package com.willfp.ecomobs.category.spawning.impl -import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.entities.Entities +import com.willfp.ecomobs.EcoMobsPlugin import com.willfp.ecomobs.category.MobCategory import com.willfp.ecomobs.category.spawning.SpawnMethod import com.willfp.ecomobs.category.spawning.SpawnMethodFactory @@ -19,7 +19,7 @@ object SpawnMethodFactoryReplace : SpawnMethodFactory("replace") { override fun create( category: MobCategory, config: Config, - plugin: EcoPlugin, + plugin: EcoMobsPlugin, context: ViolationContext ): SpawnMethod { return SpawnMethodReplace(category, config, plugin) @@ -28,7 +28,7 @@ object SpawnMethodFactoryReplace : SpawnMethodFactory("replace") { class SpawnMethodReplace( category: MobCategory, config: Config, - plugin: EcoPlugin + plugin: EcoMobsPlugin ) : SpawnMethod(category, config, plugin), Listener { private val toReplace = config.getStrings("replace") .mapNotNull { enumValueOfOrNull(it.uppercase()) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/spawnpoints/SpawnPointGenerator.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/spawnpoints/SpawnPointGenerator.kt index 443fa68..9d12fbe 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/spawnpoints/SpawnPointGenerator.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecomobs/category/spawning/spawnpoints/SpawnPointGenerator.kt @@ -1,10 +1,13 @@ package com.willfp.ecomobs.category.spawning.spawnpoints import com.github.benmanes.caffeine.cache.Caffeine +import com.sun.tools.javac.jvm.ByteCodes.ret import com.willfp.eco.core.EcoPlugin import com.willfp.ecomobs.math.Int3 import com.willfp.ecomobs.plugin +import org.bukkit.Location import org.bukkit.Material +import org.bukkit.World import org.bukkit.block.data.Waterlogged import org.bukkit.entity.Mob import org.bukkit.entity.Player @@ -28,11 +31,14 @@ class SpawnPointGenerator( private val maxAttempts = plugin.configYml.getInt("custom-spawning.max-attempts") private val maxMobs = plugin.configYml.getInt("custom-spawning.max-mobs-per-player") - fun generate(player: Player): Set { + fun generate(player: Player): Set = + generate(player.location) + + fun generate(location: Location): Set { val points = mutableSetOf() - val mobsAroundPlayer = player.location.world - .getNearbyEntities(player.location, radius.toDouble(), radius.toDouble(), radius.toDouble()) + val mobsAroundPlayer = location.world + .getNearbyEntities(location, radius.toDouble(), radius.toDouble(), radius.toDouble()) .filterIsInstance() .size @@ -41,27 +47,34 @@ class SpawnPointGenerator( } for (i in 1..max) { - val point = generatePoint(player) ?: continue + val point = generateAroundLocation(location) ?: continue points.add(point) } return points } - private fun generatePoint(player: Player): SpawnPoint? { - val playerLocation = player.location - val world = playerLocation.world ?: return null + private fun generateAroundLocation(location: Location): SpawnPoint? { + val world = location.world ?: return null val bottomCorner = Int3( - playerLocation.x.toInt() - radius, playerLocation.y.toInt() - radius, playerLocation.z.toInt() - radius + location.x.toInt() - radius, + location.y.toInt() - radius, + location.z.toInt() - radius ) val topCorner = Int3( - playerLocation.x.toInt() + radius, playerLocation.y.toInt() + radius, playerLocation.z.toInt() + radius + location.x.toInt() + radius, + location.y.toInt() + radius, + location.z.toInt() + radius ) + return generateInBox(world, bottomCorner, topCorner) + } + + private fun generateInBox(world: World, corner1: Int3, corner2: Int3): SpawnPoint? { var attempts = 0 - val iterator = (bottomCorner..topCorner).randomIterator() + val iterator = (corner1..corner2).randomIterator() while (attempts < maxAttempts) { attempts++