9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-23 00:49:36 +00:00

PR Improvements

This commit is contained in:
Auxilor
2022-09-28 16:10:21 +01:00
parent 383893c8f6
commit 127a43e032
6 changed files with 54 additions and 46 deletions

View File

@@ -31,25 +31,9 @@ allprojects {
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.codemc.org/repository/nms/")
maven("https://repo.codemc.org/repository/maven-public")
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://oss.sonatype.org/content/groups/public/")
maven("https://maven.enginehub.org/repo/")
maven("https://ci.ender.zone/plugin/repository/project/")
maven("https://ci.ender.zone/plugin/repository/everything/")
maven("https://repo.md-5.net/content/repositories/snapshots/")
maven("https://repo.dmulloy2.net/nexus/repository/public/")
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.maven.apache.org/maven2/")
maven("https://repo.dustplanet.de/artifactory/ext-release-local/")
maven("https://maven.seyfahni.de/repository/snapshots/")
maven("https://libraries.minecraft.net/")
maven("https://repo.spongepowered.org/maven/")
maven("https://org.kitteh.pastegg")
maven("https://repo.mikeprimm.com/")
maven("https://maven.sk89q.com/repo/")
maven("https://github.com/factions-site/repo/raw/public/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
maven("https://mvn.lumine.io/repository/maven-public/") { metadataSources.mavenPom() }
maven("https://mvn.lumine.io/repository/maven-public/")
}
dependencies {
@@ -59,8 +43,6 @@ allprojects {
implementation("com.willfp:libreforge:3.105.0")
implementation("org.joml:joml:1.10.4")
compileOnly("com.ticxo.modelengine:api:R3.0.0")
}
java {

View File

@@ -7,4 +7,5 @@ dependencies {
// Integrations
compileOnly("com.github.lokka30:LevelledMobs:3.1.4")
compileOnly("com.ticxo.modelengine:api:R3.0.1")
}

View File

@@ -7,14 +7,13 @@ import com.willfp.eco.core.config.ConfigType
import com.willfp.eco.core.config.TransientConfig
import com.willfp.eco.core.config.updating.ConfigUpdater
import com.willfp.ecobosses.EcoBossesPlugin
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
import java.io.File
import java.util.*
import java.util.UUID
object Bosses {
/**
* Registered bosses.
*/
/** Registered bosses. */
private val BY_ID: BiMap<String, EcoBoss> = HashBiMap.create()
/**
@@ -123,4 +122,14 @@ object Bosses {
operator fun get(entity: LivingEntity): LivingEcoBoss? {
return get(entity.uniqueId)
}
/** If an entity is a boss. */
val Entity?.isBoss: Boolean
get() {
if (this !is LivingEntity) {
return false
}
return Bosses[this] != null
}
}

View File

@@ -298,7 +298,7 @@ class EcoBoss(
private val mob: TestableEntity = Entities.lookup(config.getString("mob"))
private val modelEngineID: String = config.getString("modelEngineID")
private val modelEngineID = config.getStringOrNull("modelEngineID")
private val currentlyAlive = mutableMapOf<UUID, LivingEcoBoss>()
@@ -346,11 +346,11 @@ class EcoBoss(
entityGoals.forEach { controller.addEntityGoal(it.priority, it.goal as EntityGoal<in Mob>) }
}
if (modelEngineID.isNotBlank() && Bukkit.getPluginManager().isPluginEnabled("modelEngine")) {
if (modelEngineID != null && Bukkit.getPluginManager().isPluginEnabled("modelEngine")) {
val model = ModelEngineAPI.createActiveModel(modelEngineID)
if (model == null) {
plugin.logger.warning("Invalid modelEngineID for boss $id")
plugin.logger.warning("Invalid Model Engine ID for boss $id")
}
val modelled = ModelEngineAPI.createModeledEntity(mob)
@@ -462,9 +462,9 @@ class EcoBoss(
override fun toString(): String {
return (
"EcoBoss{" +
id +
"}"
)
"EcoBoss{" +
id +
"}"
)
}
}

View File

@@ -1,8 +1,6 @@
package com.willfp.ecobosses.lifecycle
import com.willfp.ecobosses.bosses.Bosses
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
import com.willfp.ecobosses.bosses.Bosses.isBoss
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityTransformEvent
@@ -11,17 +9,17 @@ import org.bukkit.event.entity.SlimeSplitEvent
class CompatibilityListeners : Listener {
@EventHandler
fun handle(event: SlimeSplitEvent) {
if (!this.isBoss(event.entity)) return
if (!event.entity.isBoss) {
return
}
event.isCancelled = true
}
@EventHandler
fun handle(event: EntityTransformEvent) {
if (!this.isBoss(event.entity)) return
if (!event.entity.isBoss) {
return
}
event.isCancelled = true
}
private fun isBoss(entity: Entity): Boolean {
return Bosses[entity as? LivingEntity ?: return false] != null
}
}

View File

@@ -3,6 +3,7 @@ package com.willfp.ecobosses.spawn
import com.willfp.ecobosses.EcoBossesPlugin
import com.willfp.ecobosses.bosses.bossEgg
import com.willfp.ecobosses.events.BossSpawnEvent
import com.willfp.libreforge.conditions.isMet
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.block.Container
@@ -17,13 +18,20 @@ import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
class SpawnEggHandler : Listener {
class SpawnEggHandler(
private val plugin: EcoBossesPlugin
) : Listener {
@EventHandler(
ignoreCancelled = true
)
fun handle(event: PlayerInteractEvent) {
if (event.action != Action.RIGHT_CLICK_BLOCK) return
if (!this.handleSpawnEgg(event.item, event.clickedBlock?.location?.add(0.0, 1.5, 0.0), event.player)) return
if (event.action != Action.RIGHT_CLICK_BLOCK) {
return
}
if (!this.handleSpawnEgg(event.item, event.clickedBlock?.location?.add(0.0, 1.5, 0.0), event.player)) {
return
}
event.isCancelled = true
event.setUseItemInHand(Event.Result.DENY)
@@ -52,9 +60,9 @@ class SpawnEggHandler : Listener {
// This is needed as the event must finish first,
// Otherwise the dispenser/dropper thinks the item is already removed from this event.
EcoBossesPlugin.instance.scheduler.run {
plugin.scheduler.run {
val item = dispenser.inventory.find { it?.isSimilar(event.item) == true } ?: return@run
item.amount -= 1
item.amount--
dispenser.update()
}
}
@@ -66,12 +74,22 @@ class SpawnEggHandler : Listener {
): Boolean {
val boss = item?.bossEgg ?: return false
if (location == null || (player != null && !boss.spawnConditions.all { it.condition.isConditionMet(player, it.config) })) return false
if (location == null) {
return false
}
if (player != null) {
if (!boss.spawnConditions.isMet(player)) {
return false
}
}
val spawnEvent = BossSpawnEvent(boss, location, BossSpawnEvent.SpawnReason.EGG, player)
Bukkit.getPluginManager().callEvent(spawnEvent)
if (spawnEvent.isCancelled) return false
if (spawnEvent.isCancelled) {
return false
}
boss.spawn(location)