diff --git a/build.gradle.kts b/build.gradle.kts index 14010f66a..cc38b3ff2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,8 +3,6 @@ plugins { id("org.jetbrains.dokka") version "1.9.20" } -apply(plugin = "kotlin") - repositories { mavenCentral() maven("https://mvnrepository.com/") diff --git a/gradle.properties b/gradle.properties index d7676ef55..231d96271 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 4.0.5 b29 +version = 4.0.6 b35 description = The Ultimate RPG Mob Levelling Solution \ No newline at end of file diff --git a/levelledmobs-plugin/build.gradle.kts b/levelledmobs-plugin/build.gradle.kts index a46f85dbb..1c3a6a1d4 100644 --- a/levelledmobs-plugin/build.gradle.kts +++ b/levelledmobs-plugin/build.gradle.kts @@ -28,13 +28,12 @@ idea { dependencies { implementation(kotlin("stdlib", version = "2.0.0")) - implementation("org.jetbrains.kotlin:kotlin-reflect:2.0.0") compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") compileOnly("dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT") // https://repo.papermc.io/#browse/browse:maven-public:dev%2Ffolia%2Ffolia-api implementation("com.github.Redempt:Crunch:2.0.3") // https://redempt.dev/com/github/Redempt/Crunch implementation("org.bstats:bstats-bukkit:3.0.2") // https://mvnrepository.com/artifact/org.bstats/bstats-bukkit //implementation("dev.jorel:commandapi-bukkit-shade:9.3.0") // https://github.com/JorelAli/CommandAPI - implementation("nomaven:CommandAPI:9.5.0-mod") // https://github.com/JorelAli/CommandAPI + implementation("nomaven:CommandAPI:9.6.0-snapshot") // https://github.com/JorelAli/CommandAPI // stumper66's fork: https://github.com/stumper66/CommandAPI compileOnly("LibsDisguises:LibsDisguises:10.0.44-SNAPSHOT") // https://repo.md-5.net/#browse/browse:public:LibsDisguises%2FLibsDisguises compileOnly("net.essentialsx:EssentialsX:2.20.1") // https://repo.essentialsx.net/#/releases/net/essentialsx/EssentialsX @@ -75,11 +74,9 @@ tasks { relocate("org.bstats", "io.github.arcaneplugins.levelledmobs.libs.bstats") relocate("redempt.crunch", "io.github.arcaneplugins.levelledmobs.libs.crunch") relocate("org.jetbrains.annotations", "io.github.arcaneplugins.levelledmobs.libs.jetbrains.annotations") + relocate("kotlin", "io.github.arcaneplugins.levelledmobs.libs.kotlin") } - // if you don't exclude the reflection dep then reflection will be broken - minimize { - exclude(dependency("org.jetbrains.kotlin:kotlin-reflect")) - } + minimize{} } jar.configure { diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotMerge.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotMerge.kt index 24b3ba556..670446525 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotMerge.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotMerge.kt @@ -7,5 +7,5 @@ package io.github.arcaneplugins.levelledmobs.annotations * @author stumper66 * @since 3.2.0 */ -@Target(AnnotationTarget.PROPERTY) +@Target(AnnotationTarget.FIELD) annotation class DoNotMerge \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotShow.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotShow.kt index 1124cd226..ee405460c 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotShow.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/DoNotShow.kt @@ -1,4 +1,4 @@ package io.github.arcaneplugins.levelledmobs.annotations -@Target(AnnotationTarget.PROPERTY) +@Target(AnnotationTarget.FIELD) annotation class DoNotShow \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/ExcludeFromHash.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/ExcludeFromHash.kt index c650f77d6..d6695ef18 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/ExcludeFromHash.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/ExcludeFromHash.kt @@ -7,5 +7,5 @@ package io.github.arcaneplugins.levelledmobs.annotations * @author stumper66 * @since 3.12.0 */ -@Target(AnnotationTarget.PROPERTY) +@Target(AnnotationTarget.FIELD) annotation class ExcludeFromHash diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/RuleFieldInfo.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/RuleFieldInfo.kt index 6ea400cfc..8b02e3771 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/RuleFieldInfo.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/annotations/RuleFieldInfo.kt @@ -2,7 +2,7 @@ package io.github.arcaneplugins.levelledmobs.annotations import io.github.arcaneplugins.levelledmobs.enums.RuleType -@Target(AnnotationTarget.PROPERTY) +@Target(AnnotationTarget.FIELD) annotation class RuleFieldInfo( val value: String, val ruleType: RuleType diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/DebugSubcommand.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/DebugSubcommand.kt index 579930934..b44464a6e 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/DebugSubcommand.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/DebugSubcommand.kt @@ -14,7 +14,7 @@ import io.github.arcaneplugins.levelledmobs.debug.DebugCreator import io.github.arcaneplugins.levelledmobs.debug.DebugManager import io.github.arcaneplugins.levelledmobs.debug.DebugType import io.github.arcaneplugins.levelledmobs.managers.ExternalCompatibilityManager -import io.github.arcaneplugins.levelledmobs.nametag.MiscUtils +import io.github.arcaneplugins.levelledmobs.util.MiscUtils import io.github.arcaneplugins.levelledmobs.util.Log import io.github.arcaneplugins.levelledmobs.util.MessageUtils import io.github.arcaneplugins.levelledmobs.util.Utils @@ -321,15 +321,23 @@ object DebugSubcommand { sb.append("key: &b${items.key}&r, ${items.value}") } - val message = formatDumpMessage( - "Showing PDC keys for", - lmEntity, - sb.toString() - ) + val message = if (results.isEmpty()){ + formatDumpMessage( + "No PDC keys were found for", + lmEntity, + null + ) + } else{ + formatDumpMessage( + "Showing PDC keys for", + lmEntity, + sb.toString() + ) + } lmEntity.free() - if (showOnConsole) { + if (showOnConsole && results.isNotEmpty()) { Log.inf(message) sender.sendMessage("PDC keys have been printed in the console") } @@ -418,7 +426,7 @@ object DebugSubcommand { private fun formatDumpMessage( messageStart: String, lmEntity: LivingEntityWrapper, - values: String + values: String? ): String { var entityName = lmEntity.nameIfBaby if (ExternalCompatibilityManager.hasMythicMobsInstalled @@ -435,11 +443,12 @@ object DebugSubcommand { "${lmEntity.livingEntity.location.blockZ}" val mobLevel = if (lmEntity.isLevelled) lmEntity.getMobLevel.toString() else "0" + val showValues = if (values != null) "\n$values" else "" return if (lmEntity.nameIfBaby.equals(entityName, ignoreCase = true)) - "$messageStart: $entityName (lvl $mobLevel) in ${lmEntity.worldName}, $locationStr&r\n$values" + "$messageStart: $entityName (lvl $mobLevel) in ${lmEntity.worldName}, $locationStr&r$showValues" else - "$messageStart: $entityName (lvl $mobLevel ${lmEntity.typeName}) in ${lmEntity.worldName}, $locationStr&r\n$values" + "$messageStart: $entityName (lvl $mobLevel ${lmEntity.typeName}) in ${lmEntity.worldName}, $locationStr&r$showValues" } private fun parseEnableTimer(sender: CommandSender, args: CommandArguments) { diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/KillSubcommand.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/KillSubcommand.kt index 7535f7512..f355c179c 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/KillSubcommand.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/KillSubcommand.kt @@ -49,7 +49,8 @@ object KillSubcommand { .executes(CommandExecutor { sender, args -> processCmd(sender, args, true) }) .withOptionalArguments( ListArgumentBuilder("values") - .skipListValidation(true) + .allowAnyValue(true) + .allowDuplicates(true) .withList { info -> buildTabSuggestions(info) } .withStringMapper() .buildGreedy() @@ -60,7 +61,8 @@ object KillSubcommand { .executes(CommandExecutor { sender, args -> processCmd(sender, args, false) }) .withOptionalArguments( ListArgumentBuilder("values") - .skipListValidation(true) + .allowAnyValue(true) + .allowDuplicates(true) .withList { info -> buildTabSuggestions(info) } .withStringMapper() .buildGreedy() diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/RulesSubcommand.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/RulesSubcommand.kt index 2abb12523..cc4494371 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/RulesSubcommand.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/RulesSubcommand.kt @@ -44,10 +44,6 @@ import org.bukkit.entity.LivingEntity import org.bukkit.entity.Player import org.bukkit.persistence.PersistentDataType import org.bukkit.util.Vector -import kotlin.reflect.KVisibility -import kotlin.reflect.full.declaredMemberProperties -import kotlin.reflect.full.findAnnotation -import kotlin.reflect.full.hasAnnotation /** * Shows the current rules as parsed from the various config files @@ -568,17 +564,18 @@ object RulesSubcommand { for (i in effectiveRules.indices) { val pi = effectiveRules[i] - for (f in pi::class.declaredMemberProperties) { - if (f.visibility == KVisibility.PRIVATE) continue - if (f.hasAnnotation()) continue - if (f.hasAnnotation()) continue - val value = f.getter.call(pi) ?: continue + for (f in pi::class.java.declaredFields) { + f.trySetAccessible() + + if (f.isAnnotationPresent(DoNotMerge::class.java)) continue + if (f.isAnnotationPresent(DoNotShow::class.java)) continue + val value = f.get(pi) ?: continue if (value.toString().isEmpty()) continue var ruleName = f.name var showValue: String? = null var ruleInfoType = RuleType.MISC - val ruleTypeInfo = f.findAnnotation() + val ruleTypeInfo = f.getAnnotation(RuleFieldInfo::class.java) if (ruleTypeInfo != null) { ruleInfoType = ruleTypeInfo.ruleType ruleName = ruleTypeInfo.value diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerEggCommand.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerEggCommand.kt index 028886656..d386da2f1 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerEggCommand.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerEggCommand.kt @@ -56,7 +56,8 @@ object SpawnerEggCommand : SpawnerBaseClass() { }) .withOptionalArguments( ListArgumentBuilder("values") - .skipListValidation(true) + .allowAnyValue(true) + .allowDuplicates(true) .withList { info -> buildTabSuggestions(allEggOptions, info) } .withStringMapper() .buildGreedy() diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerSubcommand.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerSubcommand.kt index c96661685..732b3609c 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerSubcommand.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SpawnerSubcommand.kt @@ -47,7 +47,8 @@ object SpawnerSubcommand : SpawnerBaseClass() { }) .withOptionalArguments( ListArgumentBuilder("values") - .skipListValidation(true) + .allowAnyValue(true) + .allowDuplicates(true) .withList { info -> buildTabSuggestions(allSpawnerOptions, info) } .withStringMapper() .buildGreedy() diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SummonSubcommand.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SummonSubcommand.kt index 06abacd63..448bcb80a 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SummonSubcommand.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/commands/subcommands/SummonSubcommand.kt @@ -64,7 +64,8 @@ object SummonSubcommand { .replaceSuggestions(ArgumentSuggestions.strings("here", "at-player", "at-location"))) .withOptionalArguments( ListArgumentBuilder("values") - .skipListValidation(true) + .allowAnyValue(true) + .allowDuplicates(true) .withList { info -> buildTabSuggestions(info) } .withStringMapper() .buildGreedy() diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt index 6f2a39860..506430c80 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsHandler.kt @@ -443,7 +443,7 @@ class CustomDropsHandler { info.dropInstance = groupIdToInstance[drop.groupId] info.groupLimits = groupLimitsMap.getOrDefault(drop.groupId, defaultLimits) maxRetries = - info.groupLimits!!.retries.coerceAtMost(retriesHardcodedMax) + info.groupLimits?.retries?.coerceAtMost(retriesHardcodedMax) ?: 0 } else { info.dropInstance = null info.groupLimits = null @@ -764,7 +764,7 @@ class CustomDropsHandler { info.addDebugMessage( "&8 - &7item: &b${newItem.type.name}&7, amount: &b${dropBase.amountAsString}&7, newAmount: &b$newDropAmount&7, " + - "chance: &b{dropBase.chance?.showMatchedChance()}&7, chanceRole: " + + "chance: &b${dropBase.chance?.showMatchedChance()}&7, chanceRole: " + "&b${Utils.round(chanceRole.toDouble(), 4)}&7, dropped: &btrue&7$retryMsg." ) } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/DeathCause.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/DeathCause.kt index 030d024b3..6a12759f4 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/DeathCause.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/DeathCause.kt @@ -40,4 +40,5 @@ enum class DeathCause { VOID, WITHER, PLAYER_CAUSED, + CAMPFIRE } \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/LevelledMobSpawnReason.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/LevelledMobSpawnReason.kt index 72399ad9a..b00261805 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/LevelledMobSpawnReason.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/enums/LevelledMobSpawnReason.kt @@ -49,5 +49,6 @@ enum class LevelledMobSpawnReason { SPELL, LM_SUMMON, DEFAULT, - DUPLICATION + DUPLICATION, + TRIAL_SPAWNER } \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/ChunkLoadListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/ChunkLoadListener.kt index fb07e8224..8eddbfc4a 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/ChunkLoadListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/ChunkLoadListener.kt @@ -41,10 +41,9 @@ class ChunkLoadListener : Listener { } private fun checkEntity(livingEntity: LivingEntity, event: ChunkLoadEvent) { - val main = LevelledMobs.instance + val lmEntity = LivingEntityWrapper.getInstance(livingEntity) val wrapper = SchedulerWrapper(livingEntity){ - val lmEntity = LivingEntityWrapper.getInstance(livingEntity) - if (main.levelManager.doCheckMobHash && Utils.checkIfMobHashChanged(lmEntity)) { + if (LevelledMobs.instance.levelManager.doCheckMobHash && Utils.checkIfMobHashChanged(lmEntity)) { lmEntity.reEvaluateLevel = true lmEntity.isRulesForceAll = true lmEntity.wasPreviouslyLevelled = lmEntity.isLevelled @@ -53,10 +52,12 @@ class ChunkLoadListener : Listener { return@SchedulerWrapper } - main.mobsQueueManager.addToQueue(QueueItem(lmEntity, event)) + LevelledMobs.instance.mobsQueueManager.addToQueue(QueueItem(lmEntity, event)) lmEntity.free() } + lmEntity.buildCacheIfNeeded() + lmEntity.inUseCount.getAndIncrement() wrapper.runDirectlyInBukkit = true wrapper.run() } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDamageListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDamageListener.kt index c02dd8eb4..73d147d78 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDamageListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityDamageListener.kt @@ -67,9 +67,7 @@ class EntityDamageListener : Listener { } val theHitter = LivingEntityWrapper.getInstance(event.damager as LivingEntity) - val nametagVisibilityEnums = LevelledMobs.instance.rulesManager.getRuleCreatureNametagVisbility( - theHitter - ) + val nametagVisibilityEnums = theHitter.nametagVisibilityEnum val nametagVisibleTime = theHitter.getNametagCooldownTime() if (nametagVisibleTime > 0L && @@ -106,9 +104,7 @@ class EntityDamageListener : Listener { lmEntity.associatedPlayer = (event.damager as Player) } } - val nametagVisibilityEnums = lmEntity.main.rulesManager.getRuleCreatureNametagVisbility( - lmEntity - ) + val nametagVisibilityEnums = lmEntity.nametagVisibilityEnum val nametagVisibleTime = lmEntity.getNametagCooldownTime() if (nametagVisibleTime > 0L && wasDamagedByEntity && @@ -171,10 +167,7 @@ class EntityDamageListener : Listener { val lmEntity = LivingEntityWrapper.getInstance(event.entity as LivingEntity) MobDataManager.populateAttributeCache(lmEntity) - if (lmEntity.isLevelled && lmEntity.main.rulesManager.getRuleCreatureNametagVisbility( - lmEntity - ).contains(NametagVisibilityEnum.ATTACKED) - ) { + if (lmEntity.isLevelled && (lmEntity.nametagVisibilityEnum).contains(NametagVisibilityEnum.ATTACKED)) { if (lmEntity.playersNeedingNametagCooldownUpdate == null) { lmEntity.playersNeedingNametagCooldownUpdate = java.util.HashSet() } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityPickupItemListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityPickupItemListener.kt index 2de49987d..670d92272 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityPickupItemListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityPickupItemListener.kt @@ -37,7 +37,10 @@ class EntityPickupItemListener : Listener { val pickedUpEquipment = PickedUpEquipment(lmEntity) val wrapper = SchedulerWrapper(lmEntity.livingEntity) { pickedUpEquipment.checkEquipment(itemStack) + lmEntity.free() } + + lmEntity.inUseCount.getAndIncrement() wrapper.runDelayed(1L) } } \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt index bbd708311..b6ca67cfb 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntitySpawnListener.kt @@ -55,6 +55,7 @@ class EntitySpawnListener : Listener{ lmEntity.skylightLevel = lmEntity.currentSkyLightLevel lmEntity.isNewlySpawned = true lmEntity.populateShowShowLMNametag() + lmEntity.buildCacheIfNeeded() MobDataManager.populateAttributeCache(lmEntity, null) if (event is CreatureSpawnEvent) { @@ -447,9 +448,7 @@ class EntitySpawnListener : Listener{ ) lmEntity.playerForLevelling = closestPlayer - val nametagVisibilityEnums = main.rulesManager.getRuleCreatureNametagVisbility( - lmEntity - ) + val nametagVisibilityEnums = lmEntity.nametagVisibilityEnum if (nametagVisibilityEnums.contains(NametagVisibilityEnum.TARGETED) && lmEntity.livingEntity.hasLineOfSight(closestPlayer) ) { diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityTargetListener.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityTargetListener.kt index 484639896..b906598de 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityTargetListener.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/listeners/EntityTargetListener.kt @@ -60,9 +60,7 @@ class EntityTargetListener : Listener { return } - if (main.rulesManager.getRuleCreatureNametagVisbility(lmEntity) - .contains(NametagVisibilityEnum.TRACKING) - ) { + if (lmEntity.nametagVisibilityEnum.contains(NametagVisibilityEnum.TRACKING)) { synchronized(NametagTimerChecker.entityTarget_Lock) { main.nametagTimerChecker.entityTargetMap.put( lmEntity.livingEntity, diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt index 204182321..968658576 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt @@ -258,6 +258,10 @@ class LevelManager : LevelInterface2 { val evalResult = MobDataManager.evaluateExpression(formula) if (evalResult.hadError){ NotifyManager.notifyOfError("Error evaluating formula for construct-level on mob: ${lmEntity.nameIfBaby}, ${evalResult.error}") + DebugManager.log(DebugType.CONSTRUCT_LEVEL, lmEntity){ + "result (error, ${evalResult.error})\n" + + " formulaPre: '$formulaPre'\n" + + " formula: '$formula'" } throw EvaluationException() } @@ -1238,9 +1242,7 @@ class LevelManager : LevelInterface2 { if (!lmEntity.isPopulated) { return } - val nametagVisibilityEnums = main.rulesManager.getRuleCreatureNametagVisbility( - lmEntity - ) + val nametagVisibilityEnums = lmEntity.nametagVisibilityEnum val nametagVisibleTime = lmEntity.getNametagCooldownTime() if (nametagVisibleTime > 0L && nametagVisibilityEnums.contains(NametagVisibilityEnum.TARGETED) && diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/NametagQueueManager.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/NametagQueueManager.kt index becc2ff76..63341ec48 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/NametagQueueManager.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/NametagQueueManager.kt @@ -69,16 +69,9 @@ class NametagQueueManager { fun addToQueue(item: QueueItem) { if (!item.lmEntity.shouldShowLMNametag) return - - if (Bukkit.getOnlinePlayers().isEmpty()) { + if (Bukkit.getOnlinePlayers().isEmpty()) return + if (item.lmEntity.nametagVisibilityEnum.contains(NametagVisibilityEnum.DISABLED)) return - } - - if (LevelledMobs.instance.rulesManager.getRuleCreatureNametagVisbility(item.lmEntity) - .contains(NametagVisibilityEnum.DISABLED) - ) { - return - } item.lmEntity.inUseCount.getAndIncrement() queue.offer(item) @@ -225,9 +218,7 @@ class NametagQueueManager { for (i in 0 until loopCount) { // will loop again to update with nametag cooldown for only the specified players - val nametagVisibilityEnum = LevelledMobs.instance.rulesManager.getRuleCreatureNametagVisbility( - lmEntity - ) + val nametagVisibilityEnum = lmEntity.nametagVisibilityEnum val doAlwaysVisible = i == 1 || !nametag.isNullOrEmpty && lmEntity.livingEntity.isCustomNameVisible || nametagVisibilityEnum.contains(NametagVisibilityEnum.ALWAYS_ON) diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/NametagTimerChecker.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/NametagTimerChecker.kt index ca807c471..07974871a 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/NametagTimerChecker.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/NametagTimerChecker.kt @@ -121,9 +121,7 @@ class NametagTimerChecker { if (timeDuration.toMillis() >= cooldownTime) { // if using LoS targeting check if it's still within LoS and don't remove if so. val lmEntity = LivingEntityWrapper.getInstance(livingEntity) - val usesLoS: Boolean = LevelledMobs.instance.rulesManager.getRuleCreatureNametagVisbility( - lmEntity - ).contains(NametagVisibilityEnum.TARGETED) + val usesLoS = lmEntity.nametagVisibilityEnum.contains(NametagVisibilityEnum.TARGETED) if (usesLoS && livingEntity.hasLineOfSight(player)) { coolDown.value[livingEntity] = Instant.now() diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/PickedUpEquipment.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/PickedUpEquipment.kt index f5c720626..9da355482 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/PickedUpEquipment.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/misc/PickedUpEquipment.kt @@ -35,8 +35,6 @@ class PickedUpEquipment( if (slotNumber >= 0) { storeItemInPDC(slotNumber) } - - lmEntity.free() } fun getMobPickedUpItems(): MutableList { diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RuleInfo.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RuleInfo.kt index f9dd80457..7748eef07 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RuleInfo.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RuleInfo.kt @@ -4,13 +4,13 @@ import io.github.arcaneplugins.levelledmobs.annotations.DoNotMerge import io.github.arcaneplugins.levelledmobs.annotations.DoNotShow import io.github.arcaneplugins.levelledmobs.annotations.ExcludeFromHash import io.github.arcaneplugins.levelledmobs.annotations.RuleFieldInfo +import io.github.arcaneplugins.levelledmobs.enums.ExternalCompatibility import io.github.arcaneplugins.levelledmobs.enums.LevelledMobSpawnReason import io.github.arcaneplugins.levelledmobs.enums.MobCustomNameStatus import io.github.arcaneplugins.levelledmobs.enums.MobTamedStatus import io.github.arcaneplugins.levelledmobs.enums.NametagVisibilityEnum import io.github.arcaneplugins.levelledmobs.enums.RuleType import io.github.arcaneplugins.levelledmobs.enums.VanillaBonusEnum -import io.github.arcaneplugins.levelledmobs.enums.ExternalCompatibility import io.github.arcaneplugins.levelledmobs.misc.CachedModalList import io.github.arcaneplugins.levelledmobs.rules.strategies.CustomStrategy import io.github.arcaneplugins.levelledmobs.rules.strategies.LevellingStrategy @@ -19,12 +19,7 @@ import java.util.TreeMap import org.bukkit.Particle import org.bukkit.block.Biome import org.bukkit.generator.structure.Structure -import kotlin.reflect.KMutableProperty -import kotlin.reflect.KProperty1 -import kotlin.reflect.KVisibility -import kotlin.reflect.full.declaredMemberProperties -import kotlin.reflect.full.findAnnotation -import kotlin.reflect.full.hasAnnotation + /** * Holds rules parsed from rules.yml to make up a list of rules @@ -37,149 +32,149 @@ class RuleInfo( @DoNotMerge @ExcludeFromHash @DoNotShow internal var ruleName: String = "Unnamed" ) { - @DoNotMerge @DoNotShow + @field:DoNotMerge @field:DoNotShow var ruleIsEnabled = true - @RuleFieldInfo("construct level", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("construct level", RuleType.APPLY_SETTING) var constructLevel: String? = null - @DoNotMerge @ExcludeFromHash @RuleFieldInfo("is temp disabled", RuleType.MISC) + @field:DoNotMerge @field:ExcludeFromHash @field:RuleFieldInfo("is temp disabled", RuleType.MISC) var isTempDisabled = false - @ExcludeFromHash @RuleFieldInfo("use no spawner particles", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("use no spawner particles", RuleType.APPLY_SETTING) var useNoSpawnerParticles = false - @RuleFieldInfo("baby mobs inherit adult settings", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("baby mobs inherit adult settings", RuleType.APPLY_SETTING) var babyMobsInheritAdultSetting: Boolean? = null - @RuleFieldInfo("mob level inheritance", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("mob level inheritance", RuleType.APPLY_SETTING) var mobLevelInheritance: Boolean? = null - @ExcludeFromHash @RuleFieldInfo("use custom drops", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("use custom drops", RuleType.APPLY_SETTING) var customDropsUseForMobs: Boolean? = null - @RuleFieldInfo("stop proessing rules", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("stop proessing rules", RuleType.APPLY_SETTING) var stopProcessingRules: Boolean? = null - @ExcludeFromHash @DoNotShow + @field:ExcludeFromHash @field:DoNotShow var mergeEntityNameOverrides: Boolean? = null - @RuleFieldInfo("passenger match level", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("passenger match level", RuleType.APPLY_SETTING) var passengerMatchLevel: Boolean? = null - @ExcludeFromHash @RuleFieldInfo("lock entity", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("lock entity", RuleType.APPLY_SETTING) var lockEntity: Boolean? = null - @ExcludeFromHash @RuleFieldInfo("spawner particles count", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("spawner particles count", RuleType.APPLY_SETTING) var spawnerParticlesCount: Int? = null @RuleFieldInfo("max random variance", RuleType.STRATEGY) var maxRandomVariance: Int? = null - @ExcludeFromHash @RuleFieldInfo("creeper max damage radius", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("creeper max damage radius", RuleType.APPLY_SETTING) var creeperMaxDamageRadius: Int? = null - @RuleFieldInfo("minlevel", RuleType.CONDITION) + @field:RuleFieldInfo("minlevel", RuleType.CONDITION) var conditionsMinLevel: Int? = null - @RuleFieldInfo("maxlevel", RuleType.CONDITION) + @field:RuleFieldInfo("maxlevel", RuleType.CONDITION) var conditionsMaxLevel: Int? = null - @RuleFieldInfo("minlevel", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("minlevel", RuleType.APPLY_SETTING) var restrictionsMinLevel: Int? = null - @RuleFieldInfo("maxlevel", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("maxlevel", RuleType.APPLY_SETTING) var restrictionsMaxLevel: Int? = null - @RuleFieldInfo("apply above Y", RuleType.CONDITION) + @field:RuleFieldInfo("apply above Y", RuleType.CONDITION) var conditionsApplyAboveY: Int? = null - @RuleFieldInfo("apply below Y", RuleType.CONDITION) + @field:RuleFieldInfo("apply below Y", RuleType.CONDITION) var conditionsApplyBelowY: Int? = null - @RuleFieldInfo("min distance from spawn", RuleType.CONDITION) + @field:RuleFieldInfo("min distance from spawn", RuleType.CONDITION) var conditionsMinDistanceFromSpawn: Int? = null - @RuleFieldInfo("max distance from spawn", RuleType.CONDITION) + @field:RuleFieldInfo("max distance from spawn", RuleType.CONDITION) var conditionsMaxDistanceFromSpawn: Int? = null - @ExcludeFromHash @RuleFieldInfo("nametag visible time", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("nametag visible time", RuleType.APPLY_SETTING) var nametagVisibleTime: Long? = null - @ExcludeFromHash @RuleFieldInfo("max death in chunk threshold", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("max death in chunk threshold", RuleType.APPLY_SETTING) var maximumDeathInChunkThreshold: Int? = null - @ExcludeFromHash @RuleFieldInfo("chunk max cooldown time", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("chunk max cooldown time", RuleType.APPLY_SETTING) var chunkMaxCoolDownTime: Int? = null - @ExcludeFromHash @RuleFieldInfo("max adjacent chunks", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("max adjacent chunks", RuleType.APPLY_SETTING) var maxAdjacentChunks: Int? = null - @ExcludeFromHash @RuleFieldInfo("cooldown time", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("cooldown time", RuleType.APPLY_SETTING) var conditionsCooldownTime: Long? = null - @ExcludeFromHash @RuleFieldInfo("times to cooldown activation", RuleType.CONDITION) + @field:ExcludeFromHash @field:RuleFieldInfo("times to cooldown activation", RuleType.CONDITION) var conditionsTimesToCooldownActivation: Int? = null - @ExcludeFromHash @RuleFieldInfo("rule chance", RuleType.CONDITION) + @field:ExcludeFromHash @field:RuleFieldInfo("rule chance", RuleType.CONDITION) var conditionsChance: Float? = null - @ExcludeFromHash @RuleFieldInfo("sunlight burn amount", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("sunlight burn amount", RuleType.APPLY_SETTING) var sunlightBurnAmount: Double? = null - @ExcludeFromHash @RuleFieldInfo("nametag", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("nametag", RuleType.APPLY_SETTING) var nametag: String? = null - @ExcludeFromHash @RuleFieldInfo("creature death nametag", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("creature death nametag", RuleType.APPLY_SETTING) var nametagCreatureDeath: String? = null - @ExcludeFromHash @RuleFieldInfo("nametag placeholder levelled", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("nametag placeholder levelled", RuleType.APPLY_SETTING) var nametagPlaceholderLevelled: String? = null - @ExcludeFromHash @RuleFieldInfo("nametag placeholder unlevelled", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("nametag placeholder unlevelled", RuleType.APPLY_SETTING) var nametagPlaceholderUnlevelled: String? = null - @DoNotMerge @ExcludeFromHash @DoNotShow + @field:DoNotMerge @field:ExcludeFromHash @field:DoNotShow var presetName: String? = null - @ExcludeFromHash @RuleFieldInfo("drop table ids", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("drop table ids", RuleType.APPLY_SETTING) val customDropDropTableIds = mutableListOf() - @ExcludeFromHash @RuleFieldInfo("health indicator", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("health indicator", RuleType.APPLY_SETTING) var healthIndicator: HealthIndicator? = null - @RuleFieldInfo("mob customname", RuleType.CONDITION) + @field:RuleFieldInfo("mob customname", RuleType.CONDITION) var conditionsMobCustomnameStatus = MobCustomNameStatus.NOT_SPECIFIED - @RuleFieldInfo("mob tamed status", RuleType.CONDITION) + @field:RuleFieldInfo("mob tamed status", RuleType.CONDITION) var conditionsMobTamedStatus = MobTamedStatus.NOT_SPECIFIED - @RuleFieldInfo("levelling strategy", RuleType.STRATEGY) + @field:RuleFieldInfo("levelling strategy", RuleType.STRATEGY) val levellingStrategy = mutableMapOf() - @RuleFieldInfo("custom strategy", RuleType.STRATEGY) + @field:RuleFieldInfo("custom strategy", RuleType.STRATEGY) val customStrategy: MutableMap = TreeMap(String.CASE_INSENSITIVE_ORDER) - @ExcludeFromHash @RuleFieldInfo("entity name overrides with level", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("entity name overrides with level", RuleType.APPLY_SETTING) var entityNameOverridesLevel: MutableMap>? = null - @ExcludeFromHash @RuleFieldInfo("entity name overrides", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("entity name overrides", RuleType.APPLY_SETTING) var entityNameOverrides: MutableMap? = null - @ExcludeFromHash @RuleFieldInfo("custom death messages", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("custom death messages", RuleType.APPLY_SETTING) var deathMessages: DeathMessages? = null - @ExcludeFromHash @RuleFieldInfo("nametag visibility options", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("nametag visibility options", RuleType.APPLY_SETTING) var nametagVisibilityEnum: MutableList? = null - @DoNotMerge @ExcludeFromHash @DoNotShow + @field:DoNotMerge @field:ExcludeFromHash @field:DoNotShow val ruleSourceNames = mutableMapOf() - @ExcludeFromHash @RuleFieldInfo("spawner particle", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("spawner particle", RuleType.APPLY_SETTING) var spawnerParticle: Particle? = null - @ExcludeFromHash @RuleFieldInfo("tiered coloring info", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("tiered coloring info", RuleType.APPLY_SETTING) var tieredColoringInfos: MutableList? = null - @ExcludeFromHash @RuleFieldInfo("enabled compatibilities", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("enabled compatibilities", RuleType.APPLY_SETTING) var enabledExtCompats: MutableMap? = null - @RuleFieldInfo("mob nbt data", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("mob nbt data", RuleType.APPLY_SETTING) var mobNBTData: MergeableStringList? = null - @RuleFieldInfo("skylight level", RuleType.CONDITION) + @field:RuleFieldInfo("skylight level", RuleType.CONDITION) var conditionsSkyLightLevel: MinAndMax? = null - @RuleFieldInfo("allowed worlds", RuleType.CONDITION) + @field:RuleFieldInfo("allowed worlds", RuleType.CONDITION) var conditionsWorlds: CachedModalList? = null - @RuleFieldInfo("allowed entities", RuleType.CONDITION) + @field:RuleFieldInfo("allowed entities", RuleType.CONDITION) var conditionsEntities: CachedModalList? = null - @RuleFieldInfo("allowed biomes", RuleType.CONDITION) + @field:RuleFieldInfo("allowed biomes", RuleType.CONDITION) var conditionsBiomes: CachedModalList? = null - @RuleFieldInfo("external plugins", RuleType.CONDITION) + @field:RuleFieldInfo("external plugins", RuleType.CONDITION) var conditionsExternalPlugins: CachedModalList? = null - @RuleFieldInfo("custom names", RuleType.CONDITION) + @field:RuleFieldInfo("custom names", RuleType.CONDITION) var conditionsCustomNames: CachedModalList? = null - @RuleFieldInfo("no drop entities", RuleType.CONDITION) + @field:RuleFieldInfo("no drop entities", RuleType.CONDITION) var conditionsNoDropEntities: CachedModalList? = null - @RuleFieldInfo("worldguard regions", RuleType.CONDITION) + @field:RuleFieldInfo("worldguard regions", RuleType.CONDITION) var conditionsWGregions: CachedModalList? = null - @RuleFieldInfo("worldguard region owners", RuleType.CONDITION) + @field:RuleFieldInfo("worldguard region owners", RuleType.CONDITION) var conditionsWGregionOwners: CachedModalList? = null - @RuleFieldInfo("mythic mobs names", RuleType.CONDITION) + @field:RuleFieldInfo("mythic mobs names", RuleType.CONDITION) var conditionsMMnames: CachedModalList? = null - @RuleFieldInfo("spawner names", RuleType.CONDITION) + @field:RuleFieldInfo("spawner names", RuleType.CONDITION) var conditionsSpawnerNames: CachedModalList? = null - @RuleFieldInfo("spawner egg names", RuleType.CONDITION) + @field:RuleFieldInfo("spawner egg names", RuleType.CONDITION) var conditionsSpawnegEggNames: CachedModalList? = null - @RuleFieldInfo("scoreboard tags", RuleType.CONDITION) + @field:RuleFieldInfo("scoreboard tags", RuleType.CONDITION) var conditionsScoreboardTags: CachedModalList? = null - @RuleFieldInfo("world tick time", RuleType.CONDITION) + @field:RuleFieldInfo("world tick time", RuleType.CONDITION) var conditionsWorldTickTime: CachedModalList? = null - @RuleFieldInfo("vanilla bonuses", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("vanilla bonuses", RuleType.APPLY_SETTING) var vanillaBonuses: CachedModalList? = null - @RuleFieldInfo("spawn reasons", RuleType.CONDITION) + @field:RuleFieldInfo("spawn reasons", RuleType.CONDITION) var conditionsSpawnReasons: CachedModalList? = null - @RuleFieldInfo("structures", RuleType.CONDITION) + @field:RuleFieldInfo("structures", RuleType.CONDITION) var conditionsStructure: CachedModalList? = null - @RuleFieldInfo("player permissions", RuleType.CONDITION) + @field:RuleFieldInfo("player permissions", RuleType.CONDITION) var conditionsPermission: CachedModalList? = null - @RuleFieldInfo("within coordinates", RuleType.CONDITION) + @field:RuleFieldInfo("within coordinates", RuleType.CONDITION) var conditionsWithinCoords: WithinCoordinates? = null - @RuleFieldInfo("all mob multipliers", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("all mob multipliers", RuleType.APPLY_SETTING) var allMobMultipliers: FineTuningAttributes? = null - @RuleFieldInfo("mob specific multipliers", RuleType.APPLY_SETTING) + @field:RuleFieldInfo("mob specific multipliers", RuleType.APPLY_SETTING) var specificMobMultipliers: MutableMap? = null - @ExcludeFromHash @RuleFieldInfo("chunk kill options", RuleType.APPLY_SETTING) + @field:ExcludeFromHash @field:RuleFieldInfo("chunk kill options", RuleType.APPLY_SETTING) var chunkKillOptions: ChunkKillOptions? = null fun mergePresetRules(preset: RuleInfo?) { @@ -188,15 +183,18 @@ class RuleInfo( } try { - for (p in preset::class.declaredMemberProperties) { - if (p.visibility == KVisibility.PRIVATE) continue - if (p.hasAnnotation()) continue - var presetValue = p.getter.call(preset) ?: continue - val ruleValue = p.getter.call(this) + for (f in preset::javaClass.get().declaredFields) { + f.trySetAccessible() + + if (f.isAnnotationPresent(DoNotMerge::class.java)) continue + if (f.get(preset) == null) continue + + var presetValue = f.get(preset) + val ruleValue = this::javaClass.get().getDeclaredField(f.name).get(this) var skipSettingValue = false val mergableRule = presetValue as? MergableRule - if (p.name == "entityNameOverrides" && this.entityNameOverrides != null && presetValue is MutableMap<*, *>) { + if (f.name == "entityNameOverrides" && this.entityNameOverrides != null && presetValue is MutableMap<*, *>) { entityNameOverrides!!.putAll(presetValue as MutableMap) skipSettingValue = true } else if (mergableRule != null) { @@ -206,12 +204,12 @@ class RuleInfo( } else { presetValue = mergableRule.cloneItem() } - } else if (p.name == "entityNameOverrides_Level" && this.entityNameOverridesLevel != null) { + } else if (f.name == "entityNameOverrides_Level" && this.entityNameOverridesLevel != null) { entityNameOverridesLevel!!.putAll( presetValue as MutableMap> ) skipSettingValue = true - } else if (p.name == "specificMobMultipliers") { + } else if (f.name == "specificMobMultipliers") { val mergingPreset = presetValue as MutableMap if (this.specificMobMultipliers == null) { this.specificMobMultipliers = mutableMapOf() @@ -222,7 +220,7 @@ class RuleInfo( } skipSettingValue = true - } else if (p.name == "customDrop_DropTableIds") { + } else if (f.name == "customDropDropTableIds") { val mergingPreset = presetValue as MutableList customDropDropTableIds.addAll(mergingPreset) @@ -243,12 +241,13 @@ class RuleInfo( if (thisCachedModalList != null && presetValue.doMerge) { thisCachedModalList.mergeCachedModal(presetValue) } else { - updatePropertyValue(p, presetValue.clone()) + this::javaClass.get().getDeclaredField(f.name).set(this, presetValue) + //updatePropertyValue(p, presetValue.clone()) } skipSettingValue = true } - if (p.name == "levellingStrategy") { + if (f.name == "levellingStrategy") { val mergingStrategies = presetValue as MutableMap for (strategy in mergingStrategies){ @@ -260,7 +259,7 @@ class RuleInfo( skipSettingValue = true } - if (p.name == "customStrategy"){ + if (f.name == "customStrategy"){ val mergingStrategies = presetValue as MutableMap if (mergingStrategies.isNotEmpty()){ @@ -292,23 +291,15 @@ class RuleInfo( } if (!skipSettingValue) { - updatePropertyValue(p, presetValue) + this::javaClass.get().getDeclaredField(f.name).set(this, presetValue) } - ruleSourceNames[p.name] = preset.ruleName + ruleSourceNames[f.name] = preset.ruleName } } catch (e: IllegalAccessException) { e.printStackTrace() } } - private fun updatePropertyValue( - property: KProperty1<*, *>, - newValue: Any? - ) { - if (property is KMutableProperty<*>) - property.setter.call(this, newValue) - } - data class RuleSortingInfo( val ruleType: RuleType, val fieldName: String @@ -340,14 +331,18 @@ class RuleInfo( sb.append("&r") try { - for (f in this::class.declaredMemberProperties) { - if (f.visibility == KVisibility.PRIVATE) continue - if (isForHash && f.findAnnotation() != null) continue - if (!isForHash && f.hasAnnotation()) continue - val value = f.getter.call(this) ?: continue + for (f in this::javaClass.get().declaredFields) { + if (isForHash && f.isAnnotationPresent(ExcludeFromHash::class.java)) { + continue + } + if (!isForHash && f.isAnnotationPresent(DoNotShow::class.java)) { + continue + } + + val value = f.get(this) ?: continue var ruleName = f.name var ruleInfoType = RuleType.MISC - val ruleTypeInfo = f.findAnnotation() + val ruleTypeInfo = f.getAnnotation(RuleFieldInfo::class.java) if (ruleTypeInfo != null) { ruleInfoType = ruleTypeInfo.ruleType ruleName = ruleTypeInfo.value diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesManager.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesManager.kt index b7faaf2e2..fc8ed1fac 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesManager.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesManager.kt @@ -512,11 +512,7 @@ class RulesManager { result = ruleInfo.nametagVisibilityEnum } } - } catch (e: ConcurrentModificationException) { - Log.war( - "Got ConcurrentModificationException in getRule_CreatureNametagVisbility" - ) - } + } catch (_: ConcurrentModificationException) { } return if (result.isNullOrEmpty()) { mutableListOf(NametagVisibilityEnum.MELEE) diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt index 834809c17..bcab431b5 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt @@ -1095,22 +1095,30 @@ class RulesParser { val ymlHelper2 = YmlParsingHelper(csSpawnDistance) val spawnDistanceStrategy = SpawnDistanceStrategy() - spawnDistanceStrategy.increaseLevelDistance = ymlHelper2.getFloat2( - "ringed-tiers", spawnDistanceStrategy.increaseLevelDistance + spawnDistanceStrategy.ringedTiers = ymlHelper2.getFloat2( + "ringed-tiers", spawnDistanceStrategy.ringedTiers ) - spawnDistanceStrategy.startDistance = ymlHelper2.getFloat2( - "buffer-distance", spawnDistanceStrategy.startDistance + spawnDistanceStrategy.bufferDistance = ymlHelper2.getFloat2( + "buffer-distance", spawnDistanceStrategy.bufferDistance + ) + spawnDistanceStrategy.enableHeightMod = ymlHelper2.getBoolean2( + "enable-height-modifier", spawnDistanceStrategy.enableHeightMod + ) + spawnDistanceStrategy.transitionYheight = ymlHelper2.getFloat2( + "transition-y-height", spawnDistanceStrategy.transitionYheight + ) + spawnDistanceStrategy.lvlMultiplier = ymlHelper2.getFloat2( + "level-multiplier", spawnDistanceStrategy.lvlMultiplier + ) + spawnDistanceStrategy.yHeightPeriod = ymlHelper2.getFloat2( + "y-height-period", spawnDistanceStrategy.yHeightPeriod + ) + spawnDistanceStrategy.scaleDownward = ymlHelper2.getBoolean2( + "scale-increase-downward", spawnDistanceStrategy.scaleDownward ) parseOptionalSpawnCoordinate(csSpawnDistance, spawnDistanceStrategy) - if (ymlHelper2.getString( "blended-levelling") != null) { - parseBlendedLevelling( - YmlParsingHelper.objToCS(csSpawnDistance, "blended-levelling"), - spawnDistanceStrategy - ) - } - if (parsingInfo.levellingStrategy.containsKey(StrategyType.SPAWN_DISTANCE)) parsingInfo.levellingStrategy[StrategyType.SPAWN_DISTANCE]!!.mergeRule(spawnDistanceStrategy) else @@ -1397,30 +1405,6 @@ class RulesParser { options.defaultLevelTier = defaultTier } - private fun parseBlendedLevelling( - cs: ConfigurationSection?, - spawnDistanceStrategy: SpawnDistanceStrategy - ) { - if (cs == null) return - - val ymlHelper = YmlParsingHelper(cs) - spawnDistanceStrategy.blendedLevellingEnabled = ymlHelper.getBoolean2( - "enabled", spawnDistanceStrategy.blendedLevellingEnabled - ) - spawnDistanceStrategy.transitionYheight = ymlHelper.getFloat2( - "transition-y-height", spawnDistanceStrategy.transitionYheight - ) - spawnDistanceStrategy.lvlMultiplier = ymlHelper.getFloat2( - "level-multiplier", spawnDistanceStrategy.lvlMultiplier - ) - spawnDistanceStrategy.multiplierPeriod = ymlHelper.getFloat2( - "y-height-period", spawnDistanceStrategy.multiplierPeriod - ) - spawnDistanceStrategy.scaleDownward = ymlHelper.getBoolean2( - "scale-increase-downward", spawnDistanceStrategy.scaleDownward - ) - } - private fun parseOptionalSpawnCoordinate( cs: ConfigurationSection, sds: SpawnDistanceStrategy @@ -1428,11 +1412,11 @@ class RulesParser { val spawnLocation = YmlParsingHelper.objToCS(cs, "origin-coordinates") ?: return if (!"spawn".equals(spawnLocation.getString("x"), ignoreCase = true)) { - sds.spawnLocationX = spawnLocation.getDouble("x").toFloat() + sds.originCoordX = spawnLocation.getDouble("x").toFloat() } if (!"spawn".equals(spawnLocation.getString("z"), ignoreCase = true)) { - sds.spawnLocationZ = spawnLocation.getDouble("z").toFloat() + sds.originCoordZ = spawnLocation.getDouble("z").toFloat() } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/WithinCoordinates.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/WithinCoordinates.kt index 3c6afcb19..f8628b1ca 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/WithinCoordinates.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/WithinCoordinates.kt @@ -1,8 +1,7 @@ package io.github.arcaneplugins.levelledmobs.rules +import io.github.arcaneplugins.levelledmobs.annotations.DoNotShow import io.github.arcaneplugins.levelledmobs.util.Utils.isInteger -import kotlin.reflect.KVisibility -import kotlin.reflect.full.declaredMemberProperties /** * Specifies a region based on coordinates that can be @@ -18,9 +17,9 @@ class WithinCoordinates { var endX: Int? = null var endY: Int? = null var endZ: Int? = null - private var infinityDirectionX = InfinityDirection.NONE - private var infinityDirectionY = InfinityDirection.NONE - private var infinityDirectionZ = InfinityDirection.NONE + @DoNotShow private var infinityDirectionX = InfinityDirection.NONE + @DoNotShow private var infinityDirectionY = InfinityDirection.NONE + @DoNotShow private var infinityDirectionZ = InfinityDirection.NONE fun parseAxis( number: String?, @@ -66,11 +65,13 @@ class WithinCoordinates { val isEmpty: Boolean get() { - for (p in this::class.declaredMemberProperties) { - if (p.visibility == KVisibility.PRIVATE) continue + for (f in this::class.java.declaredFields) { + f.trySetAccessible() + + if (f.isAnnotationPresent(DoNotShow::class.java)) continue try { - if (p.getter.call(this) != null) return false + if (f.get(this) != null) return false } catch (e: IllegalAccessException) { e.printStackTrace() } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/SpawnDistanceStrategy.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/SpawnDistanceStrategy.kt index 840b817b9..1bb2391f7 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/SpawnDistanceStrategy.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/strategies/SpawnDistanceStrategy.kt @@ -1,8 +1,9 @@ package io.github.arcaneplugins.levelledmobs.rules.strategies -import java.lang.reflect.Modifier import java.util.concurrent.ThreadLocalRandom import io.github.arcaneplugins.levelledmobs.LevelledMobs +import io.github.arcaneplugins.levelledmobs.debug.DebugManager +import io.github.arcaneplugins.levelledmobs.debug.DebugType import io.github.arcaneplugins.levelledmobs.wrappers.LivingEntityWrapper import org.bukkit.Location import kotlin.math.ceil @@ -16,13 +17,13 @@ import kotlin.math.floor * @since 3.0.0 */ class SpawnDistanceStrategy : LevellingStrategy, Cloneable{ - var startDistance: Float? = null - var increaseLevelDistance: Float? = null - var spawnLocationX: Float? = null - var spawnLocationZ: Float? = null - var blendedLevellingEnabled: Boolean? = null + var bufferDistance: Float? = null + var ringedTiers: Float? = null + var originCoordX: Float? = null + var originCoordZ: Float? = null + var enableHeightMod: Boolean? = null var transitionYheight: Float? = null - var multiplierPeriod: Float? = null + var yHeightPeriod: Float? = null var lvlMultiplier: Float? = null var scaleDownward: Boolean? = null @@ -35,11 +36,11 @@ class SpawnDistanceStrategy : LevellingStrategy, Cloneable{ ): Float { var spawnLocation = lmEntity.world.spawnLocation - if (this.spawnLocationZ != null || this.spawnLocationX != null) { + if (this.originCoordZ != null || this.originCoordX != null) { val useX = - if (this.spawnLocationX == null) spawnLocation.x else spawnLocationX!!.toDouble() + if (this.originCoordX == null) spawnLocation.x else originCoordX!!.toDouble() val useZ = - if (this.spawnLocationZ == null) spawnLocation.x else spawnLocationZ!!.toDouble() + if (this.originCoordZ == null) spawnLocation.x else originCoordZ!!.toDouble() spawnLocation = Location( lmEntity.livingEntity.world, @@ -49,32 +50,42 @@ class SpawnDistanceStrategy : LevellingStrategy, Cloneable{ ) } - val startDistance = if (this.startDistance == null) 0f else startDistance!! + val bufferDistance = if (this.bufferDistance == null) 0f else bufferDistance!! val distanceFromSpawn = spawnLocation.distance(lmEntity.location).toFloat() - val levelDistance = ((distanceFromSpawn - startDistance)).coerceAtLeast(0f) + val levelDistance = (distanceFromSpawn - bufferDistance).coerceAtLeast(0f) val variance = LevelledMobs.instance.rulesManager.getRuleMaxRandomVariance(lmEntity) var varianceAdded = 0 if (variance != null) { varianceAdded = ThreadLocalRandom.current().nextInt(0, variance + 1) } - var increaseLevelDistance = - if (this.increaseLevelDistance == null) 1f else increaseLevelDistance!! - if (increaseLevelDistance == 0f) { - increaseLevelDistance = 1f + var ringedTiers = + if (this.ringedTiers == null) 1f else ringedTiers!! + if (ringedTiers == 0f) { + ringedTiers = 1f } //Get the level thats meant to be at a given distance - val spawnDistanceAssignment = - ((levelDistance / increaseLevelDistance) + varianceAdded) + var spawnDistanceAssignment = + ((levelDistance / ringedTiers) + varianceAdded) - if (this.blendedLevellingEnabled == null || !blendedLevellingEnabled!!) { + if (spawnDistanceAssignment.isNaN()){ + DebugManager.log(DebugType.STRATEGY_RESULT, lmEntity) { + "SpawnDistanceStrategy generated NaN, levelDistance: $levelDistance, increaseLevelDistance: $ringedTiers" + } + spawnDistanceAssignment = 0f + } + + if (!heightModIsEnabled) { return spawnDistanceAssignment } return generateBlendedLevel(lmEntity, spawnDistanceAssignment) } + private val heightModIsEnabled: Boolean + get() = enableHeightMod != null && enableHeightMod!! + override fun mergeRule(levellingStrategy: LevellingStrategy?) { if (levellingStrategy == null) return if (levellingStrategy is SpawnDistanceStrategy) { @@ -89,12 +100,8 @@ class SpawnDistanceStrategy : LevellingStrategy, Cloneable{ try { for (f in sds.javaClass.declaredFields) { - if (!Modifier.isPublic(f.modifiers)) { - continue - } - if (f[sds] == null) { - continue - } + if (f.name == "strategyType") continue + if (f[sds] == null) continue this.javaClass.getDeclaredField(f.name)[this] = f[sds] } @@ -107,36 +114,28 @@ class SpawnDistanceStrategy : LevellingStrategy, Cloneable{ override fun toString(): String { val sb = StringBuilder() - if (blendedLevellingEnabled != null && blendedLevellingEnabled!!) { + if (heightModIsEnabled) { sb.append( - String.format( - "blended, sd: %s, ild: %s, t_yHght: %s, mp: %s, lvlMlp: %s, scdown: %s", - if (startDistance == null) 0 else startDistance, - if (increaseLevelDistance == null) 0 else increaseLevelDistance, - if (transitionYheight == null) 0 else transitionYheight, - if (multiplierPeriod == null) 0 else multiplierPeriod, - if (lvlMultiplier == null) 0.0 else lvlMultiplier, - scaleDownward == null || scaleDownward!! - ) + "blended, dro: ${if (bufferDistance == null) 0 else bufferDistance}, " + + "rt: ${if (ringedTiers == null) 0 else ringedTiers}, " + + "t_yHght: ${if (transitionYheight == null) 0 else transitionYheight}, " + + "yhp: ${if (yHeightPeriod == null) 0 else yHeightPeriod}, " + + "lvlMlp: ${if (lvlMultiplier == null) 0.0 else lvlMultiplier}, " + + "scdown: ${scaleDownward == null || scaleDownward!!}" ) } else { sb.append( - String.format( - "spawn distance, sd: %s, ild: %s", - if (startDistance == null) 0 else startDistance, - if (increaseLevelDistance == null) 0 else increaseLevelDistance - ) + "spawn distance, dro: ${if (bufferDistance == null) 0 else bufferDistance}, " + + "rt: ${if (ringedTiers == null) 0 else ringedTiers}" ) } - if (this.spawnLocationX != null) { - sb.append(" x: ") - sb.append(this.spawnLocationX) + if (this.originCoordX != null) { + sb.append(" x: ").append(this.originCoordX) } - if (this.spawnLocationZ != null) { - sb.append(" z: ") - sb.append(this.spawnLocationZ) + if (this.originCoordZ != null) { + sb.append(" z: ").append(this.originCoordZ) } return sb.toString() @@ -150,21 +149,29 @@ class SpawnDistanceStrategy : LevellingStrategy, Cloneable{ var result: Float val transitionYHeight = if (this.transitionYheight == null) 0f else transitionYheight!!.toFloat() - val multiplierPeriod = if (this.multiplierPeriod == null) 0f else multiplierPeriod!!.toFloat() + val yHeightPeriod = if (this.yHeightPeriod == null) 0f else yHeightPeriod!!.toFloat() val lvlMultiplier = if (this.lvlMultiplier == null) 0f else lvlMultiplier!! result = if (this.scaleDownward == null || scaleDownward!!) { ((((transitionYHeight - currentYPos) / - multiplierPeriod) * lvlMultiplier) + yHeightPeriod) * lvlMultiplier) * spawnDistanceLevelAssignment) } else { ((((transitionYHeight - currentYPos) / - multiplierPeriod) * (lvlMultiplier * -1f)) + yHeightPeriod) * (lvlMultiplier * -1f)) * spawnDistanceLevelAssignment) } + if (result.isNaN()){ + DebugManager.log(DebugType.STRATEGY_RESULT, lmEntity) { + "BlendedLevel generated NaN, returning 0. transitionYHeight: $transitionYHeight, yPos: $currentYPos, " + + "yHeightPeriod: $yHeightPeriod, lvlMultiplier: $lvlMultiplier, sda: $spawnDistanceLevelAssignment" + } + result = 0f + } + result = - if (result < 0.0) ceil(result) + spawnDistanceLevelAssignment else floor(result) + spawnDistanceLevelAssignment + if (result < 0f) ceil(result) + spawnDistanceLevelAssignment else floor(result) + spawnDistanceLevelAssignment val variance = LevelledMobs.instance.rulesManager.getRuleMaxRandomVariance( lmEntity ) diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/LibsDisguisesUtils.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/LibsDisguisesUtils.kt index 10bc171c7..2af9ae04d 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/LibsDisguisesUtils.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/LibsDisguisesUtils.kt @@ -43,12 +43,12 @@ object LibsDisguisesUtils { if (!isMobUsingLibsDisguises(lmEntity)) return val disguise = lmEntity.libsDisguiseCache as Disguise - val le = lmEntity.livingEntity - - val wrapper = SchedulerWrapper(le) { + val wrapper = SchedulerWrapper(lmEntity.livingEntity) { disguise.watcher.customName = nametag + lmEntity.free() } + lmEntity.inUseCount.getAndIncrement() wrapper.run() } } \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/MiscUtils.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/MiscUtils.kt similarity index 97% rename from levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/MiscUtils.kt rename to levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/MiscUtils.kt index 5fb3d0316..07486b8d0 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/nametag/MiscUtils.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/MiscUtils.kt @@ -1,4 +1,4 @@ -package io.github.arcaneplugins.levelledmobs.nametag +package io.github.arcaneplugins.levelledmobs.util import io.github.arcaneplugins.levelledmobs.LevelledMobs import org.bukkit.entity.LivingEntity @@ -72,7 +72,7 @@ object MiscUtils { val tagsMap = tagsField.get(compoundTag) as MutableMap // NBTTagCompound.java - val bukkitValues = tagsMap["BukkitValues"] + val bukkitValues = tagsMap["BukkitValues"] ?: return results // private final Map tags; (again) val bukkitValuesMap = tagsField.get(bukkitValues) as MutableMap diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/QuickTimer.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/QuickTimer.kt index bb60f4a9c..03bb516ac 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/QuickTimer.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/QuickTimer.kt @@ -13,12 +13,6 @@ package io.github.arcaneplugins.levelledmobs.util class QuickTimer { private var startTime = 0L - constructor() - - constructor(startTime: Long){ - this.startTime = startTime - } - init { start() } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt index 776d8b8bf..0277ad7b7 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/wrappers/LivingEntityWrapper.kt @@ -14,6 +14,7 @@ import io.github.arcaneplugins.levelledmobs.misc.NamespacedKeys import io.github.arcaneplugins.levelledmobs.rules.ApplicableRulesResult import io.github.arcaneplugins.levelledmobs.rules.FineTuningAttributes import io.github.arcaneplugins.levelledmobs.enums.LevelledMobSpawnReason +import io.github.arcaneplugins.levelledmobs.enums.NametagVisibilityEnum import io.github.arcaneplugins.levelledmobs.rules.RuleInfo import io.github.arcaneplugins.levelledmobs.rules.strategies.StrategyType import io.github.arcaneplugins.levelledmobs.util.Log @@ -52,14 +53,12 @@ import org.bukkit.persistence.PersistentDataType class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), LivingEntityInterface { // privates: private var applicableGroups: MutableSet = TreeSet(String.CASE_INSENSITIVE_ORDER) - val mobExternalTypes: MutableSet = TreeSet(String.CASE_INSENSITIVE_ORDER) private var hasCache = false + private var isClearingData = false private var _livingEntity: LivingEntity? = null private var isBuildingCache = false private var groupsAreBuilt = false private var _shouldShowLMNametag: Boolean? = null - var chunkKillcount = 0 - var mobLevel: Int? = null private var _spawnedTimeOfDay: Int? = null private var _skylightLevelAtSpawn: Int? = null private var nametagCooldownTime = 0L @@ -67,14 +66,17 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv private var _sourceSpawnEggName: String? = null private val applicableRules = mutableListOf() private var spawnedWGRegions: List? = null - //private var fineTuningAttributes: FineTuningAttributes? = null private var _spawnReason: LevelledMobSpawnReason? = null - var prevChanceRuleResults: MutableMap? = null - private set + private var _nametagVisibilityEnum = mutableListOf() private val cacheLock = ReentrantLock() private val pdcLock = ReentrantLock() // publics: + var prevChanceRuleResults: MutableMap? = null + private set + var chunkKillcount = 0 + var mobLevel: Int? = null + val mobExternalTypes: MutableSet = TreeSet(String.CASE_INSENSITIVE_ORDER) var rangedDamage: Float? = null var attributeValuesCache: MutableMap? = null val strategyResults = mutableMapOf() @@ -105,9 +107,6 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv private val flyingMobNames = mutableListOf( "ALLAY", "BEE", "BLAZE", "ENDER_DRAGON", "VEX", "WITHER", "PARROT", "BAT" ) - private val aquaticMobs = mutableListOf( - "AXOLOTL", "DROWNED", "ELDER_GUARDIAN", "GUARDIAN", "FROG", "TURTLE" - ) fun getInstance( livingEntity: LivingEntity @@ -178,8 +177,10 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv } override fun clearEntityData() { + this.isClearingData = true this._livingEntity = null this.attributeValuesCache = null + this.nametagVisibilityEnum.clear() this.rangedDamage = null this.strategyResults.clear() this.customStrategyResults.clear() @@ -222,22 +223,16 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv this.lockedCustomDrops = null super.clearEntityData() + this.isClearingData = false } private fun buildCache() { - if (isBuildingCache || this.hasCache) { - return - } + if (this.hasCache) return try { - if (!cacheLock.tryLock(500, TimeUnit.MILLISECONDS)) { - Log.war("lock timed out building cache") - return - } + if (!cacheLock.tryLock(500, TimeUnit.MILLISECONDS)) return + if (this.hasCache) return - if (this.hasCache) { - return - } isBuildingCache = true this.mobLevel = if (main.levelInterface.isLevelled(livingEntity)) main.levelInterface.getLevelOfMob(livingEntity) else null @@ -263,6 +258,8 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv checkChanceRules(applicableRulesResult) this.fineTuningAttributes = main.rulesManager.getFineTuningAttributes(this) this.nametagCooldownTime = main.rulesManager.getRuleNametagVisibleTime(this) + this.nametagVisibilityEnum.clear() + this.nametagVisibilityEnum.addAll(main.rulesManager.getRuleCreatureNametagVisbility(this)) this.isBuildingCache = false } catch (e: InterruptedException) { Log.war("exception in buildCache: " + e.message) @@ -315,6 +312,12 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv applicableRules.clear() } + fun buildCacheIfNeeded(){ + if (!hasCache) { + buildCache() + } + } + private fun checkChanceRules( result: ApplicableRulesResult ) { @@ -466,13 +469,20 @@ class LivingEntityWrapper private constructor() : LivingEntityWrapperBase(), Liv var fineTuningAttributes: FineTuningAttributes? = null private set get() { - if (!hasCache) { - buildCache() - } + if (isClearingData) return field + if (!hasCache) buildCache() return field } + val nametagVisibilityEnum = mutableListOf() + get() { + if (isClearingData) return field + if (!hasCache) buildCache() + + return field + } + override fun getApplicableRules(): MutableList { if (!hasCache) { buildCache()