Skip to content

Commit 86550f2

Browse files
committed
Update generics to couple the interface, view and builder
1 parent 2cab50c commit 86550f2

16 files changed

+47
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.bukkit.Material
1010
public class CatalogueExampleInterface : RegistrableInterface {
1111
override val subcommand: String = "catalogue"
1212

13-
override fun create(): Interface<*> = buildCombinedInterface {
13+
override fun create(): Interface<*, *> = buildCombinedInterface {
1414
rows = 1
1515

1616
withTransform { pane, _ ->

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ChangingTitleExampleInterface : RegistrableInterface {
1313

1414
override val subcommand: String = "changing-title"
1515

16-
override fun create(): Interface<*> = buildCombinedInterface {
16+
override fun create(): Interface<*, *> = buildCombinedInterface {
1717
rows = 1
1818

1919
val numberProperty = interfaceProperty(0)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class DelayedRequestExampleInterface : RegistrableInterface {
2121
override val subcommand: String = "delayed"
2222

2323
@OptIn(DelicateCoroutinesApi::class)
24-
override fun create(): Interface<*> = buildCombinedInterface {
24+
override fun create(): Interface<*, *> = buildCombinedInterface {
2525
initialTitle = text(subcommand)
2626
rows = 2
2727

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.bukkit.Material
1010
public class MovingExampleInterface : RegistrableInterface {
1111
override val subcommand: String = "moving"
1212

13-
override fun create(): Interface<*> = buildCombinedInterface {
13+
override fun create(): Interface<*, *> = buildCombinedInterface {
1414
val countProperty = BoundInteger(4, 1, 7)
1515
var count by countProperty
1616

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ public interface RegistrableInterface {
66

77
public val subcommand: String
88

9-
public fun create(): Interface<*>
9+
public fun create(): Interface<*, *>
1010
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class TabbedExampleInterface : RegistrableInterface {
2020

2121
override val subcommand: String = "tabbed"
2222

23-
override fun create(): Interface<*> = first
23+
override fun create(): Interface<*, *> = first
2424

2525
private fun CombinedInterfaceBuilder.defaults() {
2626
rows = 6

interfaces/src/main/kotlin/com/noxcrew/interfaces/InterfacesListeners.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
150150
@EventHandler
151151
public fun onClose(event: InventoryCloseEvent) {
152152
val holder = event.inventory.holder
153-
val view = holder as? AbstractInterfaceView<*, *> ?: return
153+
val view = holder as? AbstractInterfaceView<*, *, *> ?: return
154154
val reason = event.reason
155155

156156
// Saves any persistent items stored in the given inventory before we close it
@@ -233,7 +233,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
233233
// Check if the action is prevented if this slot is not freely
234234
// movable
235235
if (!canFreelyMove(view, clickedPoint) &&
236-
event.action in view.backing.properties.preventedInteractions
236+
event.action in view.builder.preventedInteractions
237237
) {
238238
event.isCancelled = true
239239
return
@@ -336,11 +336,11 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
336336
* Converts an inventory holder to an [AbstractInterfaceView] if possible. If the holder is a player
337337
* their currently open player interface is returned.
338338
*/
339-
public fun convertHolderToInterfaceView(holder: InventoryHolder?): AbstractInterfaceView<*, *>? {
339+
public fun convertHolderToInterfaceView(holder: InventoryHolder?): AbstractInterfaceView<*, *, *>? {
340340
if (holder == null) return null
341341

342342
// If it's an abstract view use that one
343-
if (holder is AbstractInterfaceView<*, *>) return holder
343+
if (holder is AbstractInterfaceView<*, *, *>) return holder
344344

345345
// If it's the player's own inventory use the held one
346346
if (holder is HumanEntity) return getOpenInterface(holder.uniqueId)
@@ -350,13 +350,13 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
350350

351351
/** Returns whether [clickedPoint] in [view] can be freely moved. */
352352
private fun canFreelyMove(
353-
view: AbstractInterfaceView<*, *>,
353+
view: AbstractInterfaceView<*, *, *>,
354354
clickedPoint: GridPoint
355-
): Boolean = view.pane.getRaw(clickedPoint) == null && !view.backing.properties.preventClickingEmptySlots
355+
): Boolean = view.pane.getRaw(clickedPoint) == null && !view.builder.preventClickingEmptySlots
356356

357357
/** Handles a [view] being clicked at [clickedPoint] through some [event]. */
358358
private fun handleClick(
359-
view: AbstractInterfaceView<*, *>,
359+
view: AbstractInterfaceView<*, *, *>,
360360
clickedPoint: GridPoint,
361361
click: ClickType,
362362
event: Cancellable,
@@ -367,7 +367,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
367367

368368
// Optionally cancel clicking on other slots
369369
if (raw == null) {
370-
if (view.backing.properties.preventClickingEmptySlots) {
370+
if (view.builder.preventClickingEmptySlots) {
371371
event.isCancelled = true
372372
}
373373
return
@@ -384,7 +384,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
384384

385385
// Forward this click to all pre-processors
386386
val clickContext = ClickContext(view.player, view, click, slot)
387-
view.backing.properties.clickPreprocessors
387+
view.builder.clickPreprocessors
388388
.forEach { handler -> ClickHandler.process(handler, clickContext) }
389389

390390
// Run the click handler and deal with its result
@@ -502,7 +502,7 @@ public class InterfacesListeners private constructor(private val plugin: Plugin)
502502

503503
// Mark the view as properly closed
504504
SCOPE.launch {
505-
(query.view as AbstractInterfaceView<*, *>).markClosed(Reason.PLAYER)
505+
(query.view as AbstractInterfaceView<*, *, *>).markClosed(Reason.PLAYER)
506506
}
507507
}
508508
}

interfaces/src/main/kotlin/com/noxcrew/interfaces/interfaces/ChestInterface.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import org.bukkit.entity.Player
1010
public class ChestInterface internal constructor(
1111
override val rows: Int,
1212
override val initialTitle: Component?,
13-
override val properties: InterfaceProperties<Pane>
14-
) : Interface<Pane>, TitledInterface {
13+
override val builder: ChestInterfaceBuilder
14+
) : Interface<ChestInterface, Pane>, TitledInterface {
1515

1616
public companion object {
1717
/** The maximum number of rows for a chest GUI. */

interfaces/src/main/kotlin/com/noxcrew/interfaces/interfaces/CombinedInterface.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import org.bukkit.entity.Player
1010
public class CombinedInterface internal constructor(
1111
override val rows: Int,
1212
override val initialTitle: Component?,
13-
override val properties: InterfaceProperties<CombinedPane>
14-
) : Interface<CombinedPane>, TitledInterface {
13+
override val builder: CombinedInterfaceBuilder
14+
) : Interface<CombinedInterface, CombinedPane>, TitledInterface {
1515

1616
public companion object {
1717
/** The maximum number of rows for a combined interface. */

interfaces/src/main/kotlin/com/noxcrew/interfaces/interfaces/Interface.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import com.noxcrew.interfaces.view.InterfaceView
66
import org.bukkit.entity.Player
77

88
/** A created interface that can be opened for a player to create a unique view. */
9-
public interface Interface<P : Pane> {
9+
public interface Interface<I : Interface<I, P>, P : Pane> {
1010

1111
/** The amount of rows this interface contains. */
1212
public val rows: Int
1313

14-
/** The properties of this interface. */
15-
public val properties: InterfaceProperties<P>
14+
/** The builder that creates this interface. */
15+
public val builder: InterfaceBuilder<P, I>
1616

1717
/** Returns the total amount of rows. */
1818
public fun totalRows(): Int = rows

0 commit comments

Comments
 (0)