diff --git a/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt index 592764fe..27b61599 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/GeneralExtensions.kt @@ -3,6 +3,7 @@ package net.axay.kspigot.extensions import net.axay.kspigot.main.PluginInstance import org.bukkit.Bukkit import org.bukkit.NamespacedKey +import org.bukkit.World import org.bukkit.command.CommandSender import org.bukkit.entity.Player @@ -47,3 +48,8 @@ val console get() = Bukkit.getConsoleSender() * Shortcut for creating a new [NamespacedKey] */ fun pluginKey(key: String) = NamespacedKey(PluginInstance, key) + +/** + * Shortcut to get a collection of all worlds + */ +val worlds: List get() = Bukkit.getWorlds() diff --git a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt index 8bdd0b5d..8732d561 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/ConsoleSenderExtensions.kt @@ -2,6 +2,7 @@ package net.axay.kspigot.extensions.bukkit import net.axay.kspigot.main.PluginInstance import net.md_5.bungee.api.ChatColor +import org.bukkit.Bukkit import org.bukkit.command.CommandSender import org.bukkit.plugin.Plugin @@ -30,3 +31,11 @@ fun CommandSender.error(text: String, plugin: Plugin? = PluginInstance) = */ fun CommandSender.printColoredPrefix(text: String, textColor: ChatColor, prefix: String, prefixColor: ChatColor) = sendMessage("${prefixColor}[${prefix}]${textColor} $text") + +/** + * Dispatches the command given by [commandLine]. + * + * @param commandLine the command without a leading / + */ +fun CommandSender.dispatchCommand(commandLine: String) = + Bukkit.dispatchCommand(this, commandLine) 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 c9fa3221..08a1e73b 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/bukkit/EntityExtensions.kt @@ -29,6 +29,11 @@ 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 +/** + * Returns the material that is present under the feet of this entity. + */ +val Entity.groundMaterial get() = this.location.add(0.0, -0.01, 0.0).block.type + /** * Kills the damageable. */ diff --git a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt index 6c0d362e..dd413096 100644 --- a/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt +++ b/src/main/kotlin/net/axay/kspigot/extensions/geometry/KSpigotLocations.kt @@ -40,3 +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) + +/** + * Returns a simple string in the format of `[x, y, z]`. + */ +fun Location.toSimpleString() = "[$x, $y, $z]"