Update formatting

This commit is contained in:
Jakob K
2021-05-15 21:26:10 +02:00
parent ddc576a394
commit fa8fa9ae96
71 changed files with 203 additions and 249 deletions

View File

@@ -46,4 +46,4 @@ val console get() = Bukkit.getConsoleSender()
/**
* Shortcut for creating a new [NamespacedKey]
*/
fun pluginKey(key: String) = NamespacedKey(KSpigotMainInstance, key)
fun pluginKey(key: String) = NamespacedKey(KSpigotMainInstance, key)

View File

@@ -1,5 +1,7 @@
package net.axay.kspigot.extensions.bukkit
// FROM BUNGEE COLOR
/**
* Returns the corresponding Bukkit Color object.
*/
@@ -12,7 +14,9 @@ val net.md_5.bungee.api.ChatColor.bukkitColor
*/
val net.md_5.bungee.api.ChatColor.javaAwtColor: java.awt.Color
get() = color
// FROM BUKKIT COLOR
/**
* Returns the corresponding Bungee Color object.
*/
@@ -24,7 +28,9 @@ val org.bukkit.Color.bungeeColor: net.md_5.bungee.api.ChatColor
*/
val org.bukkit.Color.javaAwtColor: java.awt.Color
get() = java.awt.Color(asRGB())
// FROM JAVA AWT COLOR
/**
* Returns the corresponding Bukkit Color object.
*/
@@ -36,7 +42,9 @@ val java.awt.Color.bukkitColor
*/
val java.awt.Color.bungeeColor: net.md_5.bungee.api.ChatColor
get() = net.md_5.bungee.api.ChatColor.of(this)
// FROM BUKKIT CHAT COLOR
/**
* Returns the corresponding Bukkit Color object.
*/
@@ -53,4 +61,4 @@ val org.bukkit.ChatColor.bungeeColor: net.md_5.bungee.api.ChatColor
* Returns the corresponding Java Color object.
*/
val org.bukkit.ChatColor.javaAwtColor: java.awt.Color
get() = bungeeColor.javaAwtColor
get() = bungeeColor.javaAwtColor

View File

@@ -17,4 +17,4 @@ fun CommandExecutor.register(commandName: String): Boolean {
return true
}
return false
}
}

View File

@@ -29,4 +29,4 @@ fun CommandSender.error(text: String, plugin: Plugin? = KSpigotMainInstance) =
* 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")
sendMessage("${prefixColor}[${prefix}]${textColor} $text")

View File

@@ -14,11 +14,6 @@ import org.bukkit.entity.*
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
/**
* Checks if the entity is completely in water.
*/
val LivingEntity.isInWater: Boolean get() = isFeetInWater && isHeadInWater
/**
* Checks if the entities' head is in water.
*/
@@ -167,4 +162,4 @@ fun Player.sendToServer(servername: String) {
* Adds the given ItemStacks to the player's inventory.
* @return The items that did not fit into the player's inventory.
*/
fun Player.give(vararg itemStacks: ItemStack) = inventory.addItem(*itemStacks)
fun Player.give(vararg itemStacks: ItemStack) = inventory.addItem(*itemStacks)

View File

@@ -9,4 +9,4 @@ val GameMode.isDamageable: Boolean
get() = when (this) {
GameMode.SURVIVAL, GameMode.ADVENTURE -> true
GameMode.SPECTATOR, GameMode.CREATIVE -> false
}
}

View File

@@ -23,4 +23,4 @@ val Chunk.allBlocks
for (z in 0 until 16)
add(getBlock(x, y, z))
}
}
}

View File

@@ -10,4 +10,4 @@ val BookMeta.content
append('\n')
append(it)
}
}.toString()
}.toString()

View File

@@ -18,4 +18,4 @@ val PrepareItemCraftEvent.isCancelled: Boolean
*/
fun PrepareItemCraftEvent.cancel() {
this.inventory.result = ItemStack(Material.AIR)
}
}

View File

@@ -32,10 +32,11 @@ data class SimpleChunkLocation(
val x: Int,
val z: Int,
)
// CONVERTER
fun Location.toSimple() = SimpleLocation3D(x, y, z)
fun Chunk.toSimple() = SimpleChunkLocation(x, z)
fun SimpleLocation3D.withWorld(world: World) = Location(world, x, y, z).apply { direction = this@withWorld.direction }
fun SimpleChunkLocation.withWorld(world: World) = world.getChunkAt(x, z)
fun Vector.toSimpleLoc() = SimpleLocation3D(x, y, z)
fun SimpleLocation3D.toVector() = Vector(x, y, z)
fun SimpleLocation3D.toVector() = Vector(x, y, z)

View File

@@ -14,8 +14,10 @@ class SimpleLocationPair(loc1: Location, loc2: Location) {
if (it == loc2.worldOrException) it
else throw IllegalArgumentException("The given locations worlds are not the same!")
}
val minSimpleLoc = SimpleLocation3D(min(loc1.x, loc2.x), min(loc1.y, loc2.y), min(loc1.z, loc2.z))
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,
@@ -59,14 +61,19 @@ class LocationArea(loc1: Location, loc2: Location) {
field = value
simpleLocationPair = SimpleLocationPair(loc1, value)
}
var simpleLocationPair = SimpleLocationPair(loc1, loc2); private set
val world: World get() = simpleLocationPair.world
val minLoc: Location get() = simpleLocationPair.minSimpleLoc.withWorld(simpleLocationPair.world)
val maxLoc: Location get() = simpleLocationPair.maxSimpleLoc.withWorld(simpleLocationPair.world)
val touchedChunks: Set<Chunk> get() = simpleLocationPair.touchedSimpleChunks.mapTo(HashSet()) { it.withWorld(world) }
fun isInArea(
loc: Location,
check3d: Boolean = true,
tolerance: Int = 0,
) = simpleLocationPair.isInArea(loc, check3d, tolerance)
}
}

View File

@@ -36,6 +36,7 @@ infix fun Location.reduceZ(distance: Number) = subtract(0.0, 0.0, distance)
infix fun Location.reduceXY(distance: Number) = subtract(distance, distance, 0.0)
infix fun Location.reduceYZ(distance: Number) = subtract(0.0, distance, distance)
infix fun Location.reduceXZ(distance: Number) = subtract(distance, 0.0, distance)
// extensions
fun Location.add(x: Number, y: Number, z: Number) = add(x.toDouble(), y.toDouble(), z.toDouble())
fun Location.subtract(x: Number, y: Number, z: Number) = subtract(x.toDouble(), y.toDouble(), z.toDouble())
@@ -83,9 +84,11 @@ infix fun Location.increase(loc: Location) = add(loc)
infix fun Location.reduce(loc: Location) = subtract(loc)
infix fun Location.increase(loc: SimpleLocation3D) = add(loc.x, loc.y, loc.z)
infix fun Location.reduce(loc: SimpleLocation3D) = subtract(loc.x, loc.y, loc.z)
/*
* VECTOR
*/
val Vector.isFinite: Boolean get() = x.isFinite() && y.isFinite() && z.isFinite()
// fast construct
@@ -125,4 +128,4 @@ operator fun Vector.timesAssign(num: Number) {
infix fun Vector.increase(vec: Vector) = add(vec)
infix fun Vector.reduce(vec: Vector) = subtract(vec)
infix fun Vector.multiply(vec: Vector) = multiply(vec)
infix fun Vector.multiply(num: Number) = multiply(num.toDouble())
infix fun Vector.multiply(num: Number) = multiply(num.toDouble())