From 10eb279bc52dd865f323a48515ce74d53356a973 Mon Sep 17 00:00:00 2001 From: Dawson Date: Tue, 20 Feb 2024 16:19:07 -0500 Subject: [PATCH 1/4] Added Extension Functions To Entity.kt --- README.md | 2 +- .../gg/flyte/twilight/extension/Entity.kt | 196 +++++++++++++++++- 2 files changed, 196 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e448768..5fa295d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Twilight is an API for developers creating plugins for Spigot or Paper based Minecraft servers. It contains a wide range of utilities and QOL improvements, from inventories, to schedulers and databases. -Twilight is built using **Kotlin**, and is recommended for usage with. Many features of Twilight should work with plain Java, though compatability is not guaranteed. +Twilight is built using **Kotlin**, and is recommended for usage with. Many features of Twilight should work with plain Java, though compatibility is not guaranteed. If you have any questions or need any support, head over to the [Flyte Discord](https://discord.gg/CGmMQwfXXN)! diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt index 97ddf9a..b5df665 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt @@ -1,6 +1,8 @@ package gg.flyte.twilight.extension import org.bukkit.entity.Entity +import org.bukkit.entity.LivingEntity +import org.bukkit.entity.Player /** * Retrieves a list of nearby entities within the specified range from the current entity. @@ -27,4 +29,196 @@ fun Entity.getNearbyEntities(range: Double): MutableList { */ fun Entity.isOnFire(): Boolean { return fireTicks > 0 -} \ No newline at end of file +} + +/** + * Gets the nearest player to this entity. + * @return The nearest player. + */ + +fun Entity.getNearestPlayer(): Player? { + var nearestDistance = Double.MAX_VALUE + var nearestPlayer: Player? = null + for (player in world.players) { + if (player == this) continue + val distance = location.distance(player.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestPlayer = player + } + } + return nearestPlayer +} + + +/** + * Gets the nearest player to this entity within the given radius. + * @param radius The radius to search. + * @return The nearest player. + */ + +fun Entity.getNearestPlayer(radius: Double): Player? { + var nearestDistance = Double.MAX_VALUE + var nearestPlayer: Player? = null + for (player in world.getNearbyPlayers(location, radius)) { + if (player == this) continue + val distance = location.distance(player.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestPlayer = player + } + } + return nearestPlayer +} + + +/** + * Gets the nearest player to this entity within the given radius. + * @param xRadius The x radius to search. + * @param yRadius The y radius to search. + * @param zRadius The z radius to search. + * @return The nearest player. + */ + +fun Entity.getNearestPlayer(xRadius: Double, yRadius: Double, zRadius: Double): Player? { + var nearestDistance = Double.MAX_VALUE + var nearestPlayer: Player? = null + for (player in world.getNearbyPlayers(location, xRadius, yRadius, zRadius)) { + if (player == this) continue + val distance = location.distance(player.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestPlayer = player + } + } + return nearestPlayer +} + + +/** + * Gets the nearest entity to this entity. + * @return The nearest entity. + */ + +fun Entity.getNearestEntity(): Entity? { + var nearestDistance = Double.MAX_VALUE + var nearestEntity: Entity? = null + for (entity in world.entities.also { it.remove(this) }) { + if (entity == this) continue + val distance = location.distance(entity.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestEntity = entity + } + } + return nearestEntity +} + + +/** + * Gets the nearest entity to this entity within the given radius. + * @param radius The radius to search. + * @return The nearest entity. + */ + +fun Entity.getNearestEntity(radius: Double): Entity? { + var nearestDistance = Double.MAX_VALUE + var nearestEntity: Entity? = null + for (entity in world.getNearbyEntities(location, radius, radius, radius)) { + if (entity == this) continue + val distance = location.distance(entity.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestEntity = entity + } + } + return nearestEntity +} + + +/** + * Gets the nearest entity to this entity within the given radius. + * @param xRadius The x radius to search. + * @param yRadius The y radius to search. + * @param zRadius The z radius to search. + * @return The nearest entity. + */ + +fun Entity.getNearestEntity(xRadius: Double, yRadius: Double, zRadius: Double): Entity? { + var nearestDistance = Double.MAX_VALUE + var nearestEntity: Entity? = null + for (entity in world.getNearbyEntities(location, xRadius, yRadius, zRadius)) { + if (entity == this) continue + val distance = location.distance(entity.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestEntity = entity + } + } + return nearestEntity +} + + +/** + * Gets the nearest living entity to this entity. + * @return The nearest living entity. + */ + +fun Entity.getNearestLivingEntity(): LivingEntity? { + var nearestDistance = Double.MAX_VALUE + var nearestEntity: LivingEntity? = null + for (entity in world.livingEntities) { + if (entity == this) continue + val distance = location.distance(entity.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestEntity = entity + } + } + return nearestEntity +} + + +/** + * Gets the nearest living entity to this entity within the given radius. + * @param radius The radius to search. + * @return The nearest living entity. + */ + +fun Entity.getNearestLivingEntity(radius: Double): LivingEntity? { + var nearestDistance = Double.MAX_VALUE + var nearestEntity: LivingEntity? = null + for (entity in world.getNearbyLivingEntities(location, radius)) { + if (entity == this) continue + val distance = location.distance(entity.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestEntity = entity + } + } + return nearestEntity +} + + +/** + * Gets the nearest living entity to this entity within the given radius. + * @param xRadius The x radius to search. + * @param yRadius The y radius to search. + * @param zRadius The z radius to search. + * @return The nearest living entity. + */ + +fun Entity.getNearestLivingEntity(xRadius: Double, yRadius: Double, zRadius: Double): LivingEntity? { + var nearestDistance = Double.MAX_VALUE + var nearestEntity: LivingEntity? = null + for (entity in world.getNearbyLivingEntities(location, xRadius, yRadius, zRadius)) { + if (entity == this) continue + val distance = location.distance(entity.location) + if (distance < nearestDistance) { + nearestDistance = distance + nearestEntity = entity + } + } + return nearestEntity +} + From f26c3004b2c798744eed970525bfc71610b500de Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 24 Feb 2024 19:13:11 +0200 Subject: [PATCH 2/4] Added Extension Functions To Entity.kt --- .../gg/flyte/twilight/extension/Entity.kt | 129 +----------------- 1 file changed, 3 insertions(+), 126 deletions(-) diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt index b5df665..cc465b1 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt @@ -31,47 +31,6 @@ fun Entity.isOnFire(): Boolean { return fireTicks > 0 } -/** - * Gets the nearest player to this entity. - * @return The nearest player. - */ - -fun Entity.getNearestPlayer(): Player? { - var nearestDistance = Double.MAX_VALUE - var nearestPlayer: Player? = null - for (player in world.players) { - if (player == this) continue - val distance = location.distance(player.location) - if (distance < nearestDistance) { - nearestDistance = distance - nearestPlayer = player - } - } - return nearestPlayer -} - - -/** - * Gets the nearest player to this entity within the given radius. - * @param radius The radius to search. - * @return The nearest player. - */ - -fun Entity.getNearestPlayer(radius: Double): Player? { - var nearestDistance = Double.MAX_VALUE - var nearestPlayer: Player? = null - for (player in world.getNearbyPlayers(location, radius)) { - if (player == this) continue - val distance = location.distance(player.location) - if (distance < nearestDistance) { - nearestDistance = distance - nearestPlayer = player - } - } - return nearestPlayer -} - - /** * Gets the nearest player to this entity within the given radius. * @param xRadius The x radius to search. @@ -80,7 +39,7 @@ fun Entity.getNearestPlayer(radius: Double): Player? { * @return The nearest player. */ -fun Entity.getNearestPlayer(xRadius: Double, yRadius: Double, zRadius: Double): Player? { +fun Entity.getNearestPlayer(xRadius: Double = Double.MAX_VALUE, yRadius: Double = Double.MAX_VALUE, zRadius: Double = Double.MAX_VALUE): Player? { var nearestDistance = Double.MAX_VALUE var nearestPlayer: Player? = null for (player in world.getNearbyPlayers(location, xRadius, yRadius, zRadius)) { @@ -95,47 +54,6 @@ fun Entity.getNearestPlayer(xRadius: Double, yRadius: Double, zRadius: Double): } -/** - * Gets the nearest entity to this entity. - * @return The nearest entity. - */ - -fun Entity.getNearestEntity(): Entity? { - var nearestDistance = Double.MAX_VALUE - var nearestEntity: Entity? = null - for (entity in world.entities.also { it.remove(this) }) { - if (entity == this) continue - val distance = location.distance(entity.location) - if (distance < nearestDistance) { - nearestDistance = distance - nearestEntity = entity - } - } - return nearestEntity -} - - -/** - * Gets the nearest entity to this entity within the given radius. - * @param radius The radius to search. - * @return The nearest entity. - */ - -fun Entity.getNearestEntity(radius: Double): Entity? { - var nearestDistance = Double.MAX_VALUE - var nearestEntity: Entity? = null - for (entity in world.getNearbyEntities(location, radius, radius, radius)) { - if (entity == this) continue - val distance = location.distance(entity.location) - if (distance < nearestDistance) { - nearestDistance = distance - nearestEntity = entity - } - } - return nearestEntity -} - - /** * Gets the nearest entity to this entity within the given radius. * @param xRadius The x radius to search. @@ -144,7 +62,7 @@ fun Entity.getNearestEntity(radius: Double): Entity? { * @return The nearest entity. */ -fun Entity.getNearestEntity(xRadius: Double, yRadius: Double, zRadius: Double): Entity? { +fun Entity.getNearestEntity(xRadius: Double = Double.MAX_VALUE, yRadius: Double = Double.MAX_VALUE, zRadius: Double = Double.MAX_VALUE): Entity? { var nearestDistance = Double.MAX_VALUE var nearestEntity: Entity? = null for (entity in world.getNearbyEntities(location, xRadius, yRadius, zRadius)) { @@ -159,47 +77,6 @@ fun Entity.getNearestEntity(xRadius: Double, yRadius: Double, zRadius: Double): } -/** - * Gets the nearest living entity to this entity. - * @return The nearest living entity. - */ - -fun Entity.getNearestLivingEntity(): LivingEntity? { - var nearestDistance = Double.MAX_VALUE - var nearestEntity: LivingEntity? = null - for (entity in world.livingEntities) { - if (entity == this) continue - val distance = location.distance(entity.location) - if (distance < nearestDistance) { - nearestDistance = distance - nearestEntity = entity - } - } - return nearestEntity -} - - -/** - * Gets the nearest living entity to this entity within the given radius. - * @param radius The radius to search. - * @return The nearest living entity. - */ - -fun Entity.getNearestLivingEntity(radius: Double): LivingEntity? { - var nearestDistance = Double.MAX_VALUE - var nearestEntity: LivingEntity? = null - for (entity in world.getNearbyLivingEntities(location, radius)) { - if (entity == this) continue - val distance = location.distance(entity.location) - if (distance < nearestDistance) { - nearestDistance = distance - nearestEntity = entity - } - } - return nearestEntity -} - - /** * Gets the nearest living entity to this entity within the given radius. * @param xRadius The x radius to search. @@ -208,7 +85,7 @@ fun Entity.getNearestLivingEntity(radius: Double): LivingEntity? { * @return The nearest living entity. */ -fun Entity.getNearestLivingEntity(xRadius: Double, yRadius: Double, zRadius: Double): LivingEntity? { +fun Entity.getNearestLivingEntity(xRadius: Double = Double.MAX_VALUE, yRadius: Double = Double.MAX_VALUE, zRadius: Double = Double.MAX_VALUE): LivingEntity? { var nearestDistance = Double.MAX_VALUE var nearestEntity: LivingEntity? = null for (entity in world.getNearbyLivingEntities(location, xRadius, yRadius, zRadius)) { From 702ad20841139f202882bbdbadfa5ea37b56883c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 24 Feb 2024 19:13:52 +0200 Subject: [PATCH 3/4] Added Extension Functions To Entity.kt --- src/main/kotlin/gg/flyte/twilight/extension/Entity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt index cc465b1..55bfec8 100644 --- a/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt +++ b/src/main/kotlin/gg/flyte/twilight/extension/Entity.kt @@ -76,7 +76,6 @@ fun Entity.getNearestEntity(xRadius: Double = Double.MAX_VALUE, yRadius: Double return nearestEntity } - /** * Gets the nearest living entity to this entity within the given radius. * @param xRadius The x radius to search. From 8aeff638620cd0401d9e6263c2c5f6a7b5e94d11 Mon Sep 17 00:00:00 2001 From: Josh <43449531+joshbker@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:23:49 +0000 Subject: [PATCH 4/4] chore: bump ver v1.1.9 --- README.md | 6 +++--- build.gradle.kts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8173223..406a4e7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Maven gg.flyte twilight - 1.1.8 + 1.1.9 ``` @@ -31,14 +31,14 @@ maven { url "https://repo.flyte.gg/releases" } -implementation "gg.flyte:twilight:1.1.8" +implementation "gg.flyte:twilight:1.1.9" ``` Gradle (Kotlin DSL) ```kotlin maven("https://repo.flyte.gg/releases") -implementation("gg.flyte:twilight:1.1.8") +implementation("gg.flyte:twilight:1.1.9") ``` Certain features of Twilight require configuration, which can be done via the Twilight class. To setup a Twilight class instance, you can use the `twilight` function as shown below: diff --git a/build.gradle.kts b/build.gradle.kts index 3c4fae7..8c659e8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "gg.flyte" -version = "1.1.8" +version = "1.1.9" repositories { mavenLocal()