ginloader.bukkit-api.1.13.0.source-code.CmdUtil.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bukkit-api Show documentation
Show all versions of bukkit-api Show documentation
Bukkit API for runtime kotlin plugin loader
package pluginloader.api
import org.bukkit.Bukkit
import org.bukkit.entity.Player
val prefix = "§8[§aPlu§8]§f"
private val constNonNull = Any()
fun Args.use(sender: Sender, required: Int, text: String): Any?{
if(size < required){
sender.sendMessage("$prefix Usage: §6/$text")
return null
}
return constNonNull
}
fun Args.player(sender: Sender, index: Int): Player?{
val str = this[index]
val player = Bukkit.getPlayer(str)
if(player == null) sender.sendMessage("$prefix Player §6${str}§f offline")
return player
}
fun Args.int(sender: Sender, index: Int): Int?{
val str = this[index]
val i = str.toIntOrNull()
if(i == null) sender.sendMessage("$prefix §6$str§f not a number")
return i
}
fun Args.float(sender: Sender, index: Int): Float?{
return double(sender, index)?.toFloat()
}
fun Args.double(sender: Sender, index: Int): Double?{
return double(this[index], sender)
}
private fun double(str: String, sender: Sender): Double?{
val d = str.toDoubleOrNull()
if(d == null) sender.sendMessage("$prefix §6$str§f not a number")
return d
}
fun Args.v3(sender: Sender, index: Int): V3?{
val str = this[index]
if(str == "~" && sender is Player) return V3(sender.location)
val split = str.split(",")
if(split.size == 3){
run{
return V3(
double(split[0], sender) ?: return@run,
double(split[1], sender) ?: return@run,
double(split[2], sender) ?: return@run,
)
}
}
sender.sendMessage("$prefix §6$str§f not a location, example: §60,60,0")
return null
}
fun Args.v5(sender: Sender, index: Int): V5?{
val str = this[index]
if(str == "~" && sender is Player) return V5(sender.location)
val split = str.split(",")
if(split.size == 3){
run{
return V5(
double(split[0], sender) ?: return@run,
double(split[1], sender) ?: return@run,
double(split[2], sender) ?: return@run,
)
}
}else if(split.size == 5){
run{
return V5(
double(split[0], sender) ?: return@run,
double(split[1], sender) ?: return@run,
double(split[2], sender) ?: return@run,
double(split[3], sender)?.toFloat() ?: return@run,
double(split[4], sender)?.toFloat() ?: return@run,
)
}
}
sender.sendMessage("$prefix §6'$str'§f not a location, example: §6'0,60,0,0,0'")
return null
}