Skip to content

Commit ec78ed9

Browse files
committed
Update and apply ktlint
1 parent 88b558f commit ec78ed9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+604
-448
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ subprojects {
3636

3737
configure<SpotlessExtension> {
3838
kotlin {
39-
ktlint("0.48.2")
39+
ktlint("1.5.0")
4040
}
4141
}
4242

examples/src/main/kotlin/com/noxcrew/interfaces/example/CatalogueExampleInterface.kt

+12-10
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ import org.bukkit.Material
1010
public class CatalogueExampleInterface : RegistrableInterface {
1111
override val subcommand: String = "catalogue"
1212

13-
override fun create(): Interface<*, *> = buildCombinedInterface {
14-
rows = 1
13+
override fun create(): Interface<*, *> =
14+
buildCombinedInterface {
15+
rows = 1
1516

16-
withTransform { pane, _ ->
17-
pane[3, 3] = StaticElement(
18-
Drawable.drawable(Material.STICK),
19-
) { (player) ->
20-
runBlocking {
21-
ChangingTitleExampleInterface().create().open(player)
22-
}
17+
withTransform { pane, _ ->
18+
pane[3, 3] =
19+
StaticElement(
20+
Drawable.drawable(Material.STICK),
21+
) { (player) ->
22+
runBlocking {
23+
ChangingTitleExampleInterface().create().open(player)
24+
}
25+
}
2326
}
2427
}
25-
}
2628
}

examples/src/main/kotlin/com/noxcrew/interfaces/example/ChangingTitleExampleInterface.kt

+18-16
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,31 @@ import org.bukkit.Material
1010
import org.bukkit.inventory.ItemStack
1111

1212
public class ChangingTitleExampleInterface : RegistrableInterface {
13-
1413
override val subcommand: String = "changing-title"
1514

16-
override fun create(): Interface<*, *> = buildChestInterface {
17-
rows = 1
15+
override fun create(): Interface<*, *> =
16+
buildChestInterface {
17+
rows = 1
1818

19-
// Allow clicking the player inventory but not anything in the top inventory
20-
allowClickingOwnInventoryIfClickingEmptySlotsIsPrevented = true
19+
// Allow clicking the player inventory but not anything in the top inventory
20+
allowClickingOwnInventoryIfClickingEmptySlotsIsPrevented = true
2121

22-
val numberProperty = interfaceProperty(0)
23-
var number by numberProperty
22+
val numberProperty = interfaceProperty(0)
23+
var number by numberProperty
2424

25-
withTransform(numberProperty) { pane, view ->
26-
view.title(Component.text(number))
25+
withTransform(numberProperty) { pane, view ->
26+
view.title(Component.text(number))
2727

28-
val item = ItemStack(Material.STICK)
29-
.name("number -> $number")
28+
val item =
29+
ItemStack(Material.STICK)
30+
.name("number -> $number")
3031

31-
pane[0, 4] = StaticElement(drawable(item)) {
32-
number += 1
33-
}
32+
pane[0, 4] =
33+
StaticElement(drawable(item)) {
34+
number += 1
35+
}
3436

35-
pane[0, 6] = StaticElement(drawable(Material.ACACIA_SIGN))
37+
pane[0, 6] = StaticElement(drawable(Material.ACACIA_SIGN))
38+
}
3639
}
37-
}
3840
}

examples/src/main/kotlin/com/noxcrew/interfaces/example/DelayedRequestExampleInterface.kt

+21-20
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,39 @@ import org.bukkit.Material
1313
import kotlin.time.Duration.Companion.seconds
1414

1515
public class DelayedRequestExampleInterface : RegistrableInterface {
16-
1716
private companion object {
1817
private val BACKING_ELEMENT = StaticElement(Drawable.drawable(Material.GRAY_CONCRETE))
1918
}
2019

2120
override val subcommand: String = "delayed"
2221

2322
@OptIn(DelicateCoroutinesApi::class)
24-
override fun create(): Interface<*, *> = buildChestInterface {
25-
initialTitle = text(subcommand)
26-
rows = 2
27-
28-
withTransform { pane, _ ->
29-
suspendingData().forEachIndexed { index, material ->
30-
pane[0, index] = StaticElement(Drawable.drawable(material))
31-
}
32-
}
33-
34-
withTransform { pane, _ ->
35-
for (index in 0..8) {
36-
pane[1, index] = BACKING_ELEMENT
23+
override fun create(): Interface<*, *> =
24+
buildChestInterface {
25+
initialTitle = text(subcommand)
26+
rows = 2
27+
28+
withTransform { pane, _ ->
29+
suspendingData().forEachIndexed { index, material ->
30+
pane[0, index] = StaticElement(Drawable.drawable(material))
31+
}
3732
}
3833

39-
pane[0, 8] = StaticElement(Drawable.drawable(Material.ENDER_PEARL)) {
40-
// This is very unsafe, it's up to you to set up a way to reliably
41-
// launch coroutines per player in a click handler.
42-
GlobalScope.launch {
43-
it.view.back()
34+
withTransform { pane, _ ->
35+
for (index in 0..8) {
36+
pane[1, index] = BACKING_ELEMENT
4437
}
38+
39+
pane[0, 8] =
40+
StaticElement(Drawable.drawable(Material.ENDER_PEARL)) {
41+
// This is very unsafe, it's up to you to set up a way to reliably
42+
// launch coroutines per player in a click handler.
43+
GlobalScope.launch {
44+
it.view.back()
45+
}
46+
}
4547
}
4648
}
47-
}
4849

4950
private suspend fun suspendingData(): List<Material> {
5051
delay(3.seconds)

examples/src/main/kotlin/com/noxcrew/interfaces/example/ExamplePlugin.kt

+83-66
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ import org.incendo.cloud.kotlin.coroutines.extension.suspendingHandler
2222
import org.incendo.cloud.kotlin.extension.buildAndRegister
2323
import org.incendo.cloud.paper.LegacyPaperCommandManager
2424

25-
public class ExamplePlugin : JavaPlugin(), Listener {
26-
25+
public class ExamplePlugin :
26+
JavaPlugin(),
27+
Listener {
2728
private companion object {
28-
private val INTERFACES = listOf(
29-
DelayedRequestExampleInterface(),
30-
ChangingTitleExampleInterface(),
31-
CatalogueExampleInterface(),
32-
MovingExampleInterface(),
33-
TabbedExampleInterface(),
34-
)
29+
private val INTERFACES =
30+
listOf(
31+
DelayedRequestExampleInterface(),
32+
ChangingTitleExampleInterface(),
33+
CatalogueExampleInterface(),
34+
MovingExampleInterface(),
35+
TabbedExampleInterface(),
36+
)
3537
}
3638

3739
private val counterProperty = interfaceProperty(5)
@@ -112,93 +114,108 @@ public class ExamplePlugin : JavaPlugin(), Listener {
112114
)
113115
}
114116

115-
private fun simpleInterface() = buildChestInterface {
116-
rows = 6
117+
private fun simpleInterface() =
118+
buildChestInterface {
119+
rows = 6
117120

118-
withTransform(counterProperty) { pane, _ ->
119-
val item = ItemStack(Material.BEE_NEST)
120-
.name("it's been $counter's ticks")
121-
.description("click to see the ticks now")
121+
withTransform(counterProperty) { pane, _ ->
122+
val item =
123+
ItemStack(Material.BEE_NEST)
124+
.name("it's been $counter's ticks")
125+
.description("click to see the ticks now")
122126

123-
pane[3, 3] = StaticElement(drawable(item)) {
124-
it.player.sendMessage("it's been $counter's ticks")
127+
pane[3, 3] =
128+
StaticElement(drawable(item)) {
129+
it.player.sendMessage("it's been $counter's ticks")
130+
}
125131
}
126-
}
127132

128-
withTransform { pane, _ ->
129-
val item = ItemStack(Material.BEE_NEST)
130-
.name("block the interface")
131-
.description("block interaction and message in 5 seconds")
133+
withTransform { pane, _ ->
134+
val item =
135+
ItemStack(Material.BEE_NEST)
136+
.name("block the interface")
137+
.description("block interaction and message in 5 seconds")
132138

133-
pane[5, 3] = StaticElement(drawable(item)) {
134-
completingLater = true
139+
pane[5, 3] =
140+
StaticElement(drawable(item)) {
141+
completingLater = true
135142

136-
runAsync(5) {
137-
it.player.sendMessage("after blocking, it has been $counter's ticks")
138-
complete()
139-
}
143+
runAsync(5) {
144+
it.player.sendMessage("after blocking, it has been $counter's ticks")
145+
complete()
146+
}
147+
}
140148
}
141-
}
142149

143-
withTransform { pane, _ ->
144-
forEachInGrid(6, 9) { row, column ->
145-
if (pane.has(row, column)) return@forEachInGrid
150+
withTransform { pane, _ ->
151+
forEachInGrid(6, 9) { row, column ->
152+
if (pane.has(row, column)) return@forEachInGrid
146153

147-
val item = ItemStack(Material.WHITE_STAINED_GLASS_PANE)
148-
.name("row: $row, column: $column")
154+
val item =
155+
ItemStack(Material.WHITE_STAINED_GLASS_PANE)
156+
.name("row: $row, column: $column")
149157

150-
pane[row, column] = StaticElement(drawable(item))
158+
pane[row, column] = StaticElement(drawable(item))
159+
}
151160
}
152161
}
153-
}
154162

155-
private fun playerInterface() = buildPlayerInterface {
156-
// Use modern logic to only cancel the item interaction and not block interactions while
157-
// using this interface
158-
onlyCancelItemInteraction = true
163+
private fun playerInterface() =
164+
buildPlayerInterface {
165+
// Use modern logic to only cancel the item interaction and not block interactions while
166+
// using this interface
167+
onlyCancelItemInteraction = true
159168

160-
// Prioritise block interactions!
161-
prioritiseBlockInteractions = true
169+
// Prioritise block interactions!
170+
prioritiseBlockInteractions = true
162171

163-
withTransform { pane, _ ->
164-
val item = ItemStack(Material.COMPASS).name("interfaces example")
172+
withTransform { pane, _ ->
173+
val item = ItemStack(Material.COMPASS).name("interfaces example")
165174

166-
pane.hotbar[3] = StaticElement(drawable(item)) { (player) ->
167-
player.sendMessage("hello")
168-
}
175+
pane.hotbar[3] =
176+
StaticElement(drawable(item)) { (player) ->
177+
player.sendMessage("hello")
178+
}
169179

170-
pane.offHand = StaticElement(drawable(item)) { (player) ->
171-
player.sendMessage("hey")
172-
}
180+
pane.offHand =
181+
StaticElement(drawable(item)) { (player) ->
182+
player.sendMessage("hey")
183+
}
173184

174-
val armor = ItemStack(Material.STICK)
185+
val armor = ItemStack(Material.STICK)
175186

176-
pane.armor.helmet = StaticElement(drawable(armor.name("helmet").clone()))
187+
pane.armor.helmet = StaticElement(drawable(armor.name("helmet").clone()))
177188

178-
pane.armor.chest = StaticElement(drawable(armor.name("chest").clone()))
189+
pane.armor.chest = StaticElement(drawable(armor.name("chest").clone()))
179190

180-
pane.armor.leggings = StaticElement(drawable(armor.name("leggings").clone()))
191+
pane.armor.leggings = StaticElement(drawable(armor.name("leggings").clone()))
181192

182-
pane.armor.boots = StaticElement(drawable(armor.name("boots").clone()))
193+
pane.armor.boots = StaticElement(drawable(armor.name("boots").clone()))
194+
}
183195
}
184-
}
185196

186-
private fun combinedInterface() = buildCombinedInterface {
187-
rows = 6
197+
private fun combinedInterface() =
198+
buildCombinedInterface {
199+
rows = 6
188200

189-
withTransform { pane, _ ->
190-
forEachInGrid(10, 9) { row, column ->
191-
val item = ItemStack(Material.WHITE_STAINED_GLASS_PANE)
192-
.name("row: $row, column: $column")
201+
withTransform { pane, _ ->
202+
forEachInGrid(10, 9) { row, column ->
203+
val item =
204+
ItemStack(Material.WHITE_STAINED_GLASS_PANE)
205+
.name("row: $row, column: $column")
193206

194-
pane[row, column] = StaticElement(drawable(item)) { (player) ->
195-
player.sendMessage("row: $row, column: $column")
207+
pane[row, column] =
208+
StaticElement(drawable(item)) { (player) ->
209+
player.sendMessage("row: $row, column: $column")
210+
}
196211
}
197212
}
198213
}
199-
}
200214

201-
private fun runAsync(delay: Int, runnable: Runnable) {
215+
private fun runAsync(
216+
delay: Int,
217+
runnable: Runnable,
218+
) {
202219
Bukkit.getScheduler().runTaskLaterAsynchronously(this, runnable, delay * 20L)
203220
}
204221
}

examples/src/main/kotlin/com/noxcrew/interfaces/example/ExampleUtilities.kt

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import net.kyori.adventure.text.Component
44
import org.bukkit.inventory.ItemStack
55

66
public fun ItemStack.name(name: String): ItemStack {
7-
itemMeta = itemMeta.also { meta ->
8-
meta.displayName(Component.text(name))
9-
}
7+
itemMeta =
8+
itemMeta.also { meta ->
9+
meta.displayName(Component.text(name))
10+
}
1011
return this
1112
}
1213

1314
public fun ItemStack.description(description: String): ItemStack {
14-
itemMeta = itemMeta.also { meta ->
15-
meta.lore(listOf(Component.text(description)))
16-
}
15+
itemMeta =
16+
itemMeta.also { meta ->
17+
meta.lore(listOf(Component.text(description)))
18+
}
1719
return this
1820
}

examples/src/main/kotlin/com/noxcrew/interfaces/example/MovingExampleInterface.kt

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ import org.bukkit.Material
1010
public class MovingExampleInterface : RegistrableInterface {
1111
override val subcommand: String = "moving"
1212

13-
override fun create(): Interface<*, *> = buildChestInterface {
14-
val countProperty = BoundInteger(4, 1, 7)
15-
var count by countProperty
13+
override fun create(): Interface<*, *> =
14+
buildChestInterface {
15+
val countProperty = BoundInteger(4, 1, 7)
16+
var count by countProperty
1617

17-
// Allow clicking empty slots to allow testing various interactions with tiems and chest interfaces
18-
preventClickingEmptySlots = false
18+
// Allow clicking empty slots to allow testing various interactions with tiems and chest interfaces
19+
preventClickingEmptySlots = false
1920

20-
rows = 1
21+
rows = 1
2122

22-
withTransform(countProperty) { pane, _ ->
23-
pane[0, 0] = StaticElement(drawable(Material.RED_CONCRETE)) { count-- }
24-
pane[0, 8] = StaticElement(drawable(Material.GREEN_CONCRETE)) { count++ }
23+
withTransform(countProperty) { pane, _ ->
24+
pane[0, 0] = StaticElement(drawable(Material.RED_CONCRETE)) { count-- }
25+
pane[0, 8] = StaticElement(drawable(Material.GREEN_CONCRETE)) { count++ }
2526

26-
pane[0, count] = StaticElement(drawable(Material.STICK))
27+
pane[0, count] = StaticElement(drawable(Material.STICK))
28+
}
2729
}
28-
}
2930
}

0 commit comments

Comments
 (0)