From 3b9eaf996c58c8300a5369bf9d99b150be917ac6 Mon Sep 17 00:00:00 2001 From: Nicholas Stonecipher Date: Sun, 14 Jun 2020 17:28:42 -0400 Subject: [PATCH] Reformat using Kotlin style guide --- src/main/kotlin/Find.kt | 21 +++++++++------------ src/main/kotlin/NbtUtil.kt | 2 +- src/main/kotlin/RStack.kt | 18 +++++++++--------- src/main/kotlin/RedstoneTools.kt | 12 ++++++------ src/main/kotlin/Slab.kt | 9 ++++----- src/main/kotlin/WorldEditHelper.kt | 6 +++--- 6 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/main/kotlin/Find.kt b/src/main/kotlin/Find.kt index 4e6a041..1a6bfc7 100644 --- a/src/main/kotlin/Find.kt +++ b/src/main/kotlin/Find.kt @@ -23,8 +23,7 @@ import com.sk89q.worldedit.util.formatting.text.event.HoverEvent import com.sk89q.worldedit.util.formatting.text.format.TextColor import org.bukkit.ChatColor import org.bukkit.entity.Player -import java.lang.IllegalArgumentException -import java.util.UUID +import java.util.* import kotlin.collections.HashMap import kotlin.math.ceil @@ -88,9 +87,8 @@ class Find(private val worldEdit: WorldEdit) : BaseCommand() { } } -class FindPaginationBox(private val locations: MutableList, title: String, command: String): - PaginationBox("${ChatColor.LIGHT_PURPLE}$title", command) -{ +class FindPaginationBox(private val locations: MutableList, title: String, command: String) : + PaginationBox("${ChatColor.LIGHT_PURPLE}$title", command) { override fun getComponent(number: Int): Component { if (number > locations.size) throw IllegalArgumentException("Invalid location index.") return TextComponent.of("${number}: ${locations[number]}") @@ -98,22 +96,21 @@ class FindPaginationBox(private val locations: MutableList, title: .clickEvent(ClickEvent.runCommand("/tp ${locations[number].x} ${locations[number].y} ${locations[number].z}")) .hoverEvent(HoverEvent.showText(TextComponent.of("Click to teleport"))) } + override fun getComponentsSize(): Int = locations.size } -class FindPageCompletionHandler: - CommandCompletions.CommandCompletionHandler -{ +class FindPageCompletionHandler : + CommandCompletions.CommandCompletionHandler { override fun getCompletions(context: BukkitCommandCompletionContext): Collection { val player = context.sender as Player val locations = findResults[player.uniqueId] ?: return emptyList() - return (1..ceil(locations.size/8f).toInt()).map { it.toString() }.toList() + return (1..ceil(locations.size / 8f).toInt()).map { it.toString() }.toList() } } -class FindCompletionHandler(worldEdit: WorldEdit): - CommandCompletions.CommandCompletionHandler -{ +class FindCompletionHandler(worldEdit: WorldEdit) : + CommandCompletions.CommandCompletionHandler { private val maskFactory = MaskFactory(worldEdit) override fun getCompletions(context: BukkitCommandCompletionContext): Collection { return maskFactory.getSuggestions(context.input) diff --git a/src/main/kotlin/NbtUtil.kt b/src/main/kotlin/NbtUtil.kt index ff3994c..4b55652 100644 --- a/src/main/kotlin/NbtUtil.kt +++ b/src/main/kotlin/NbtUtil.kt @@ -16,6 +16,6 @@ fun NBTItem.addFakeEnchant() { // 😎 @Suppress("UNCHECKED_CAST") -inline fun ItemStack.modifyMeta(action: T.() -> Unit) { +inline fun ItemStack.modifyMeta(action: T.() -> Unit) { itemMeta = (itemMeta as T).apply(action) } diff --git a/src/main/kotlin/RStack.kt b/src/main/kotlin/RStack.kt index be4a36e..ca8963e 100644 --- a/src/main/kotlin/RStack.kt +++ b/src/main/kotlin/RStack.kt @@ -32,8 +32,8 @@ class RStack(private val worldEdit: WorldEdit) : BaseCommand() { @Default @Syntax("[-e] [direction] [count] [spacing]") fun rstack( - player: Player, - args: Array + player: Player, + args: Array ) { var expand = false var direction: String? = null @@ -129,17 +129,17 @@ class RStack(private val worldEdit: WorldEdit) : BaseCommand() { // diagonal direction, need to add the y-component // negative pitch is upwards return vec.add( - if (pitch < 0) { - Direction.UP - } else { - Direction.DOWN - }.toBlockVector() + if (pitch < 0) { + Direction.UP + } else { + Direction.DOWN + }.toBlockVector() ) } private fun isDiagDirStr(direction: String, upOrDown: Char) = - // check length, because 'd' and 'u' alone are not diagonal directions (they're just up or down) - direction.length > 1 && direction.last().toLowerCase() == upOrDown + // check length, because 'd' and 'u' alone are not diagonal directions (they're just up or down) + direction.length > 1 && direction.last().toLowerCase() == upOrDown } private fun List.getOrDefault(index: Int, default: E): E = getOrNull(index) ?: default diff --git a/src/main/kotlin/RedstoneTools.kt b/src/main/kotlin/RedstoneTools.kt index 52a6e87..45b576a 100644 --- a/src/main/kotlin/RedstoneTools.kt +++ b/src/main/kotlin/RedstoneTools.kt @@ -5,17 +5,16 @@ import com.sk89q.worldedit.bukkit.WorldEditPlugin import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.plugin.java.JavaPlugin -import java.lang.Exception import java.util.logging.Level class RedstoneTools : JavaPlugin() { private fun handleCommandException( - command: BaseCommand, - registeredCommand: RegisteredCommand<*>, - sender: CommandIssuer, - args: List, - throwable: Throwable + command: BaseCommand, + registeredCommand: RegisteredCommand<*>, + sender: CommandIssuer, + args: List, + throwable: Throwable ): Boolean { val exception = throwable as? RedstoneToolsException if (exception == null) { @@ -79,6 +78,7 @@ class SignalStrength(val value: Int) { in intValues -> SignalStrength(arg.toInt()) else -> null } + private val intValues = (0..15).map(Int::toString) private val hexValues = ('a'..'f').map(Char::toString) val values = intValues + hexValues diff --git a/src/main/kotlin/Slab.kt b/src/main/kotlin/Slab.kt index e45d592..cfcacf6 100644 --- a/src/main/kotlin/Slab.kt +++ b/src/main/kotlin/Slab.kt @@ -18,8 +18,8 @@ class Slab : BaseCommand() { @Default @CommandCompletion("@slabs") fun slab( - player: Player, - args: Array + player: Player, + args: Array ) { val slab: ItemStack? if (args.isNotEmpty()) { @@ -35,7 +35,7 @@ class Slab : BaseCommand() { } } - private fun getSlab(type: String) : ItemStack? { + private fun getSlab(type: String): ItemStack? { val material = Material.getMaterial(type.toUpperCase()) ?: return null if (!material.isBlock) return null val blockData = material.createBlockData() as? Slab ?: return null @@ -53,8 +53,7 @@ class Slab : BaseCommand() { } class SlabCompletionHandler : - CommandCompletions.CommandCompletionHandler -{ + CommandCompletions.CommandCompletionHandler { override fun getCompletions(context: BukkitCommandCompletionContext?): MutableCollection = Material.values().filter { it.isBlock && (it.createBlockData() is Slab) diff --git a/src/main/kotlin/WorldEditHelper.kt b/src/main/kotlin/WorldEditHelper.kt index 9039df1..416a4d8 100644 --- a/src/main/kotlin/WorldEditHelper.kt +++ b/src/main/kotlin/WorldEditHelper.kt @@ -62,9 +62,9 @@ class WorldEditHelper(plugin: JavaPlugin, private val worldEdit: WorldEdit) : Li } player.scoreboard = Bukkit.getScoreboardManager()!!.newScoreboard.apply { registerNewObjective( - Random.nextInt(1234567890).toString(), - "dummy", - "Current selection" + Random.nextInt(1234567890).toString(), + "dummy", + "Current selection" ).apply { displaySlot = DisplaySlot.SIDEBAR displayName = "${RED}Current Selection"