mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-19 15:09:17 +00:00
Improvements
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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() {
|
||||
|
||||
|
||||
@@ -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<EntityType>(it.uppercase()) }
|
||||
|
||||
@@ -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<SpawnPoint> {
|
||||
fun generate(player: Player): Set<SpawnPoint> =
|
||||
generate(player.location)
|
||||
|
||||
fun generate(location: Location): Set<SpawnPoint> {
|
||||
val points = mutableSetOf<SpawnPoint>()
|
||||
|
||||
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<Mob>()
|
||||
.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++
|
||||
|
||||
Reference in New Issue
Block a user