From 9f1c1b05831443a59fb70588d9c362db25495f7f Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Wed, 17 Apr 2024 16:30:38 +0200 Subject: [PATCH 1/6] Fixed GUI return types --- .../it/angrybear/yagl/guis/PageableGUI.java | 60 +++++++++++++++++ .../it/angrybear/yagl/guis/ResizableGUI.java | 65 +++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java b/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java index 4433affe..9fa76fc2 100644 --- a/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java +++ b/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java @@ -338,6 +338,66 @@ public int columns() { return (PageableGUI) GUI.super.setContents(slot, contents); } + @Override + public @NotNull PageableGUI setAllSides(Item @NotNull ... contents) { + return (PageableGUI) GUI.super.setAllSides(contents); + } + + @Override + public @NotNull PageableGUI setAllSides(ItemGUIContent @NotNull ... contents) { + return (PageableGUI) GUI.super.setAllSides(contents); + } + + @Override + public @NotNull PageableGUI setAllSides(GUIContent @NotNull ... contents) { + return (PageableGUI) GUI.super.setAllSides(contents); + } + + @Override + public @NotNull PageableGUI setAllSides(@NotNull Collection contents) { + return (PageableGUI) GUI.super.setAllSides(contents); + } + + @Override + public @NotNull PageableGUI setTopAndBottomSides(Item @NotNull ... contents) { + return (PageableGUI) GUI.super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull PageableGUI setTopAndBottomSides(ItemGUIContent @NotNull ... contents) { + return (PageableGUI) GUI.super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull PageableGUI setTopAndBottomSides(GUIContent @NotNull ... contents) { + return (PageableGUI) GUI.super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull PageableGUI setTopAndBottomSides(@NotNull Collection contents) { + return (PageableGUI) GUI.super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull PageableGUI setLeftAndRightSides(Item @NotNull ... contents) { + return (PageableGUI) GUI.super.setLeftAndRightSides(contents); + } + + @Override + public @NotNull PageableGUI setLeftAndRightSides(ItemGUIContent @NotNull ... contents) { + return (PageableGUI) GUI.super.setLeftAndRightSides(contents); + } + + @Override + public @NotNull PageableGUI setLeftAndRightSides(GUIContent @NotNull ... contents) { + return (PageableGUI) GUI.super.setLeftAndRightSides(contents); + } + + @Override + public @NotNull PageableGUI setLeftAndRightSides(@NotNull Collection contents) { + return (PageableGUI) GUI.super.setLeftAndRightSides(contents); + } + @Override public @NotNull PageableGUI setTopSide(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setTopSide(contents); diff --git a/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java b/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java index 878160f3..15b3cb5e 100644 --- a/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java +++ b/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java @@ -82,6 +82,71 @@ public void resize(int size) { return (ResizableGUI) super.unsetContent(slot); } + @Override + public @NotNull ResizableGUI clear() { + return (ResizableGUI) super.clear(); + } + + @Override + public @NotNull ResizableGUI setAllSides(Item @NotNull ... contents) { + return (ResizableGUI) super.setAllSides(contents); + } + + @Override + public @NotNull ResizableGUI setAllSides(ItemGUIContent @NotNull ... contents) { + return (ResizableGUI) super.setAllSides(contents); + } + + @Override + public @NotNull ResizableGUI setAllSides(GUIContent @NotNull ... contents) { + return (ResizableGUI) super.setAllSides(contents); + } + + @Override + public @NotNull ResizableGUI setAllSides(@NotNull Collection contents) { + return (ResizableGUI) super.setAllSides(contents); + } + + @Override + public @NotNull ResizableGUI setTopAndBottomSides(Item @NotNull ... contents) { + return (ResizableGUI) super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull ResizableGUI setTopAndBottomSides(ItemGUIContent @NotNull ... contents) { + return (ResizableGUI) super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull ResizableGUI setTopAndBottomSides(GUIContent @NotNull ... contents) { + return (ResizableGUI) super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull ResizableGUI setTopAndBottomSides(@NotNull Collection contents) { + return (ResizableGUI) super.setTopAndBottomSides(contents); + } + + @Override + public @NotNull ResizableGUI setLeftAndRightSides(Item @NotNull ... contents) { + return (ResizableGUI) super.setLeftAndRightSides(contents); + } + + @Override + public @NotNull ResizableGUI setLeftAndRightSides(ItemGUIContent @NotNull ... contents) { + return (ResizableGUI) super.setLeftAndRightSides(contents); + } + + @Override + public @NotNull ResizableGUI setLeftAndRightSides(GUIContent @NotNull ... contents) { + return (ResizableGUI) super.setLeftAndRightSides(contents); + } + + @Override + public @NotNull ResizableGUI setLeftAndRightSides(@NotNull Collection contents) { + return (ResizableGUI) super.setLeftAndRightSides(contents); + } + @Override public @NotNull ResizableGUI setTopSide(Item @NotNull ... contents) { return (ResizableGUI) super.setTopSide(contents); From a0bb84f797200004cff3c6323947f47b626830a2 Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Wed, 17 Apr 2024 16:32:21 +0200 Subject: [PATCH 2/6] Implemented clear method --- .../test/java/it/angrybear/yagl/parsers/MockGUIParser.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gui/serializer/src/test/java/it/angrybear/yagl/parsers/MockGUIParser.java b/gui/serializer/src/test/java/it/angrybear/yagl/parsers/MockGUIParser.java index 788c5dad..87bdcaea 100644 --- a/gui/serializer/src/test/java/it/angrybear/yagl/parsers/MockGUIParser.java +++ b/gui/serializer/src/test/java/it/angrybear/yagl/parsers/MockGUIParser.java @@ -95,6 +95,11 @@ public int columns() { return 0; } + @Override + public @NotNull GUI clear() { + return null; + } + @Override public @NotNull GUI unsetContent(int slot) { return null; From b1a8ad8fb9732545bd917082cf76be96a5475b1f Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Wed, 17 Apr 2024 16:43:34 +0200 Subject: [PATCH 3/6] Added rows and columns tests --- .../java/it/angrybear/yagl/guis/GUITest.java | 86 ++++++++++--------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/gui/base/src/test/java/it/angrybear/yagl/guis/GUITest.java b/gui/base/src/test/java/it/angrybear/yagl/guis/GUITest.java index ee834cc5..206ceabc 100644 --- a/gui/base/src/test/java/it/angrybear/yagl/guis/GUITest.java +++ b/gui/base/src/test/java/it/angrybear/yagl/guis/GUITest.java @@ -24,34 +24,34 @@ class GUITest { private static Object[][] expectedCorners() { return new Object[][]{ - new Object[]{9, 0, 4, 8, 0, 4, 8, 0, 4, 8}, - new Object[]{18, 0, 4, 8, 0, 4, 8, 9, 13, 17}, - new Object[]{27, 0, 4, 8, 9, 13, 17, 18, 22, 26}, - new Object[]{36, 0, 4, 8, 9, 13, 17, 27, 31, 35}, - new Object[]{45, 0, 4, 8, 18, 22, 26, 36, 40, 44}, - new Object[]{54, 0, 4, 8, 18, 22, 26, 45, 49, 53}, - new Object[]{GUIType.CHEST, 0, 4, 8, 9, 13, 17, 18, 22, 26}, - new Object[]{GUIType.DISPENSER, 0, 1, 2, 3, 4, 5, 6, 7, 8}, - new Object[]{GUIType.DROPPER, 0, 1, 2, 3, 4, 5, 6, 7, 8}, - new Object[]{GUIType.FURNACE, 0, 1, 2, 0, 1, 2, 0, 1, 2}, - new Object[]{GUIType.WORKBENCH, 0, 1, 2, 3, 4, 5, 6, 7, 8}, - new Object[]{GUIType.ENCHANTING, 0, 1, 1, 0, 1, 1, 0, 1, 1}, - new Object[]{GUIType.BREWING, 0, 1, 1, 2, 3, 4, 2, 3, 4}, - new Object[]{GUIType.PLAYER, 0, 4, 8, 9, 13, 17, 27, 31, 35}, - new Object[]{GUIType.ENDER_CHEST, 0, 4, 8, 9, 13, 17, 18, 22, 26}, - new Object[]{GUIType.ANVIL, 0, 1, 2, 0, 1, 2, 0, 1, 2}, - new Object[]{GUIType.SMITHING, 0, 1, 2, 0, 1, 2, 0, 1, 2}, - new Object[]{GUIType.BEACON, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - new Object[]{GUIType.HOPPER, 0, 2, 4, 0, 2, 4, 0, 2, 4}, - new Object[]{GUIType.SHULKER_BOX, 0, 4, 8, 9, 13, 17, 18, 22, 26}, - new Object[]{GUIType.BARREL, 0, 4, 8, 9, 13, 17, 18, 22, 26}, - new Object[]{GUIType.BLAST_FURNACE, 0, 1, 2, 0, 1, 2, 0, 1, 2}, - new Object[]{GUIType.LECTERN, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - new Object[]{GUIType.SMOKER, 0, 1, 2, 0, 1, 2, 0, 1, 2}, - new Object[]{GUIType.LOOM, 0, 1, 1, 0, 1, 3, 2, 2, 2}, - new Object[]{GUIType.CARTOGRAPHY, 0, 1, 2, 0, 1, 2, 0, 1, 2}, - new Object[]{GUIType.GRINDSTONE, 0, 1, 2, 0, 1, 2, 0, 1, 2}, - new Object[]{GUIType.STONECUTTER, 0, 1, 1, 0, 1, 1, 0, 1, 1}, + new Object[]{9, 0, 4, 8, 0, 4, 8, 0, 4, 8, 1, 9}, + new Object[]{18, 0, 4, 8, 0, 4, 8, 9, 13, 17, 2, 9}, + new Object[]{27, 0, 4, 8, 9, 13, 17, 18, 22, 26, 3, 9}, + new Object[]{36, 0, 4, 8, 9, 13, 17, 27, 31, 35, 4, 9}, + new Object[]{45, 0, 4, 8, 18, 22, 26, 36, 40, 44, 5, 9}, + new Object[]{54, 0, 4, 8, 18, 22, 26, 45, 49, 53, 6, 9}, + new Object[]{GUIType.CHEST, 0, 4, 8, 9, 13, 17, 18, 22, 26, 3, 9}, + new Object[]{GUIType.DISPENSER, 0, 1, 2, 3, 4, 5, 6, 7, 8, 3, 3}, + new Object[]{GUIType.DROPPER, 0, 1, 2, 3, 4, 5, 6, 7, 8, 3, 3}, + new Object[]{GUIType.FURNACE, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 3}, + new Object[]{GUIType.WORKBENCH, 0, 1, 2, 3, 4, 5, 6, 7, 8, 3, 3}, + new Object[]{GUIType.ENCHANTING, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 2}, + new Object[]{GUIType.BREWING, 0, 1, 1, 2, 3, 4, 2, 3, 4, 2, 3}, + new Object[]{GUIType.PLAYER, 0, 4, 8, 9, 13, 17, 27, 31, 35, 4, 9}, + new Object[]{GUIType.ENDER_CHEST, 0, 4, 8, 9, 13, 17, 18, 22, 26, 3, 9}, + new Object[]{GUIType.ANVIL, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 3}, + new Object[]{GUIType.SMITHING, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 3}, + new Object[]{GUIType.BEACON, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, + new Object[]{GUIType.HOPPER, 0, 2, 4, 0, 2, 4, 0, 2, 4, 1, 5}, + new Object[]{GUIType.SHULKER_BOX, 0, 4, 8, 9, 13, 17, 18, 22, 26, 3, 9}, + new Object[]{GUIType.BARREL, 0, 4, 8, 9, 13, 17, 18, 22, 26, 3, 9}, + new Object[]{GUIType.BLAST_FURNACE, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 3}, + new Object[]{GUIType.LECTERN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, + new Object[]{GUIType.SMOKER, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 3}, + new Object[]{GUIType.LOOM, 0, 1, 1, 0, 1, 3, 2, 2, 2, 2, 3}, + new Object[]{GUIType.CARTOGRAPHY, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 3}, + new Object[]{GUIType.GRINDSTONE, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 3}, + new Object[]{GUIType.STONECUTTER, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 2}, }; } @@ -60,7 +60,8 @@ private static Object[][] expectedCorners() { void testGUICorners(Object object, int northWest, int north, int northEast, int middleWest, int middle, int middleEast, - int southWest, int south, int southEast) { + int southWest, int south, int southEast, + int rows, int columns) { GUI gui = new Refl<>(GUI.class).invokeMethod("newGUI", object); assertEquals(northWest, gui.northWest(), "Invalid North West slot"); @@ -74,14 +75,18 @@ void testGUICorners(Object object, assertEquals(southWest, gui.southWest(), "Invalid South West slot"); assertEquals(south, gui.south(), "Invalid South slot"); assertEquals(southEast, gui.southEast(), "Invalid South East slot"); + + assertEquals(rows, gui.rows()); + assertEquals(columns, gui.columns()); } @ParameterizedTest @MethodSource("expectedCorners") void testSetTopSide(Object object, - int northWest, int north, int northEast, - int middleWest, int middle, int middleEast, - int southWest, int south, int southEast) { + int northWest, int north, int northEast, + int middleWest, int middle, int middleEast, + int southWest, int south, int southEast, + int rows, int columns) { final Map ignored = new HashMap<>(); GUI gui = new Refl<>(GUI.class).invokeMethod("newGUI", object); @@ -115,7 +120,8 @@ void testSetTopSide(Object object, void testSetLeftSide(Object object, int northWest, int north, int northEast, int middleWest, int middle, int middleEast, - int southWest, int south, int southEast) { + int southWest, int south, int southEast, + int rows, int columns) { final Map ignored = new HashMap<>(); ignored.put(GUIType.WORKBENCH, 9); ignored.put(GUIType.BREWING, 3); @@ -147,9 +153,10 @@ void testSetLeftSide(Object object, @ParameterizedTest @MethodSource("expectedCorners") void testSetBottomSide(Object object, - int northWest, int north, int northEast, - int middleWest, int middle, int middleEast, - int southWest, int south, int southEast) { + int northWest, int north, int northEast, + int middleWest, int middle, int middleEast, + int southWest, int south, int southEast, + int rows, int columns) { final Map ignored = new HashMap<>(); ignored.put(GUIType.WORKBENCH, 9); ignored.put(GUIType.PLAYER, 36); @@ -184,9 +191,10 @@ void testSetBottomSide(Object object, @ParameterizedTest @MethodSource("expectedCorners") void testSetRightSide(Object object, - int northWest, int north, int northEast, - int middleWest, int middle, int middleEast, - int southWest, int south, int southEast) { + int northWest, int north, int northEast, + int middleWest, int middle, int middleEast, + int southWest, int south, int southEast, + int rows, int columns) { final Map ignored = new HashMap<>(); ignored.put(GUIType.LOOM, 0); From e18d25b8075de39b46cf5cb1539033b10d2a4e9c Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Wed, 17 Apr 2024 16:47:53 +0200 Subject: [PATCH 4/6] Fixed setAllSides not setting to lateral sides --- gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java b/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java index f93847ea..c1e8f80b 100644 --- a/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java +++ b/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java @@ -211,7 +211,7 @@ default boolean isEmpty() { * @return this gui */ default @NotNull GUI setAllSides(final Item @NotNull ... contents) { - return setTopSide(contents).setBottomSide(contents); + return setTopAndBottomSides(contents).setLeftAndRightSides(contents); } /** @@ -222,7 +222,7 @@ default boolean isEmpty() { * @return this gui */ default @NotNull GUI setAllSides(final ItemGUIContent @NotNull ... contents) { - return setTopSide(contents).setBottomSide(contents); + return setTopAndBottomSides(contents).setLeftAndRightSides(contents); } /** @@ -233,7 +233,7 @@ default boolean isEmpty() { * @return this gui */ default @NotNull GUI setAllSides(final GUIContent @NotNull ... contents) { - return setTopSide(contents).setBottomSide(contents); + return setTopAndBottomSides(contents).setLeftAndRightSides(contents); } /** @@ -244,7 +244,7 @@ default boolean isEmpty() { * @return this gui */ default @NotNull GUI setAllSides(final @NotNull Collection contents) { - return setTopSide(contents).setBottomSide(contents); + return setTopAndBottomSides(contents).setLeftAndRightSides(contents); } /** From 66d8ff3b9cc5863fef1a586fb4017e79a0aeea48 Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Wed, 17 Apr 2024 16:59:56 +0200 Subject: [PATCH 5/6] Added unsetter corner methods --- .../main/java/it/angrybear/yagl/guis/GUI.java | 165 +++++++++++++++++- 1 file changed, 157 insertions(+), 8 deletions(-) diff --git a/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java b/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java index c1e8f80b..aa98a5e8 100644 --- a/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java +++ b/gui/base/src/main/java/it/angrybear/yagl/guis/GUI.java @@ -203,6 +203,14 @@ default boolean isEmpty() { */ @NotNull GUI setContents(int slot, final GUIContent @NotNull ... contents); + /** + * Removes the content from the given index. + * + * @param slot the slot + * @return this gui + */ + @NotNull GUI unsetContent(int slot); + /** * Sets the given contents at the {@link #topSlots()}, the {@link #leftSlots()}, * the {@link #bottomSlots()} and the {@link #rightSlots()}. @@ -247,6 +255,16 @@ default boolean isEmpty() { return setTopAndBottomSides(contents).setLeftAndRightSides(contents); } + /** + * Removes the contents at the {@link #topSlots()}, the {@link #leftSlots()}, + * the {@link #bottomSlots()} and the {@link #rightSlots()}. + * + * @return this gui + */ + default @NotNull GUI unsetAllSides() { + return unsetTopAndBottomSides().unsetLeftAndRightSides(); + } + /** * Sets the given contents at the {@link #topSlots()} and the {@link #bottomSlots()}. * @@ -287,6 +305,15 @@ default boolean isEmpty() { return setTopSide(contents).setBottomSide(contents); } + /** + * Removes the contents at the {@link #topSlots()} and the {@link #bottomSlots()}. + * + * @return this gui + */ + default @NotNull GUI unsetTopAndBottomSides() { + return unsetTopSide().unsetBottomSide(); + } + /** * Sets the given contents at the {@link #leftSlots()} and the {@link #rightSlots()}. * @@ -327,6 +354,15 @@ default boolean isEmpty() { return setLeftSide(contents).setRightSide(contents); } + /** + * Removes the contents at the {@link #leftSlots()} and the {@link #rightSlots()}. + * + * @return this gui + */ + default @NotNull GUI unsetLeftAndRightSides() { + return unsetLeftSide().unsetRightSide(); + } + /** * Sets the given contents at the {@link #topSlots()}. * @@ -375,6 +411,16 @@ default boolean isEmpty() { return this; } + /** + * Removes the contents at the {@link #topSlots()}. + * + * @return this gui + */ + default @NotNull GUI unsetTopSide() { + topSlots().forEach(this::unsetContent); + return this; + } + /** * Gets the slots on the top side. * @@ -434,6 +480,16 @@ default boolean isEmpty() { return this; } + /** + * Removes the contents at the {@link #leftSlots()}. + * + * @return this gui + */ + default @NotNull GUI unsetLeftSide() { + leftSlots().forEach(this::unsetContent); + return this; + } + /** * Gets the slots on the left side. * @@ -494,6 +550,16 @@ default boolean isEmpty() { return this; } + /** + * Removes the contents at the {@link #bottomSlots()}. + * + * @return this gui + */ + default @NotNull GUI unsetBottomSide() { + bottomSlots().forEach(this::unsetContent); + return this; + } + /** * Gets the slots on the bottom side. * @@ -553,6 +619,16 @@ default boolean isEmpty() { return this; } + /** + * Removes all the contents at the {@link #rightSlots()}. + * + * @return this gui + */ + default @NotNull GUI unsetRightSide() { + rightSlots().forEach(this::unsetContent); + return this; + } + /** * Gets the slots on the right side. * @@ -595,6 +671,15 @@ default boolean isEmpty() { return setContents(northWest(), contents); } + /** + * Removes all the contents at the index {@link #northWest()}. + * + * @return this gui + */ + default @NotNull GUI unsetNorthWest() { + return unsetContent(northWest()); + } + /** * Sets the given contents at the index {@link #north()}. * @@ -625,6 +710,15 @@ default boolean isEmpty() { return setContents(north(), contents); } + /** + * Removes all the contents at the index {@link #north()}. + * + * @return this gui + */ + default @NotNull GUI unsetNorth() { + return unsetContent(north()); + } + /** * Sets the given contents at the index {@link #northEast()}. * @@ -655,6 +749,15 @@ default boolean isEmpty() { return setContents(northEast(), contents); } + /** + * Removes all the contents at the index {@link #northEast()}. + * + * @return this gui + */ + default @NotNull GUI unsetNorthEast() { + return unsetContent(northEast()); + } + /** * Sets the given contents at the index {@link #middleWest()}. * @@ -685,6 +788,15 @@ default boolean isEmpty() { return setContents(middleWest(), contents); } + /** + * Removes all the contents at the index {@link #middleWest()}. + * + * @return this gui + */ + default @NotNull GUI unsetMiddleWest() { + return unsetContent(middleWest()); + } + /** * Sets the given contents at the index {@link #middle()}. * @@ -715,6 +827,15 @@ default boolean isEmpty() { return setContents(middle(), contents); } + /** + * Removes all the contents at the index {@link #middle()}. + * + * @return this gui + */ + default @NotNull GUI unsetMiddle() { + return unsetContent(middle()); + } + /** * Sets the given contents at the index {@link #middleEast()}. * @@ -745,6 +866,15 @@ default boolean isEmpty() { return setContents(middleEast(), contents); } + /** + * Removes all the contents at the index {@link #middleEast()}. + * + * @return this gui + */ + default @NotNull GUI unsetMiddleEast() { + return unsetContent(middleEast()); + } + /** * Sets the given contents at the index {@link #southWest()}. * @@ -775,6 +905,15 @@ default boolean isEmpty() { return setContents(southWest(), contents); } + /** + * Removes all the contents at the index {@link #southWest()}. + * + * @return this gui + */ + default @NotNull GUI unsetSouthWest() { + return unsetContent(southWest()); + } + /** * Sets the given contents at the index {@link #south()}. * @@ -805,6 +944,15 @@ default boolean isEmpty() { return setContents(south(), contents); } + /** + * Removes all the contents at the index {@link #south()}. + * + * @return this gui + */ + default @NotNull GUI unsetSouth() { + return unsetContent(south()); + } + /** * Sets the given contents at the index {@link #southEast()}. * @@ -835,6 +983,15 @@ default boolean isEmpty() { return setContents(southEast(), contents); } + /** + * Removes all the contents at the index {@link #southEast()}. + * + * @return this gui + */ + default @NotNull GUI unsetSouthEast() { + return unsetContent(southEast()); + } + /** * Gets the slot at the North-West position in this GUI. * For example, in the case of a 3x3 dimension: @@ -1013,14 +1170,6 @@ default int southEast() { */ @NotNull GUI clear(); - /** - * Removes the content from the given index. - * - * @param slot the slot - * @return this gui - */ - @NotNull GUI unsetContent(int slot); - /** * Forces the {@link Viewer} to execute the given command when clicking outside the GUI (will not include player's inventory slots). * From 7ec0be48ef8776cb8c3aef3bb4c07c0aeef7055f Mon Sep 17 00:00:00 2001 From: Fulminazzo Date: Wed, 17 Apr 2024 17:07:52 +0200 Subject: [PATCH 6/6] Implemented unsetter corner methods --- .../it/angrybear/yagl/guis/PageableGUI.java | 100 +++++++++++++++++ .../it/angrybear/yagl/guis/ResizableGUI.java | 101 ++++++++++++++++++ 2 files changed, 201 insertions(+) diff --git a/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java b/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java index 9fa76fc2..a8ac2caf 100644 --- a/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java +++ b/gui/base/src/main/java/it/angrybear/yagl/guis/PageableGUI.java @@ -358,6 +358,11 @@ public int columns() { return (PageableGUI) GUI.super.setAllSides(contents); } + @Override + public @NotNull PageableGUI unsetAllSides() { + return (PageableGUI) GUI.super.unsetAllSides(); + } + @Override public @NotNull PageableGUI setTopAndBottomSides(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setTopAndBottomSides(contents); @@ -378,6 +383,11 @@ public int columns() { return (PageableGUI) GUI.super.setTopAndBottomSides(contents); } + @Override + public @NotNull PageableGUI unsetTopAndBottomSides() { + return (PageableGUI) GUI.super.unsetTopAndBottomSides(); + } + @Override public @NotNull PageableGUI setLeftAndRightSides(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setLeftAndRightSides(contents); @@ -398,6 +408,11 @@ public int columns() { return (PageableGUI) GUI.super.setLeftAndRightSides(contents); } + @Override + public @NotNull PageableGUI unsetLeftAndRightSides() { + return (PageableGUI) GUI.super.unsetLeftAndRightSides(); + } + @Override public @NotNull PageableGUI setTopSide(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setTopSide(contents); @@ -418,6 +433,16 @@ public int columns() { return (PageableGUI) GUI.super.setTopSide(contents); } + @Override + public @NotNull PageableGUI unsetTopSide() { + return (PageableGUI) GUI.super.unsetTopSide(); + } + + @Override + public @NotNull Set topSlots() { + return GUI.super.topSlots(); + } + @Override public @NotNull PageableGUI setLeftSide(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setLeftSide(contents); @@ -438,6 +463,16 @@ public int columns() { return (PageableGUI) GUI.super.setLeftSide(contents); } + @Override + public @NotNull PageableGUI unsetLeftSide() { + return (PageableGUI) GUI.super.unsetLeftSide(); + } + + @Override + public @NotNull Set leftSlots() { + return GUI.super.leftSlots(); + } + @Override public @NotNull PageableGUI setBottomSide(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setBottomSide(contents); @@ -458,6 +493,16 @@ public int columns() { return (PageableGUI) GUI.super.setBottomSide(contents); } + @Override + public @NotNull PageableGUI unsetBottomSide() { + return (PageableGUI) GUI.super.unsetBottomSide(); + } + + @Override + public @NotNull Set bottomSlots() { + return GUI.super.bottomSlots(); + } + @Override public @NotNull PageableGUI setRightSide(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setRightSide(contents); @@ -478,6 +523,16 @@ public int columns() { return (PageableGUI) GUI.super.setRightSide(contents); } + @Override + public @NotNull PageableGUI unsetRightSide() { + return (PageableGUI) GUI.super.unsetRightSide(); + } + + @Override + public @NotNull Set rightSlots() { + return GUI.super.rightSlots(); + } + @Override public @NotNull PageableGUI setNorthWest(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setNorthWest(contents); @@ -493,6 +548,11 @@ public int columns() { return (PageableGUI) GUI.super.setNorthWest(contents); } + @Override + public @NotNull PageableGUI unsetNorthWest() { + return (PageableGUI) GUI.super.unsetNorthWest(); + } + @Override public @NotNull PageableGUI setNorth(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setNorth(contents); @@ -508,6 +568,11 @@ public int columns() { return (PageableGUI) GUI.super.setNorth(contents); } + @Override + public @NotNull PageableGUI unsetNorth() { + return (PageableGUI) GUI.super.unsetNorth(); + } + @Override public @NotNull PageableGUI setNorthEast(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setNorthEast(contents); @@ -523,6 +588,11 @@ public int columns() { return (PageableGUI) GUI.super.setNorthEast(contents); } + @Override + public @NotNull PageableGUI unsetNorthEast() { + return (PageableGUI) GUI.super.unsetNorthEast(); + } + @Override public @NotNull PageableGUI setMiddleWest(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setMiddleWest(contents); @@ -538,6 +608,11 @@ public int columns() { return (PageableGUI) GUI.super.setMiddleWest(contents); } + @Override + public @NotNull PageableGUI unsetMiddleWest() { + return (PageableGUI) GUI.super.unsetMiddleWest(); + } + @Override public @NotNull PageableGUI setMiddle(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setMiddle(contents); @@ -553,6 +628,11 @@ public int columns() { return (PageableGUI) GUI.super.setMiddle(contents); } + @Override + public @NotNull PageableGUI unsetMiddle() { + return (PageableGUI) GUI.super.unsetMiddle(); + } + @Override public @NotNull PageableGUI setMiddleEast(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setMiddleEast(contents); @@ -568,6 +648,11 @@ public int columns() { return (PageableGUI) GUI.super.setMiddleEast(contents); } + @Override + public @NotNull PageableGUI unsetMiddleEast() { + return (PageableGUI) GUI.super.unsetMiddleEast(); + } + @Override public @NotNull PageableGUI setSouthWest(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setSouthWest(contents); @@ -583,6 +668,11 @@ public int columns() { return (PageableGUI) GUI.super.setSouthWest(contents); } + @Override + public @NotNull PageableGUI unsetSouthWest() { + return (PageableGUI) GUI.super.unsetSouthWest(); + } + @Override public @NotNull PageableGUI setSouth(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setSouth(contents); @@ -598,6 +688,11 @@ public int columns() { return (PageableGUI) GUI.super.setSouth(contents); } + @Override + public @NotNull PageableGUI unsetSouth() { + return (PageableGUI) GUI.super.unsetSouth(); + } + @Override public @NotNull PageableGUI setSouthEast(Item @NotNull ... contents) { return (PageableGUI) GUI.super.setSouthEast(contents); @@ -613,6 +708,11 @@ public int columns() { return (PageableGUI) GUI.super.setSouthEast(contents); } + @Override + public @NotNull PageableGUI unsetSouthEast() { + return (PageableGUI) GUI.super.unsetSouthEast(); + } + @Override public @NotNull PageableGUI onClickOutside(@NotNull String command) { return (PageableGUI) GUI.super.onClickOutside(command); diff --git a/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java b/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java index 15b3cb5e..30736538 100644 --- a/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java +++ b/gui/base/src/main/java/it/angrybear/yagl/guis/ResizableGUI.java @@ -13,6 +13,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Collection; +import java.util.Set; /** * Represents a "chest" GUI that can be resized. @@ -107,6 +108,11 @@ public void resize(int size) { return (ResizableGUI) super.setAllSides(contents); } + @Override + public @NotNull ResizableGUI unsetAllSides() { + return (ResizableGUI) super.unsetAllSides(); + } + @Override public @NotNull ResizableGUI setTopAndBottomSides(Item @NotNull ... contents) { return (ResizableGUI) super.setTopAndBottomSides(contents); @@ -127,6 +133,11 @@ public void resize(int size) { return (ResizableGUI) super.setTopAndBottomSides(contents); } + @Override + public @NotNull ResizableGUI unsetTopAndBottomSides() { + return (ResizableGUI) super.unsetTopAndBottomSides(); + } + @Override public @NotNull ResizableGUI setLeftAndRightSides(Item @NotNull ... contents) { return (ResizableGUI) super.setLeftAndRightSides(contents); @@ -147,6 +158,11 @@ public void resize(int size) { return (ResizableGUI) super.setLeftAndRightSides(contents); } + @Override + public @NotNull ResizableGUI unsetLeftAndRightSides() { + return (ResizableGUI) super.unsetLeftAndRightSides(); + } + @Override public @NotNull ResizableGUI setTopSide(Item @NotNull ... contents) { return (ResizableGUI) super.setTopSide(contents); @@ -167,6 +183,16 @@ public void resize(int size) { return (ResizableGUI) super.setTopSide(contents); } + @Override + public @NotNull ResizableGUI unsetTopSide() { + return (ResizableGUI) super.unsetTopSide(); + } + + @Override + public @NotNull Set topSlots() { + return super.topSlots(); + } + @Override public @NotNull ResizableGUI setLeftSide(Item @NotNull ... contents) { return (ResizableGUI) super.setLeftSide(contents); @@ -187,6 +213,16 @@ public void resize(int size) { return (ResizableGUI) super.setLeftSide(contents); } + @Override + public @NotNull ResizableGUI unsetLeftSide() { + return (ResizableGUI) super.unsetLeftSide(); + } + + @Override + public @NotNull Set leftSlots() { + return super.leftSlots(); + } + @Override public @NotNull ResizableGUI setBottomSide(Item @NotNull ... contents) { return (ResizableGUI) super.setBottomSide(contents); @@ -207,6 +243,16 @@ public void resize(int size) { return (ResizableGUI) super.setBottomSide(contents); } + @Override + public @NotNull ResizableGUI unsetBottomSide() { + return (ResizableGUI) super.unsetBottomSide(); + } + + @Override + public @NotNull Set bottomSlots() { + return super.bottomSlots(); + } + @Override public @NotNull ResizableGUI setRightSide(Item @NotNull ... contents) { return (ResizableGUI) super.setRightSide(contents); @@ -227,6 +273,16 @@ public void resize(int size) { return (ResizableGUI) super.setRightSide(contents); } + @Override + public @NotNull ResizableGUI unsetRightSide() { + return (ResizableGUI) super.unsetRightSide(); + } + + @Override + public @NotNull Set rightSlots() { + return super.rightSlots(); + } + @Override public @NotNull ResizableGUI setNorthWest(Item @NotNull ... contents) { return (ResizableGUI) super.setNorthWest(contents); @@ -242,6 +298,11 @@ public void resize(int size) { return (ResizableGUI) super.setNorthWest(contents); } + @Override + public @NotNull ResizableGUI unsetNorthWest() { + return (ResizableGUI) super.unsetNorthWest(); + } + @Override public @NotNull ResizableGUI setNorth(Item @NotNull ... contents) { return (ResizableGUI) super.setNorth(contents); @@ -257,6 +318,11 @@ public void resize(int size) { return (ResizableGUI) super.setNorth(contents); } + @Override + public @NotNull ResizableGUI unsetNorth() { + return (ResizableGUI) super.unsetNorth(); + } + @Override public @NotNull ResizableGUI setNorthEast(Item @NotNull ... contents) { return (ResizableGUI) super.setNorthEast(contents); @@ -272,6 +338,11 @@ public void resize(int size) { return (ResizableGUI) super.setNorthEast(contents); } + @Override + public @NotNull ResizableGUI unsetNorthEast() { + return (ResizableGUI) super.unsetNorthEast(); + } + @Override public @NotNull ResizableGUI setMiddleWest(Item @NotNull ... contents) { return (ResizableGUI) super.setMiddleWest(contents); @@ -287,6 +358,11 @@ public void resize(int size) { return (ResizableGUI) super.setMiddleWest(contents); } + @Override + public @NotNull ResizableGUI unsetMiddleWest() { + return (ResizableGUI) super.unsetMiddleWest(); + } + @Override public @NotNull ResizableGUI setMiddle(Item @NotNull ... contents) { return (ResizableGUI) super.setMiddle(contents); @@ -302,6 +378,11 @@ public void resize(int size) { return (ResizableGUI) super.setMiddle(contents); } + @Override + public @NotNull ResizableGUI unsetMiddle() { + return (ResizableGUI) super.unsetMiddle(); + } + @Override public @NotNull ResizableGUI setMiddleEast(Item @NotNull ... contents) { return (ResizableGUI) super.setMiddleEast(contents); @@ -317,6 +398,11 @@ public void resize(int size) { return (ResizableGUI) super.setMiddleEast(contents); } + @Override + public @NotNull ResizableGUI unsetMiddleEast() { + return (ResizableGUI) super.unsetMiddleEast(); + } + @Override public @NotNull ResizableGUI setSouthWest(Item @NotNull ... contents) { return (ResizableGUI) super.setSouthWest(contents); @@ -332,6 +418,11 @@ public void resize(int size) { return (ResizableGUI) super.setSouthWest(contents); } + @Override + public @NotNull ResizableGUI unsetSouthWest() { + return (ResizableGUI) super.unsetSouthWest(); + } + @Override public @NotNull ResizableGUI setSouth(Item @NotNull ... contents) { return (ResizableGUI) super.setSouth(contents); @@ -347,6 +438,11 @@ public void resize(int size) { return (ResizableGUI) super.setSouth(contents); } + @Override + public @NotNull ResizableGUI unsetSouth() { + return (ResizableGUI) super.unsetSouth(); + } + @Override public @NotNull ResizableGUI setSouthEast(Item @NotNull ... contents) { return (ResizableGUI) super.setSouthEast(contents); @@ -362,6 +458,11 @@ public void resize(int size) { return (ResizableGUI) super.setSouthEast(contents); } + @Override + public @NotNull ResizableGUI unsetSouthEast() { + return (ResizableGUI) super.unsetSouthEast(); + } + @Override public @NotNull ResizableGUI onClickOutside(@NotNull GUIAction action) { return (ResizableGUI) super.onClickOutside(action);