Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle.kts
  • Loading branch information
joshbker committed Nov 5, 2023
2 parents ce1fc07 + ce2182d commit f9f0d7e
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "gg.flyte"
version = "1.0.19"
version = "1.0.22"

repositories {
mavenCentral()
Expand Down
87 changes: 87 additions & 0 deletions src/main/kotlin/gg/flyte/twilight/extension/BoundingBox.kt
Original file line number Diff line number Diff line change
@@ -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<Block> {
val blocks = mutableListOf<Block>()

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<Location> {
val locations = mutableListOf<Location>()

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)
}
12 changes: 12 additions & 0 deletions src/main/kotlin/gg/flyte/twilight/extension/Location.kt
Original file line number Diff line number Diff line change
@@ -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

/**
Expand All @@ -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)
}
7 changes: 7 additions & 0 deletions src/main/kotlin/gg/flyte/twilight/extension/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit f9f0d7e

Please sign in to comment.