Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Fix info/remove commands
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Jul 16, 2023
1 parent fee5250 commit 74086ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group=com.mineinabyss
version=0.21
idofrontVersion=0.18.13
idofrontVersion=0.18.15
2 changes: 1 addition & 1 deletion gradle/myLibs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
gearyPaper = "0.24-SNAPSHOT"
gearyPaper = "0.25-SNAPSHOT"

[libraries]
geary-papermc = { module = "com.mineinabyss:geary-papermc", version.ref = "gearyPaper" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mineinabyss.mobzy.spawning.vertical

import com.mineinabyss.geary.papermc.tracking.entities.toGeary
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.helpers.prefabs
import com.mineinabyss.geary.systems.accessors.TargetScope
import com.mineinabyss.geary.systems.query.GearyQuery
import com.mineinabyss.idofront.location.down
Expand Down Expand Up @@ -89,7 +90,7 @@ class SpawnInfo(
companion object {
//TODO perhaps give normal mobs prefab keys too to make this more type safe
fun categorizeByType(mobs: Collection<Entity>): Map<PrefabKey?, Int> =
mobs.groupingBy { it.toGeary().get<PrefabKey>() }.eachCount()
mobs.groupingBy { it.toGeary().prefabs.first().get<PrefabKey>() }.eachCount()
}
}

22 changes: 15 additions & 7 deletions src/main/kotlin/com/mineinabyss/mobzy/MobzyCommands.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.mineinabyss.mobzy

import com.mineinabyss.geary.components.relations.InstanceOf
import com.mineinabyss.geary.datatypes.GearyEntity
import com.mineinabyss.geary.helpers.toGeary
import com.mineinabyss.geary.papermc.tracking.entities.components.SetEntityType
import com.mineinabyss.geary.papermc.tracking.entities.gearyMobs
import com.mineinabyss.geary.papermc.tracking.entities.toGeary
Expand Down Expand Up @@ -72,7 +75,7 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter {
else -> {
val prefab = runCatching { PrefabKey.of(type).toEntityOrNull() }.getOrNull()
?: this@commandGroup.stopCommand("No such prefab or selector $type")
geary.instanceOf(prefab)
geary.deepInstanceOf(prefab)
}
}
}) {
Expand Down Expand Up @@ -114,7 +117,7 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter {
}

"locate" {
val mobKey by optionArg(options = gearyMobs.mobPrefabs.run { map { it.key.toString() } }) {
val mobKey by optionArg(options = gearyMobs.prefabs.run { map { it.key.toString() } }) {
parseErrorMessage = { "No such entity: $passed" }
}
val radius by intArg {
Expand All @@ -125,14 +128,14 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter {
val key = PrefabKey.of(mobKey)
if (radius <= 0) {
Bukkit.getWorlds().forEach { world ->
world.entities.filter { it.toGeary().instanceOf(key.toEntity()) }.forEach { entity ->
world.entities.filter { it.toGeary().deepInstanceOf(key.toEntity()) }.forEach { entity ->
val loc = entity.location
player.info("Found ${key.key} at <click:run_command:/teleport ${loc.blockX} ${loc.blockY} ${loc.blockZ}>${entity.location}>${entity.location} in ${entity.world.name}")
}
}
} else {
player.location.getNearbyEntities(radius.toDouble(), radius.toDouble(), radius.toDouble())
.filter { it.toGeary().instanceOf(key.toEntity()) }.forEach { entity ->
.filter { it.toGeary().deepInstanceOf(key.toEntity()) }.forEach { entity ->
val loc = entity.location
player.info("Found ${key.key} at <click:run_command:/teleport ${loc.blockX} ${loc.blockY} ${loc.blockZ}>${entity.location}")

Expand All @@ -142,15 +145,15 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter {
}

("list" / "l")(desc = "Lists all custom mob types")?.action {
sender.success("All registered types:\n${gearyMobs.mobPrefabs.getKeys()}")
sender.success("All registered types:\n${gearyMobs.prefabs.getKeys()}")
}
}
}

private val mobs: List<String> by lazy {
buildList {
addAll(listOf("custom", "important", "mob", "renamed", "passive", "hostile", "flying"))
addAll(gearyMobs.mobPrefabs.getKeys().map { it.toString() })
addAll(gearyMobs.prefabs.getKeys().map { it.toString() })
}
}

Expand All @@ -175,7 +178,7 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter {
).filter { it.startsWith(args[0]) }

else -> {
val subCommand = args[1]
val subCommand = args[0]

when (subCommand) {
"remove", "rm", "info", "i" -> if (args.size == 2) {
Expand All @@ -195,3 +198,8 @@ class MobzyCommands : IdofrontCommandExecutor(), TabCompleter {
}
}
}

fun GearyEntity.deepInstanceOf(entity: GearyEntity): Boolean =
instanceOf(entity) || getRelations<InstanceOf?, Any?>().any {
it.target.toGeary().deepInstanceOf(entity)
}

0 comments on commit 74086ee

Please sign in to comment.