From f224e00dba9fba014670fab2da91be94e67b29ef Mon Sep 17 00:00:00 2001 From: mooziii <63669478+mooziii@users.noreply.github.com> Date: Tue, 12 Apr 2022 11:52:22 +0200 Subject: [PATCH 1/3] Add LivingEntity.realMaxHealth because the normal one is deprecated :) --- .../axay/kspigot/extensions/bukkit/EntityExtensions.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt index ebb07a5c..881218ef 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt @@ -42,6 +42,14 @@ val Entity.isGroundSolid: Boolean get() = this.location.add(0.0, -0.01, 0.0).blo */ val Entity.groundMaterial get() = this.location.add(0.0, -0.01, 0.0).block.type +/** + * @return The max health of the entity + * @throws NullPointerException if the entity doesn't have a max health value + */ +val LivingEntity.realMaxHealth: Double + get() = getAttribute(Attribute.GENERIC_MAX_HEALTH)?.value + ?: throw NullPointerException("The entity does not have a max health value!") + /** * Kills the damageable. */ From 3c811ed5bb5dfb4db324da160a54fe2e5d47ff78 Mon Sep 17 00:00:00 2001 From: mooziii <63669478+mooziii@users.noreply.github.com> Date: Tue, 12 Apr 2022 11:55:57 +0200 Subject: [PATCH 2/3] Add Entity.isStandingOnBlock --- .../axay/kspigot/extensions/bukkit/EntityExtensions.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt index 881218ef..afbf071b 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt @@ -42,6 +42,14 @@ val Entity.isGroundSolid: Boolean get() = this.location.add(0.0, -0.01, 0.0).blo */ val Entity.groundMaterial get() = this.location.add(0.0, -0.01, 0.0).block.type +/** + * @returns true if the entity is supported by a block. + * The method from bukkit is deprecated because it can be spoofed by the client. + * This can't be spoofed. + */ +val Entity.isStandingOnBlock: Boolean + get() = groundMaterial.isSolid + /** * @return The max health of the entity * @throws NullPointerException if the entity doesn't have a max health value From f3dba9467b1e240db7c1615dc102445ada5b17f2 Mon Sep 17 00:00:00 2001 From: mooziii <63669478+mooziii@users.noreply.github.com> Date: Tue, 12 Apr 2022 11:57:48 +0200 Subject: [PATCH 3/3] Add Entity.isStandingInMidAir --- .../net/axay/kspigot/extensions/bukkit/EntityExtensions.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt index afbf071b..4af45d3f 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt @@ -50,6 +50,12 @@ val Entity.groundMaterial get() = this.location.add(0.0, -0.01, 0.0).block.type val Entity.isStandingOnBlock: Boolean get() = groundMaterial.isSolid +/** + * @returns true if the entity is standing in mid air. + */ +val Entity.isStandingInMidAir: Boolean + get() = !isStandingOnBlock && vehicle == null && !location.clone().add(0.0, 0.1, 0.0).block.type.isSolid && !location.block.type.isSolid + /** * @return The max health of the entity * @throws NullPointerException if the entity doesn't have a max health value