diff --git a/build.gradle.kts b/build.gradle.kts index 86d8863..23060da 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "gg.flyte" -version = "1.0.19" +version = "1.0.22" repositories { mavenCentral() diff --git a/src/main/kotlin/gg/flyte/twilight/extension/BoundingBox.kt b/src/main/kotlin/gg/flyte/twilight/extension/BoundingBox.kt new file mode 100644 index 0000000..23c112b --- /dev/null +++ b/src/main/kotlin/gg/flyte/twilight/extension/BoundingBox.kt @@ -0,0 +1,87 @@ +package gg.flyte.twilight.extension + +import org.bukkit.Location +import org.bukkit.World +import org.bukkit.block.Block +import org.bukkit.util.BoundingBox + +/** + * Retrieves all the blocks within the bounding box in the specified world. + * + * This extension function for BoundingBox iterates through all x, y, and z + * coordinates that the bounding box encompasses and collects the corresponding + * blocks from the world. + * + * Note: This function can be performance-intensive for large bounding boxes, + * as it iterates over every single block within the bounding box. + * + * @param world The world from which to retrieve the blocks. + * @return A list of Block objects within the bounding box in the given world. + */ +fun BoundingBox.getBlocks(world: World): List { + val blocks = mutableListOf() + + val minX = minX.toInt() + val minY = minY.toInt() + val minZ = minZ.toInt() + val maxX = maxX.toInt() + val maxY = maxY.toInt() + val maxZ = maxZ.toInt() + + for (x in minX..maxX) { + for (y in minY..maxY) { + for (z in minZ..maxZ) { + blocks.add(world.getBlockAt(x, y, z)) + } + } + } + + return blocks +} + +/** + * Retrieves all the locations within the bounding box in the specified world. + * + * This extension function for BoundingBox iterates through all x, y, and z + * coordinates that the bounding box encompasses and collects the corresponding + * locations from the world. + * + * Note: This function can be performance-intensive for large bounding boxes, + * as it iterates over every single location within the bounding box. + * + * @param world The world in which the bounding box is defined. + * @return A list of Location objects representing each block position within the bounding box. + */ +fun BoundingBox.getLocations(world: World): List { + val locations = mutableListOf() + + val minX = minX.toInt() + val minY = minY.toInt() + val minZ = minZ.toInt() + val maxX = maxX.toInt() + val maxY = maxY.toInt() + val maxZ = maxZ.toInt() + + for (x in minX..maxX) { + for (y in minY..maxY) { + for (z in minZ..maxZ) { + locations.add(Location(world, x.toDouble(), y.toDouble(), z.toDouble())) + } + } + } + + return locations +} + +/** + * Checks if the specified Location is within the boundaries of this BoundingBox. + * + * This extension function provides a simple way to determine if a Location is contained + * within the BoundingBox using its x, y, and z coordinates. + * + * @param location The Location to check for containment within this BoundingBox. + * @return Boolean true if the Location is within the BoundingBox; false otherwise. + */ +fun BoundingBox.contains(location: Location): Boolean { + return contains(location.x, location.y, location.z) +} \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Location.kt b/src/main/kotlin/gg/flyte/twilight/extension/Location.kt index d262cdb..1a074c6 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Location.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Location.kt @@ -1,6 +1,8 @@ package gg.flyte.twilight.extension import org.bukkit.Location +import org.bukkit.entity.Entity +import org.bukkit.entity.EntityType import org.bukkit.inventory.ItemStack /** @@ -21,3 +23,13 @@ fun Location.dropItem(itemStack: ItemStack) { fun Location.dropItemNaturally(itemStack: ItemStack) { world!!.dropItemNaturally(this, itemStack) } + +/** + * Extension function for the Location class to spawn an entity of the specified type at the location. + * + * @param type The type of entity to spawn at this location. + * @return The entity that was spawned. + */ +fun Location.spawnEntity(type: EntityType): Entity { + return world!!.spawnEntity(this, type) +} \ No newline at end of file diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt index 0f176d3..2f0c1df 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Player.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Player.kt @@ -29,6 +29,13 @@ fun Player.sendActionBar(message: String) { spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent(message)) } +/** + * Removes any existing action bar for the player. + */ +fun Player.clearActionBar() { + spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent("")) +} + /** * Restores the player's food level to maximum. *