From fdaa6c622f05fcd280a3742c1f88e5fc402ac29c Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Tue, 11 Aug 2026 13:15:06 +0200 Subject: [PATCH 1/4] chore(data): change return type from the addPage method --- .../net/onelitefeather/cygnus/setup/data/GameData.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/setup/src/main/java/net/onelitefeather/cygnus/setup/data/GameData.java b/setup/src/main/java/net/onelitefeather/cygnus/setup/data/GameData.java index e865cc2..3dd0b92 100644 --- a/setup/src/main/java/net/onelitefeather/cygnus/setup/data/GameData.java +++ b/setup/src/main/java/net/onelitefeather/cygnus/setup/data/GameData.java @@ -92,11 +92,15 @@ private PageableInventory createPageInventory(Player player) { * * @param pos of the resource * @param face of the resource + * @return true if the page was added, false if a page at the position and face already exists */ - public void addPage(Vec pos, Direction face) { + public boolean addPage(Vec pos, Direction face) { PageResource pageResource = new PageResource(pos, face); - this.gameMapBuilder.addPage(pos, face); - this.pageInventory.add(new PageSlot(pageResource)); + boolean added = this.gameMapBuilder.addPage(pos, face); + if (added) { + this.pageInventory.add(new PageSlot(pageResource)); + } + return added; } /** From 5afa525fe02fe3763542c27e2c43abd84dc98da7 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Tue, 11 Aug 2026 13:15:30 +0200 Subject: [PATCH 2/4] test(data): add new test behaivour for the page addition and removal --- .../net/onelitefeather/cygnus/setup/data/GameDataTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup/src/test/java/net/onelitefeather/cygnus/setup/data/GameDataTest.java b/setup/src/test/java/net/onelitefeather/cygnus/setup/data/GameDataTest.java index bb242f0..00c2181 100644 --- a/setup/src/test/java/net/onelitefeather/cygnus/setup/data/GameDataTest.java +++ b/setup/src/test/java/net/onelitefeather/cygnus/setup/data/GameDataTest.java @@ -44,8 +44,9 @@ void testAddAndRemovePage(Env env) { GameData gameData = new GameData(player, mapEntry); - gameData.addPage(Vec.ZERO, Direction.NORTH); - assertNotNull(gameData); + assertTrue(gameData.addPage(Vec.ZERO, Direction.NORTH)); + assertFalse(gameData.addPage(Vec.ZERO, Direction.NORTH)); + assertTrue(gameData.addPage(Vec.ZERO, Direction.SOUTH)); env.destroyInstance(instance, true); } From 0e1b2cad17faab812d987b229f8a3baff1e784b2 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Tue, 11 Aug 2026 13:15:48 +0200 Subject: [PATCH 3/4] chore(map): update returntype of a method --- .../cygnus/common/map/GameMapBuilder.java | 5 +++-- .../onelitefeather/cygnus/common/map/GameMapTest.java | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMapBuilder.java b/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMapBuilder.java index 9584413..731ecb3 100644 --- a/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMapBuilder.java +++ b/common/src/main/java/net/onelitefeather/cygnus/common/map/GameMapBuilder.java @@ -96,9 +96,10 @@ public GameMap build() { * * @param pos the position to add * @param face the face of the page + * @return true if the page was added, false if a page at the position and face already exists */ - public void addPage(Vec pos, Direction face) { - this.pageFaces.add(new PageResource(pos, face)); + public boolean addPage(Vec pos, Direction face) { + return this.pageFaces.add(new PageResource(pos, face)); } /** diff --git a/common/src/test/java/net/onelitefeather/cygnus/common/map/GameMapTest.java b/common/src/test/java/net/onelitefeather/cygnus/common/map/GameMapTest.java index 5b68171..bf8e890 100644 --- a/common/src/test/java/net/onelitefeather/cygnus/common/map/GameMapTest.java +++ b/common/src/test/java/net/onelitefeather/cygnus/common/map/GameMapTest.java @@ -82,7 +82,7 @@ void testPageFaceHandling() { assertNotNull(mapBuilder); assertTrue(mapBuilder.getPageFaces().isEmpty()); - mapBuilder.addPage(Vec.ZERO, Direction.NORTH); + assertTrue(mapBuilder.addPage(Vec.ZERO, Direction.NORTH)); assertFalse(mapBuilder.getPageFaces().isEmpty()); @@ -92,6 +92,15 @@ void testPageFaceHandling() { assertEquals(Direction.NORTH, pageResource.face()); } + @Test + void testDuplicatePageHandling() { + GameMapBuilder mapBuilder = new GameMapBuilder(); + assertTrue(mapBuilder.addPage(Vec.ZERO, Direction.NORTH)); + assertFalse(mapBuilder.addPage(Vec.ZERO, Direction.NORTH)); + assertTrue(mapBuilder.addPage(Vec.ZERO, Direction.EAST)); + assertEquals(2, mapBuilder.getPageFaces().size()); + } + @Test void testGameMapCopy() { Pos slenderPos = new Pos(10, 10, 10); From 365e9a15c42fa0b2fda2506bdad659ac67ff2bac Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Tue, 11 Aug 2026 13:16:09 +0200 Subject: [PATCH 4/4] chore(setup): abort double page creation --- .../cygnus/setup/listener/PageCreationListener.java | 5 ++++- .../net/onelitefeather/cygnus/setup/util/SetupMessages.java | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/setup/src/main/java/net/onelitefeather/cygnus/setup/listener/PageCreationListener.java b/setup/src/main/java/net/onelitefeather/cygnus/setup/listener/PageCreationListener.java index 479bbf0..f9e382a 100644 --- a/setup/src/main/java/net/onelitefeather/cygnus/setup/listener/PageCreationListener.java +++ b/setup/src/main/java/net/onelitefeather/cygnus/setup/listener/PageCreationListener.java @@ -55,7 +55,10 @@ public void accept(PlayerBlockBreakEvent event) { } Vec position = event.getBlockPosition().asVec(); - gameData.addPage(position, direction); + if (!gameData.addPage(position, direction)) { + player.sendMessage(SetupMessages.DUPLICATE_PAGE); + return; + } Component component = Component.text("Created page at: ", NamedTextColor.GRAY) .append(Components.convertPoint(position).style(Style.style(NamedTextColor.GOLD))) diff --git a/setup/src/main/java/net/onelitefeather/cygnus/setup/util/SetupMessages.java b/setup/src/main/java/net/onelitefeather/cygnus/setup/util/SetupMessages.java index e3ffaf7..2ee31d3 100644 --- a/setup/src/main/java/net/onelitefeather/cygnus/setup/util/SetupMessages.java +++ b/setup/src/main/java/net/onelitefeather/cygnus/setup/util/SetupMessages.java @@ -34,6 +34,7 @@ public final class SetupMessages { public static final Component PAGE_MODE_DISABLED; public static final Component SURVIVOR_MODE_ENABLED; public static final Component SURVIVOR_MODE_DISABLED; + public static final Component DUPLICATE_PAGE; static { SPACE_SEPARATOR = Component.text("ยป ", NamedTextColor.GRAY); @@ -85,6 +86,9 @@ public final class SetupMessages { .append(Component.space()) .append(Component.text("disabled", NamedTextColor.RED)) ); + DUPLICATE_PAGE = Messages.withPrefix( + Component.text("A page with this direction already exists at this position", NamedTextColor.RED) + ); } private SetupMessages() {