From cf3c1f8394666c50aa164e1fb163b40fc4c5d2ec Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 10 Sep 2021 13:48:50 +0100 Subject: [PATCH] Added destructuring support to pairs --- .../java/com/willfp/eco/core/tuples/Pair.java | 22 +++++++++++++++++++ .../com/willfp/eco/core/tuples/Triplet.java | 11 ++++++++++ .../com/willfp/eco/spigot/gui/GUIListener.kt | 4 +--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/tuples/Pair.java b/eco-api/src/main/java/com/willfp/eco/core/tuples/Pair.java index abd41675..d4ecd5f1 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/tuples/Pair.java +++ b/eco-api/src/main/java/com/willfp/eco/core/tuples/Pair.java @@ -38,4 +38,26 @@ public class Pair { this.first = first; this.second = second; } + + /** + * component1 exists to allow a pair to be destructured by kotlin. + * The default kotlin pair already has this, however there is no default + * pair in java so this exists for parity. + * + * @return First. + */ + public A component1() { + return first; + } + + /** + * component2 exists to allow a pair to be destructured by kotlin. + * The default kotlin pair already has this, however there is no default + * pair in java so this exists for parity. + * + * @return First. + */ + public B component2() { + return second; + } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/tuples/Triplet.java b/eco-api/src/main/java/com/willfp/eco/core/tuples/Triplet.java index c857ab69..1254a88c 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/tuples/Triplet.java +++ b/eco-api/src/main/java/com/willfp/eco/core/tuples/Triplet.java @@ -34,4 +34,15 @@ public class Triplet extends Pair { this.third = third; } + + /** + * component3 exists to allow a pair to be destructured by kotlin. + * The default kotlin pair already has this, however there is no default + * pair in java so this exists for parity. + * + * @return First. + */ + public C component3() { + return third; + } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt index b37bbf06..c17c5123 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/spigot/gui/GUIListener.kt @@ -73,9 +73,7 @@ class GUIListener(private val plugin: EcoPlugin) : Listener { val menu = MenuHandler.getMenu(inv) ?: return - val rowColumn = MenuUtils.convertSlotToRowColumn(inv.firstEmpty()) - val row = rowColumn.first!! - val column = rowColumn.second!! + val (row, column) = MenuUtils.convertSlotToRowColumn(inv.firstEmpty()) val slot = menu.getSlot(row, column) if (!slot.isCaptive) {