Merge pull request #26 from copyandexecute/extensions
Simple Extensions/Shortcuts
This commit is contained in:
@@ -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<World> get() = Bukkit.getWorlds()
|
||||
|
@@ -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)
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
@@ -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]"
|
||||
|
Reference in New Issue
Block a user