General update

This commit is contained in:
bluefireoly
2020-08-27 20:51:46 +02:00
parent 64bbc55649
commit f46fa5d658
10 changed files with 356 additions and 30 deletions

View File

@@ -0,0 +1,19 @@
package net.axay.kspigot.extensions
import org.bukkit.Bukkit
import org.bukkit.entity.Player
/**
* @see Bukkit.getOnlinePlayers
*/
val onlinePlayers: Collection<Player> get() = Bukkit.getOnlinePlayers()
/**
* @see Bukkit.getServer
*/
val server by lazy { Bukkit.getServer() }
/**
* @see Bukkit.getPluginManager
*/
val pluginManager by lazy { Bukkit.getPluginManager() }

View File

@@ -0,0 +1,84 @@
package net.axay.kspigot.extensions.bukkit
import net.axay.kspigot.extensions.onlinePlayers
import net.axay.kspigot.main.KSpigot
import org.bukkit.Material
import org.bukkit.attribute.Attribute
import org.bukkit.entity.Damageable
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
/**
* Checks if the entity is completely in water.
*/
val LivingEntity.isInWater: Boolean get() = isFeetInWater && isHeadInWater
/**
* Checks if the entities' head is in water.
*/
val LivingEntity.isHeadInWater: Boolean get() = this.eyeLocation.block.type == Material.WATER
/**
* Checks if the entities' feet are in water.
*/
val Entity.isFeetInWater: Boolean get() = this.location.block.type == Material.WATER
/**
* Checks if the entity stands on solid ground.
*/
val Entity.isGroundSolid: Boolean get() = this.location.add(0.0, -0.01, 0.0).block.type.isSolid
/**
* Kills the damageable.
*/
fun Damageable.kill() {
health = 0.0
}
/**
* Sets the entities' health to the max possible value.
* @throws NullPointerException if the entity does not have a max health value
*/
fun LivingEntity.heal() {
health = getAttribute(Attribute.GENERIC_MAX_HEALTH)?.value
?: throw NullPointerException("The entity does not have a max health value!")
}
/**
* Sets the players' foodLevel to the
* max possible value.
*/
fun Player.feed() {
foodLevel = 20
}
/**
* Sets the players' saturation to the
* current max possible value.
*/
fun Player.saturate() {
saturation = foodLevel.toFloat()
}
/**
* Feeds and saturates the player.
*/
fun Player.feedSaturate() {
foodLevel = 20
saturation = 20f
}
/**
* Hides the player for all [onlinePlayers].
*/
fun Player.disappear(kSpigot: KSpigot) {
onlinePlayers.filter { it != this }.forEach { it.hidePlayer(kSpigot, this) }
}
/**
* Shows the player for all [onlinePlayers].
*/
fun Player.appear(kSpigot: KSpigot) {
onlinePlayers.filter { it != this }.forEach { it.showPlayer(kSpigot, this) }
}

View File

@@ -1,5 +0,0 @@
package net.axay.kspigot.extensions.bukkit
import org.bukkit.util.Vector
val Vector.isFinite: Boolean get() = x.isFinite() && y.isFinite() && z.isFinite()

View File

@@ -1,8 +0,0 @@
package net.axay.kspigot.extensions.entities
import org.bukkit.Material
import org.bukkit.entity.Entity
val Entity.isInWater: Boolean get() = this.location.block.type == Material.WATER
val Entity.isGroundSolid: Boolean get() = this.location.add(0.0, -0.01, 0.0).block.type.isSolid

View File

@@ -28,14 +28,18 @@ val PlayerInteractEntityEvent.interactItem: ItemStack?
@UnsafeImplementation
val PlayerInteractEvent.clickedBlockExceptAir: Block?
get() {
val p: Player = this.player
return when (this.action) {
Action.RIGHT_CLICK_BLOCK -> this.clickedBlock
Action.RIGHT_CLICK_AIR -> {
return clickedBlock ?: kotlin.run {
return@run if (this.action == Action.RIGHT_CLICK_AIR) {
val p: Player = this.player
// check for sight blocking entities
for (nearbyEntity: Entity in p.getNearbyEntities(5.0, 5.0, 5.0))
if (p.hasLineOfSight(nearbyEntity)) return null
if (p.hasLineOfSight(nearbyEntity)) return@run null
// get first block in line of sight which is not air
p.getLineOfSight(null, 5).find { block -> !block.type.isAir }
}
else -> null
} else null
}
}