Applied kotlin style conventions
This commit is contained in:
@@ -6,27 +6,27 @@ import org.bukkit.command.CommandSender
|
||||
import org.bukkit.plugin.Plugin
|
||||
|
||||
/** @see printColoredPrefix */
|
||||
fun CommandSender.print(text: String, plugin: Plugin? = KSpigotMainInstance)
|
||||
= printColoredPrefix(text, ChatColor.RESET, plugin?.name ?: "INFO", ChatColor.GRAY)
|
||||
fun CommandSender.print(text: String, plugin: Plugin? = KSpigotMainInstance) =
|
||||
printColoredPrefix(text, ChatColor.RESET, plugin?.name ?: "INFO", ChatColor.GRAY)
|
||||
|
||||
/** @see printColoredPrefix */
|
||||
fun CommandSender.info(text: String, plugin: Plugin? = KSpigotMainInstance)
|
||||
= printColoredPrefix(text, ChatColor.WHITE, plugin?.name ?: "INFO", ChatColor.DARK_AQUA)
|
||||
fun CommandSender.info(text: String, plugin: Plugin? = KSpigotMainInstance) =
|
||||
printColoredPrefix(text, ChatColor.WHITE, plugin?.name ?: "INFO", ChatColor.DARK_AQUA)
|
||||
|
||||
/** @see printColoredPrefix */
|
||||
fun CommandSender.success(text: String, plugin: Plugin? = KSpigotMainInstance)
|
||||
= printColoredPrefix(text, ChatColor.GREEN, plugin?.name ?: "SUCCESS", ChatColor.DARK_AQUA)
|
||||
fun CommandSender.success(text: String, plugin: Plugin? = KSpigotMainInstance) =
|
||||
printColoredPrefix(text, ChatColor.GREEN, plugin?.name ?: "SUCCESS", ChatColor.DARK_AQUA)
|
||||
|
||||
/** @see printColoredPrefix */
|
||||
fun CommandSender.warn(text: String, plugin: Plugin? = KSpigotMainInstance)
|
||||
= printColoredPrefix(text, ChatColor.WHITE, plugin?.name?.plus(" - WARN") ?: "WARN", ChatColor.YELLOW)
|
||||
fun CommandSender.warn(text: String, plugin: Plugin? = KSpigotMainInstance) =
|
||||
printColoredPrefix(text, ChatColor.WHITE, plugin?.name?.plus(" - WARN") ?: "WARN", ChatColor.YELLOW)
|
||||
|
||||
/** @see printColoredPrefix */
|
||||
fun CommandSender.error(text: String, plugin: Plugin? = KSpigotMainInstance)
|
||||
= printColoredPrefix(text, ChatColor.RED, plugin?.name?.plus(" - ERROR") ?: "ERROR", ChatColor.DARK_RED)
|
||||
fun CommandSender.error(text: String, plugin: Plugin? = KSpigotMainInstance) =
|
||||
printColoredPrefix(text, ChatColor.RED, plugin?.name?.plus(" - ERROR") ?: "ERROR", ChatColor.DARK_RED)
|
||||
|
||||
/**
|
||||
* Sends the given message and adds the given prefix with the given color to it.
|
||||
*/
|
||||
fun CommandSender.printColoredPrefix(text: String, textColor: ChatColor, prefix: String, prefixColor: ChatColor)
|
||||
= sendMessage("${prefixColor}[${prefix}]${textColor} $text")
|
||||
fun CommandSender.printColoredPrefix(text: String, textColor: ChatColor, prefix: String, prefixColor: ChatColor) =
|
||||
sendMessage("${prefixColor}[${prefix}]${textColor} $text")
|
@@ -43,7 +43,7 @@ fun Damageable.kill() {
|
||||
*/
|
||||
fun LivingEntity.heal() {
|
||||
health = getAttribute(Attribute.GENERIC_MAX_HEALTH)?.value
|
||||
?: throw NullPointerException("The entity does not have a max health value!")
|
||||
?: throw NullPointerException("The entity does not have a max health value!")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,7 +110,13 @@ fun Location.spawnCleanEntity(entityType: EntityType): Entity? {
|
||||
* @param stay time in ticks for titles to stay
|
||||
* @param fadeOut time in ticks for titles to fade out
|
||||
*/
|
||||
fun Player.title(mainText: String? = null, subText: String? = null, fadeIn: Int = 10, stay: Int = 70, fadeOut: Int = 20) {
|
||||
fun Player.title(
|
||||
mainText: String? = null,
|
||||
subText: String? = null,
|
||||
fadeIn: Int = 10,
|
||||
stay: Int = 70,
|
||||
fadeOut: Int = 20
|
||||
) {
|
||||
sendTitle(mainText, subText, fadeIn, stay, fadeOut)
|
||||
}
|
||||
|
||||
|
@@ -7,5 +7,6 @@ import org.bukkit.World
|
||||
* Assumes that this Location has world data.
|
||||
* If not, an exception will be thrown.
|
||||
*/
|
||||
val Location.worldOrException: World get() = world
|
||||
?: throw NullPointerException("The world of the location is null!")
|
||||
val Location.worldOrException: World
|
||||
get() = world
|
||||
?: throw NullPointerException("The world of the location is null!")
|
@@ -10,10 +10,12 @@ import org.bukkit.inventory.ItemStack
|
||||
* the result is equal to [Material.AIR].
|
||||
*/
|
||||
val PrepareItemCraftEvent.isCancelled: Boolean
|
||||
get() = this.inventory.result?.type == Material.AIR
|
||||
get() = this.inventory.result?.type == Material.AIR
|
||||
|
||||
/**
|
||||
* "Cancels" this event by
|
||||
* setting the result to [Material.AIR].
|
||||
*/
|
||||
fun PrepareItemCraftEvent.cancel() { this.inventory.result = ItemStack(Material.AIR) }
|
||||
fun PrepareItemCraftEvent.cancel() {
|
||||
this.inventory.result = ItemStack(Material.AIR)
|
||||
}
|
@@ -20,16 +20,16 @@ class SimpleLocationPair(loc1: Location, loc2: Location) {
|
||||
val maxSimpleLoc = SimpleLocation3D(max(loc1.x, loc2.x), max(loc1.y, loc2.y), max(loc1.z, loc2.z))
|
||||
|
||||
fun isInArea(
|
||||
loc: Location,
|
||||
check3d: Boolean = true,
|
||||
tolerance: Int = 0
|
||||
loc: Location,
|
||||
check3d: Boolean = true,
|
||||
tolerance: Int = 0
|
||||
): Boolean {
|
||||
|
||||
// checking world
|
||||
if (loc.world != world) return false
|
||||
|
||||
return if (
|
||||
// checking x
|
||||
// checking x
|
||||
loc.x >= minSimpleLoc.x - tolerance && loc.x <= maxSimpleLoc.x + tolerance &&
|
||||
// checking z
|
||||
loc.z >= minSimpleLoc.z - tolerance && loc.z <= maxSimpleLoc.z + tolerance
|
||||
@@ -45,9 +45,10 @@ class SimpleLocationPair(loc1: Location, loc2: Location) {
|
||||
val foundChunks = HashSet<SimpleChunkLocation>()
|
||||
|
||||
(minSimpleLoc.chunk.x until maxSimpleLoc.chunk.x + 1).forEach { curX ->
|
||||
(minSimpleLoc.chunk.z until maxSimpleLoc.chunk.z + 1).forEach { curZ ->
|
||||
foundChunks += SimpleChunkLocation(curX, curZ)
|
||||
} }
|
||||
(minSimpleLoc.chunk.z until maxSimpleLoc.chunk.z + 1).forEach { curZ ->
|
||||
foundChunks += SimpleChunkLocation(curX, curZ)
|
||||
}
|
||||
}
|
||||
|
||||
return@lazy foundChunks
|
||||
|
||||
@@ -77,9 +78,9 @@ class LocationArea(loc1: Location, loc2: Location) {
|
||||
val touchedChunks: Set<Chunk> get() = simpleLocationPair.touchedSimpleChunks.mapTo(HashSet()) { it.withWorld(world) }
|
||||
|
||||
fun isInArea(
|
||||
loc: Location,
|
||||
check3d: Boolean = true,
|
||||
tolerance: Int = 0
|
||||
loc: Location,
|
||||
check3d: Boolean = true,
|
||||
tolerance: Int = 0
|
||||
) = simpleLocationPair.isInArea(loc, check3d, tolerance)
|
||||
|
||||
}
|
@@ -12,10 +12,12 @@ import org.bukkit.util.Vector
|
||||
// INCREASE
|
||||
// all
|
||||
infix fun Location.increase(distance: Number) = add(distance, distance, distance)
|
||||
|
||||
// single
|
||||
infix fun Location.increaseX(distance: Number) = add(distance, 0.0, 0.0)
|
||||
infix fun Location.increaseY(distance: Number) = add(0.0, distance, 0.0)
|
||||
infix fun Location.increaseZ(distance: Number) = add(0.0, 0.0, distance)
|
||||
|
||||
// pair
|
||||
infix fun Location.increaseXY(distance: Number) = add(distance, distance, 0.0)
|
||||
infix fun Location.increaseYZ(distance: Number) = add(0.0, distance, distance)
|
||||
@@ -24,10 +26,12 @@ infix fun Location.increaseXZ(distance: Number) = add(distance, 0.0, distance)
|
||||
// REDUCE
|
||||
// all
|
||||
infix fun Location.reduce(distance: Number) = substract(distance, distance, distance)
|
||||
|
||||
// single
|
||||
infix fun Location.reduceX(distance: Number) = substract(distance, 0.0, 0.0)
|
||||
infix fun Location.reduceY(distance: Number) = substract(0.0, distance, 0.0)
|
||||
infix fun Location.reduceZ(distance: Number) = substract(0.0, 0.0, distance)
|
||||
|
||||
// pair
|
||||
infix fun Location.reduceXY(distance: Number) = substract(distance, distance, 0.0)
|
||||
infix fun Location.reduceYZ(distance: Number) = substract(0.0, distance, distance)
|
||||
@@ -50,13 +54,32 @@ operator fun Location.plus(loc: Location) = clone().add(loc)
|
||||
operator fun Location.minus(loc: Location) = clone().subtract(loc)
|
||||
operator fun Location.plus(loc: SimpleLocation3D) = clone().add(loc.x, loc.y, loc.z)
|
||||
operator fun Location.minus(loc: SimpleLocation3D) = clone().subtract(loc.x, loc.y, loc.z)
|
||||
|
||||
// mutable
|
||||
operator fun Location.plusAssign(vec: Vector) { add(vec) }
|
||||
operator fun Location.minusAssign(vec: Vector) { subtract(vec) }
|
||||
operator fun Location.plusAssign(loc: Location) { add(loc) }
|
||||
operator fun Location.minusAssign(loc: Location) { subtract(loc) }
|
||||
operator fun Location.plusAssign(loc: SimpleLocation3D) { add(loc.x, loc.y, loc.z) }
|
||||
operator fun Location.minusAssign(loc: SimpleLocation3D) { subtract(loc.x, loc.y, loc.z) }
|
||||
operator fun Location.plusAssign(vec: Vector) {
|
||||
add(vec)
|
||||
}
|
||||
|
||||
operator fun Location.minusAssign(vec: Vector) {
|
||||
subtract(vec)
|
||||
}
|
||||
|
||||
operator fun Location.plusAssign(loc: Location) {
|
||||
add(loc)
|
||||
}
|
||||
|
||||
operator fun Location.minusAssign(loc: Location) {
|
||||
subtract(loc)
|
||||
}
|
||||
|
||||
operator fun Location.plusAssign(loc: SimpleLocation3D) {
|
||||
add(loc.x, loc.y, loc.z)
|
||||
}
|
||||
|
||||
operator fun Location.minusAssign(loc: SimpleLocation3D) {
|
||||
subtract(loc.x, loc.y, loc.z)
|
||||
}
|
||||
|
||||
// mutable with return
|
||||
infix fun Location.increase(vec: Vector) = add(vec)
|
||||
infix fun Location.reduce(vec: Vector) = subtract(vec)
|
||||
@@ -86,11 +109,24 @@ operator fun Vector.plus(vec: Vector) = clone().add(vec)
|
||||
operator fun Vector.minus(vec: Vector) = clone().subtract(vec)
|
||||
operator fun Vector.times(vec: Vector) = clone().multiply(vec)
|
||||
operator fun Vector.times(num: Number) = clone().multiply(num.toDouble())
|
||||
|
||||
// mutable
|
||||
operator fun Vector.plusAssign(vec: Vector) { add(vec) }
|
||||
operator fun Vector.minusAssign(vec: Vector) { subtract(vec) }
|
||||
operator fun Vector.timesAssign(vec: Vector) { multiply(vec) }
|
||||
operator fun Vector.timesAssign(num: Number) { multiply(num.toDouble()) }
|
||||
operator fun Vector.plusAssign(vec: Vector) {
|
||||
add(vec)
|
||||
}
|
||||
|
||||
operator fun Vector.minusAssign(vec: Vector) {
|
||||
subtract(vec)
|
||||
}
|
||||
|
||||
operator fun Vector.timesAssign(vec: Vector) {
|
||||
multiply(vec)
|
||||
}
|
||||
|
||||
operator fun Vector.timesAssign(num: Number) {
|
||||
multiply(num.toDouble())
|
||||
}
|
||||
|
||||
// mutable with return
|
||||
infix fun Vector.increase(vec: Vector) = add(vec)
|
||||
infix fun Vector.reduce(vec: Vector) = subtract(vec)
|
||||
|
Reference in New Issue
Block a user