From 784ad9fb71c5e31c7704565b063cbe154a016b3f Mon Sep 17 00:00:00 2001 From: Tofpu Date: Tue, 23 Jan 2024 02:26:48 +0200 Subject: [PATCH] Introduce `ArenaManagerOptions` to remove a couple of classes --- .../common/game/BridgeSystem.java | 6 ++++- .../common/game/IslandGameArenaManager.java | 19 -------------- .../land/arena/ArenaManagerOptions.java | 25 +++++++++++++++++++ .../land/arena/BasicArenaManager.java | 20 ++++++++------- .../common/setup/GameSetupSystem.java | 6 ++++- .../common/setup/IslandSetupArenaManager.java | 11 -------- 6 files changed, 46 insertions(+), 41 deletions(-) delete mode 100644 common/src/main/java/com/github/tofpu/speedbridge2/common/game/IslandGameArenaManager.java create mode 100644 common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/ArenaManagerOptions.java delete mode 100644 common/src/main/java/com/github/tofpu/speedbridge2/common/setup/IslandSetupArenaManager.java diff --git a/common/src/main/java/com/github/tofpu/speedbridge2/common/game/BridgeSystem.java b/common/src/main/java/com/github/tofpu/speedbridge2/common/game/BridgeSystem.java index 4e04a0bb..44cf6e98 100644 --- a/common/src/main/java/com/github/tofpu/speedbridge2/common/game/BridgeSystem.java +++ b/common/src/main/java/com/github/tofpu/speedbridge2/common/game/BridgeSystem.java @@ -7,16 +7,20 @@ import com.github.tofpu.speedbridge2.common.game.listener.GameListener; import com.github.tofpu.speedbridge2.common.gameextra.land.Land; import com.github.tofpu.speedbridge2.common.gameextra.land.LandController; +import com.github.tofpu.speedbridge2.common.gameextra.land.arena.ArenaManagerOptions; +import com.github.tofpu.speedbridge2.common.gameextra.land.arena.BasicArenaManager; import com.github.tofpu.speedbridge2.common.island.Island; import com.github.tofpu.speedbridge2.common.lobby.LobbyService; import com.github.tofpu.speedbridge2.common.schematic.SchematicHandler; import com.github.tofpu.speedbridge2.event.dispatcher.EventDispatcherService; +import com.github.tofpu.speedbridge2.object.Vector; import com.github.tofpu.speedbridge2.object.player.OnlinePlayer; import com.github.tofpu.speedbridge2.service.manager.ServiceManager; import java.util.UUID; public class BridgeSystem { + private static final ArenaManagerOptions DEFAULT_OPTIONS = new ArenaManagerOptions(new Vector(0, 100, 0), 10); private final EventDispatcherService eventDispatcher; private final IslandGameHandler gameHandler; private final GameLandReserver landReserver; @@ -25,7 +29,7 @@ public BridgeSystem(EventDispatcherService eventDispatcher, SchematicHandler sch this.eventDispatcher = eventDispatcher; this.gameHandler = new IslandGameHandler(eventDispatcher); - LandController landController = new LandController(new IslandGameArenaManager(arenaAdapter)); + LandController landController = new LandController(new BasicArenaManager(arenaAdapter, DEFAULT_OPTIONS)); this.landReserver = new GameLandReserver(arenaAdapter.gameWorld(), schematicHandler, landController); } diff --git a/common/src/main/java/com/github/tofpu/speedbridge2/common/game/IslandGameArenaManager.java b/common/src/main/java/com/github/tofpu/speedbridge2/common/game/IslandGameArenaManager.java deleted file mode 100644 index 840ea898..00000000 --- a/common/src/main/java/com/github/tofpu/speedbridge2/common/game/IslandGameArenaManager.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.tofpu.speedbridge2.common.game; - -import com.github.tofpu.speedbridge2.common.PlatformArenaAdapter; -import com.github.tofpu.speedbridge2.common.gameextra.land.arena.BasicArenaManager; -import com.github.tofpu.speedbridge2.object.Vector; - -public class IslandGameArenaManager extends BasicArenaManager { - // todo: make this option configurable - private static final int ISLAND_GAP = 10; - - public IslandGameArenaManager(PlatformArenaAdapter arenaAdapter) { - super(arenaAdapter, new Vector(0, 100, 0)); - } - - @Override - protected int gapBetweenLand() { - return ISLAND_GAP; - } -} diff --git a/common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/ArenaManagerOptions.java b/common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/ArenaManagerOptions.java new file mode 100644 index 00000000..04ff71f1 --- /dev/null +++ b/common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/ArenaManagerOptions.java @@ -0,0 +1,25 @@ +package com.github.tofpu.speedbridge2.common.gameextra.land.arena; + +import com.github.tofpu.speedbridge2.object.Vector; + +public class ArenaManagerOptions { + private final Vector initialPosition; + private final int gapBetweenIsland; + + public ArenaManagerOptions(Vector initialPosition, int gapBetweenIsland) { + this.initialPosition = initialPosition; + this.gapBetweenIsland = gapBetweenIsland; + } + + public ArenaManagerOptions(Vector initialPosition) { + this(initialPosition, 10); + } + + public Vector initialPosition() { + return initialPosition; + } + + public int gapBetweenIsland() { + return gapBetweenIsland; + } +} diff --git a/common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/BasicArenaManager.java b/common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/BasicArenaManager.java index 4cb93679..22b5913c 100644 --- a/common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/BasicArenaManager.java +++ b/common/src/main/java/com/github/tofpu/speedbridge2/common/gameextra/land/arena/BasicArenaManager.java @@ -14,19 +14,17 @@ import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; -public abstract class BasicArenaManager implements ArenaManager { - protected final PlatformArenaAdapter arenaAdapter; +public class BasicArenaManager implements ArenaManager { + protected final ArenaManagerOptions options; protected final ClipboardPaster clipboardPaster; - protected final Vector initialPosition; private final AtomicInteger offsetX; private final Queue landReserves; - public BasicArenaManager(PlatformArenaAdapter arenaAdapter, Vector initialPosition) { - this.arenaAdapter = arenaAdapter; + public BasicArenaManager(PlatformArenaAdapter arenaAdapter, ArenaManagerOptions options) { + this.options = options; this.clipboardPaster = arenaAdapter.clipboardPaster(); - this.initialPosition = initialPosition; - this.offsetX = new AtomicInteger((int) initialPosition.x()); + this.offsetX = new AtomicInteger((int) initialPosition().x()); this.landReserves = new LinkedList<>(); } @@ -91,10 +89,14 @@ public void clear(Land land) { } protected Position reservePosition(RegionInfo region, World world) { - return new Position(world, offsetX.getAndAdd(region.getWidth() + gapBetweenLand()), (int) initialPosition.y(), (int) initialPosition.z()); + return new Position(world, offsetX.getAndAdd(region.getWidth() + gapBetweenLand()), (int) initialPosition().y(), (int) initialPosition().z()); } protected int gapBetweenLand() { - return 10; + return options.gapBetweenIsland(); + } + + public Vector initialPosition() { + return options.initialPosition(); } } diff --git a/common/src/main/java/com/github/tofpu/speedbridge2/common/setup/GameSetupSystem.java b/common/src/main/java/com/github/tofpu/speedbridge2/common/setup/GameSetupSystem.java index 31d2ddd4..029016c6 100644 --- a/common/src/main/java/com/github/tofpu/speedbridge2/common/setup/GameSetupSystem.java +++ b/common/src/main/java/com/github/tofpu/speedbridge2/common/setup/GameSetupSystem.java @@ -4,6 +4,8 @@ import com.github.tofpu.speedbridge2.common.gameextra.land.GameLandReserver; import com.github.tofpu.speedbridge2.common.gameextra.land.Land; import com.github.tofpu.speedbridge2.common.gameextra.land.LandController; +import com.github.tofpu.speedbridge2.common.gameextra.land.arena.ArenaManagerOptions; +import com.github.tofpu.speedbridge2.common.gameextra.land.arena.BasicArenaManager; import com.github.tofpu.speedbridge2.common.island.Island; import com.github.tofpu.speedbridge2.common.island.IslandService; import com.github.tofpu.speedbridge2.common.lobby.LobbyService; @@ -11,6 +13,7 @@ import com.github.tofpu.speedbridge2.common.setup.listener.IslandSetupListener; import com.github.tofpu.speedbridge2.event.dispatcher.EventDispatcherService; import com.github.tofpu.speedbridge2.object.Location; +import com.github.tofpu.speedbridge2.object.Vector; import com.github.tofpu.speedbridge2.object.World; import com.github.tofpu.speedbridge2.object.player.OnlinePlayer; import com.github.tofpu.speedbridge2.service.manager.ServiceManager; @@ -19,6 +22,7 @@ import java.util.UUID; public class GameSetupSystem { + private static final ArenaManagerOptions DEFAULT_OPTIONS = new ArenaManagerOptions(new Vector(0, 100, 100)); private final IslandSetupHandler setupHandler; private final EventDispatcherService eventDispatcherService; private final World world; @@ -29,7 +33,7 @@ public GameSetupSystem(EventDispatcherService eventDispatcherService, PlatformAr this.setupHandler = new IslandSetupHandler(eventDispatcherService); this.eventDispatcherService = eventDispatcherService; this.world = arenaAdapter.gameWorld(); - this.landReserver = new GameLandReserver(world, schematicHandler, new LandController(new IslandSetupArenaManager(arenaAdapter))); + this.landReserver = new GameLandReserver(world, schematicHandler, new LandController(new BasicArenaManager(arenaAdapter, DEFAULT_OPTIONS))); this.islandService = islandService; } diff --git a/common/src/main/java/com/github/tofpu/speedbridge2/common/setup/IslandSetupArenaManager.java b/common/src/main/java/com/github/tofpu/speedbridge2/common/setup/IslandSetupArenaManager.java deleted file mode 100644 index 74dcf79d..00000000 --- a/common/src/main/java/com/github/tofpu/speedbridge2/common/setup/IslandSetupArenaManager.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.tofpu.speedbridge2.common.setup; - -import com.github.tofpu.speedbridge2.common.PlatformArenaAdapter; -import com.github.tofpu.speedbridge2.common.gameextra.land.arena.BasicArenaManager; -import com.github.tofpu.speedbridge2.object.Vector; - -public class IslandSetupArenaManager extends BasicArenaManager { - public IslandSetupArenaManager(PlatformArenaAdapter arenaAdapter) { - super(arenaAdapter, new Vector(0, 100, 100)); - } -}