Improve proposed extensions

This commit is contained in:
Jakob K
2021-08-27 20:17:47 +02:00
parent d8d2d7ae88
commit 044129caae
4 changed files with 12 additions and 10 deletions

View File

@@ -52,5 +52,4 @@ fun pluginKey(key: String) = NamespacedKey(PluginInstance, key)
/**
* Shortcut to get a collection of all worlds
*/
val worlds: Collection<World> get() = Bukkit.getWorlds()
val worlds: List<World> get() = Bukkit.getWorlds()

View File

@@ -1,6 +1,5 @@
package net.axay.kspigot.extensions.bukkit
import net.axay.kspigot.extensions.console
import net.axay.kspigot.main.PluginInstance
import net.md_5.bungee.api.ChatColor
import org.bukkit.Bukkit
@@ -34,7 +33,9 @@ fun CommandSender.printColoredPrefix(text: String, textColor: ChatColor, prefix:
sendMessage("${prefixColor}[${prefix}]${textColor} $text")
/**
* Dispatches a command sent by Console
* Dispatches the command given by [commandLine].
*
* @param commandLine the command without a leading /
*/
fun dispatchCommand(commandLine: String) = Bukkit.dispatchCommand(console, commandLine)
fun CommandSender.dispatchCommand(commandLine: String) =
Bukkit.dispatchCommand(this, commandLine)

View File

@@ -30,10 +30,9 @@ val Entity.isFeetInWater: Boolean get() = this.location.block.type == Material.W
val Entity.isGroundSolid: Boolean get() = this.location.add(0.0, -0.01, 0.0).block.type.isSolid
/**
* Checks if the entity stands on a specific material.
* @param material the material you are looking for
* Returns the material that is present under the feet of this entity.
*/
fun Entity.isOnMaterial(material: Material): Boolean = location.block.type == material
val Entity.groundMaterial get() = this.location.add(0.0, -0.01, 0.0).block.type
/**
* Kills the damageable.

View File

@@ -40,5 +40,8 @@ fun SimpleLocation3D.withWorld(world: World) = Location(world, x, y, z).apply {
fun SimpleChunkLocation.withWorld(world: World) = world.getChunkAt(x, z)
fun Vector.toSimpleLoc() = SimpleLocation3D(x, y, z)
fun SimpleLocation3D.toVector() = Vector(x, y, z)
fun Location.printSimple(): String = "[$x, $y, $z]"
/**
* Returns a simple string in the format of `[x, y, z]`.
*/
fun Location.toSimpleString() = "[$x, $y, $z]"