Skip to content

Commit

Permalink
Reformat using Kotlin style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickster258 committed Jun 14, 2020
1 parent 345b15d commit 3b9eaf9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
21 changes: 9 additions & 12 deletions src/main/kotlin/Find.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -88,32 +87,30 @@ class Find(private val worldEdit: WorldEdit) : BaseCommand() {
}
}

class FindPaginationBox(private val locations: MutableList<BlockVector3>, title: String, command: String):
PaginationBox("${ChatColor.LIGHT_PURPLE}$title", command)
{
class FindPaginationBox(private val locations: MutableList<BlockVector3>, 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]}")
.color(TextColor.LIGHT_PURPLE)
.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<BukkitCommandCompletionContext>
{
class FindPageCompletionHandler :
CommandCompletions.CommandCompletionHandler<BukkitCommandCompletionContext> {
override fun getCompletions(context: BukkitCommandCompletionContext): Collection<String> {
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<BukkitCommandCompletionContext>
{
class FindCompletionHandler(worldEdit: WorldEdit) :
CommandCompletions.CommandCompletionHandler<BukkitCommandCompletionContext> {
private val maskFactory = MaskFactory(worldEdit)
override fun getCompletions(context: BukkitCommandCompletionContext): Collection<String> {
return maskFactory.getSuggestions(context.input)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/NbtUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ fun NBTItem.addFakeEnchant() {

// 😎
@Suppress("UNCHECKED_CAST")
inline fun <T: ItemMeta> ItemStack.modifyMeta(action: T.() -> Unit) {
inline fun <T : ItemMeta> ItemStack.modifyMeta(action: T.() -> Unit) {
itemMeta = (itemMeta as T).apply(action)
}
18 changes: 9 additions & 9 deletions src/main/kotlin/RStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class RStack(private val worldEdit: WorldEdit) : BaseCommand() {
@Default
@Syntax("[-e] [direction] [count] [spacing]")
fun rstack(
player: Player,
args: Array<String>
player: Player,
args: Array<String>
) {
var expand = false
var direction: String? = null
Expand Down Expand Up @@ -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 <E> List<E>.getOrDefault(index: Int, default: E): E = getOrNull(index) ?: default
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/RedstoneTools.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
throwable: Throwable
command: BaseCommand,
registeredCommand: RegisteredCommand<*>,
sender: CommandIssuer,
args: List<String>,
throwable: Throwable
): Boolean {
val exception = throwable as? RedstoneToolsException
if (exception == null) {
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/Slab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Slab : BaseCommand() {
@Default
@CommandCompletion("@slabs")
fun slab(
player: Player,
args: Array<String>
player: Player,
args: Array<String>
) {
val slab: ItemStack?
if (args.isNotEmpty()) {
Expand All @@ -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
Expand All @@ -53,8 +53,7 @@ class Slab : BaseCommand() {
}

class SlabCompletionHandler :
CommandCompletions.CommandCompletionHandler<BukkitCommandCompletionContext>
{
CommandCompletions.CommandCompletionHandler<BukkitCommandCompletionContext> {
override fun getCompletions(context: BukkitCommandCompletionContext?): MutableCollection<String> =
Material.values().filter {
it.isBlock && (it.createBlockData() is Slab)
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/WorldEditHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3b9eaf9

Please sign in to comment.