diff --git a/README.md b/README.md index 133492f..1a01a80 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ After 250 Survival-mode block placements anywhere by default, the spawnable over `/base` has a stationary warm-up. Looking around is allowed, while movement between blocks, damage, teleportation, world changes, death, logout, and conflicting teleport commands cancel it without consuming the cooldown. -Base IV owners can purchase and expand a persistent Pocket Base with `/basesettings pocket upgrade`. Activating a complete diamond-block portal frame inside the normal base with flint and steel opens one public entrance to the owner's grass platform in a private void world. Players and non-player living mobs can travel through the entrance and active return portal; items, projectiles, and vehicles are not transported. The owner can move the return portal by building and igniting another complete frame inside the unlocked Pocket Base boundary; only the newly activated return portal remains functional. Natural hostile and passive mob spawning is disabled by default. Owners can control each category independently with `/basesettings pocket mobs `. An owner who wins a raid inside their own Pocket Base permanently unlocks owner-only Survival flight across the full build height and within the current Pocket Base boundary plus a 16-block warning buffer on every side. The owner can control that automatic privilege with `/basesettings pocket flight `. After the raid unlock, the owner can ignite a complete gold-block portal frame inside the unlocked boundary; any player who passes through receives temporary flight within the same boundary and buffer until leaving the Pocket Base. The owner's automatic-flight preference does not affect portal-granted flight. +Base IV owners can purchase and expand a persistent Pocket Base with `/basesettings pocket upgrade`. Activating a complete diamond-block portal frame inside the normal base with flint and steel opens one public entrance to the owner's grass platform in a private void world. Players and non-player living mobs can travel through the entrance and active return portal; items, projectiles, and vehicles are not transported. The owner can move the return portal by building and igniting another complete frame inside the unlocked Pocket Base boundary; only the newly activated return portal remains functional. Natural hostile and passive mob spawning is disabled by default. Owners can control each category independently with `/basesettings pocket mobs `. An owner who wins a raid inside their own Pocket Base permanently unlocks owner-only Survival flight across the full build height and within the current Pocket Base boundary plus a 16-block warning buffer on every side. The owner can control that automatic privilege with `/basesettings pocket flight `. After the raid unlock, the owner can ignite a complete gold-block portal frame inside the unlocked boundary; any Survival player who passes through receives temporary flight within the same boundary and buffer until leaving the Pocket Base. Entering the flight portal immediately starts the player flying and displays “Pocket dimension flight enabled!” once, without repeating while they stand inside the portal. The owner's automatic-flight preference does not affect portal-granted flight. Pocket Base owners can also craft a reusable **Pocket Base Keystone**. Its shaped recipe uses an Ender Pearl in the center, Netherite Ingots on the four cardinal slots, and Obsidian in the four corners. Right-clicking the keystone outside a Pocket Base instantly records the player's location and takes them to their own Pocket Base. Right-clicking it again inside their own Pocket Base returns them to that exact location when the world and destination remain available and safe. Saved returns survive reconnects and server restarts. A transferred keystone only works for a player who has unlocked their own Pocket Base. diff --git a/design/user-stories/us-022-share-pocket-base-flight-through-a-portal.md b/design/user-stories/us-022-share-pocket-base-flight-through-a-portal.md index b592c24..21fa2fd 100644 --- a/design/user-stories/us-022-share-pocket-base-flight-through-a-portal.md +++ b/design/user-stories/us-022-share-pocket-base-flight-through-a-portal.md @@ -11,6 +11,10 @@ As a **Pocket Base owner**, I want an activated flight portal inside my Pocket B ## Acceptance criteria +- [x] Entering the active flight portal immediately starts eligible Survival players flying without double-jumping. +- [x] Each portal entry sends “Pocket dimension flight enabled!” without repeated messages while standing in the portal. +- [x] Immediate takeoff preserves existing flight boundaries and expiry rules, with regression tests. + - [x] The owner must first unlock Pocket Base flight by winning a raid in their own Pocket Base. - [x] Only the owner can activate a complete 4-by-5 gold-block frame with flint and steel as the active flight portal. - [x] Every required frame block must be inside the owner's currently unlocked Pocket Base boundary at activation. diff --git a/src/main/java/games/dmg/spigotbase/BaseFlightController.java b/src/main/java/games/dmg/spigotbase/BaseFlightController.java index 9d7e6a5..e555710 100644 --- a/src/main/java/games/dmg/spigotbase/BaseFlightController.java +++ b/src/main/java/games/dmg/spigotbase/BaseFlightController.java @@ -107,7 +107,18 @@ final class BaseFlightController implements Runnable, Listener { } void grantPocketPortalFlight(Player player, UUID ownerId) { + if (player.getGameMode() != GameMode.SURVIVAL || pocketBases == null + || !pocketBases.ownerForPocketWorld(player.getWorld().getUID()) + .filter(ownerId::equals).isPresent()) { + return; + } portalFlight.put(player.getUniqueId(), ownerId); + if (applyPocketFlight(player, ownerId)) { + player.setFlying(true); + player.sendMessage(ChatColor.GREEN + "Pocket dimension flight enabled!"); + } else { + portalFlight.remove(player.getUniqueId()); + } } @Override @@ -220,14 +231,14 @@ final class BaseFlightController implements Runnable, Listener { } } - private void applyPocketFlight(Player player, UUID ownerId) { + private boolean applyPocketFlight(Player player, UUID ownerId) { PocketBaseState pocket = pocketBases.state(ownerId); boolean ownerFlight = ownerId.equals(player.getUniqueId()) && pocket.flightUnlocked() && pocket.flightEnabled(); boolean temporaryFlight = ownerId.equals(portalFlight.get(player.getUniqueId())); if ((!ownerFlight && !temporaryFlight) || pocket.level() < 1) { removeGrantedFlight(player); - return; + return false; } int halfSize = pocketBases.policy().size(pocket.level()) / 2; int x = player.getLocation().getBlockX(); @@ -237,7 +248,7 @@ final class BaseFlightController implements Runnable, Listener { || z < -halfSize - POCKET_FLIGHT_BUFFER || z >= halfSize + POCKET_FLIGHT_BUFFER) { removeGrantedFlight(player); - return; + return false; } if (!player.getAllowFlight()) { player.setAllowFlight(true); @@ -257,6 +268,7 @@ final class BaseFlightController implements Runnable, Listener { } else { warned.remove(player.getUniqueId()); } + return true; } private void clearPortalFlight(Player player) { diff --git a/src/main/java/games/dmg/spigotbase/PocketBaseController.java b/src/main/java/games/dmg/spigotbase/PocketBaseController.java index b7ce2f0..7d48882 100644 --- a/src/main/java/games/dmg/spigotbase/PocketBaseController.java +++ b/src/main/java/games/dmg/spigotbase/PocketBaseController.java @@ -246,7 +246,8 @@ final class PocketBaseController implements Listener, Runnable { if (isIntact(portal, Material.GOLD_BLOCK) && PocketPortalGeometry.isInterior( portal, position(destination) - )) { + ) && (event.getFrom() == null + || !PocketPortalGeometry.isInterior(portal, position(event.getFrom())))) { flightController.grantPocketPortalFlight(player, ownerId); } } diff --git a/src/test/java/games/dmg/spigotbase/BaseFlightControllerTest.java b/src/test/java/games/dmg/spigotbase/BaseFlightControllerTest.java index 170430a..51a26f6 100644 --- a/src/test/java/games/dmg/spigotbase/BaseFlightControllerTest.java +++ b/src/test/java/games/dmg/spigotbase/BaseFlightControllerTest.java @@ -232,10 +232,28 @@ final class BaseFlightControllerTest { new PocketBasePolicy(PluginSettings.from(Map.of())) ); + when(player.getGameMode()).thenReturn(org.bukkit.GameMode.CREATIVE); + pocketController.grantPocketPortalFlight(player, ownerId); + verify(player, never()).setFlying(true); + verify(player, never()).sendMessage(anyString()); + + when(player.getGameMode()).thenReturn(org.bukkit.GameMode.SURVIVAL); + when(location.getBlockX()).thenReturn(10000); + pocketController.grantPocketPortalFlight(player, ownerId); + verify(player, never()).setFlying(true); + verify(player, never()).sendMessage(anyString()); + + when(location.getBlockX()).thenReturn(0); pocketController.grantPocketPortalFlight(player, ownerId); - pocketController.run(); verify(player).setAllowFlight(true); + verify(player).setFlying(true); + verify(player).sendMessage(org.bukkit.ChatColor.GREEN + "Pocket dimension flight enabled!"); + + when(player.getAllowFlight()).thenReturn(true); + pocketController.grantPocketPortalFlight(player, ownerId); + verify(player, times(2)).setFlying(true); + verify(player, times(2)).sendMessage(org.bukkit.ChatColor.GREEN + "Pocket dimension flight enabled!"); } @Test diff --git a/src/test/java/games/dmg/spigotbase/PocketBaseControllerTest.java b/src/test/java/games/dmg/spigotbase/PocketBaseControllerTest.java index 857196d..967b514 100644 --- a/src/test/java/games/dmg/spigotbase/PocketBaseControllerTest.java +++ b/src/test/java/games/dmg/spigotbase/PocketBaseControllerTest.java @@ -456,6 +456,15 @@ final class PocketBaseControllerTest { controller.onMove(event); verify(flightController).grantPocketPortalFlight(guest, ownerId); + + when(event.getFrom()).thenReturn(destination); + controller.onMove(event); + verify(flightController).grantPocketPortalFlight(guest, ownerId); + + when(event.getFrom()).thenReturn(new Location(pocketWorld, 5, 66, 8)); + controller.onMove(event); + verify(flightController, org.mockito.Mockito.times(2)) + .grantPocketPortalFlight(guest, ownerId); } @Test