diff --git a/src/main/java/org/battleplugins/arena/ctf/arena/CtfCompetition.java b/src/main/java/org/battleplugins/arena/ctf/arena/CtfCompetition.java index 4bf3100..222f46e 100644 --- a/src/main/java/org/battleplugins/arena/ctf/arena/CtfCompetition.java +++ b/src/main/java/org/battleplugins/arena/ctf/arena/CtfCompetition.java @@ -2,11 +2,17 @@ import net.kyori.adventure.text.Component; import org.battleplugins.arena.ArenaPlayer; +import org.battleplugins.arena.BattleArena; +import org.battleplugins.arena.BattleArenaApi; +import org.battleplugins.arena.BattleArenaConfig; import org.battleplugins.arena.competition.CompetitionType; import org.battleplugins.arena.competition.LiveCompetition; +import org.battleplugins.arena.competition.map.MapType; +import org.battleplugins.arena.competition.map.options.Bounds; import org.battleplugins.arena.ctf.ArenaCtf; import org.battleplugins.arena.ctf.CtfMessages; import org.battleplugins.arena.ctf.CtfUtil; +import org.battleplugins.arena.ctf.arena.CtfCompetition.ActiveFlag; import org.battleplugins.arena.ctf.event.ArenaFlagCaptureEvent; import org.battleplugins.arena.ctf.event.ArenaFlagReturnEvent; import org.battleplugins.arena.messages.Message; @@ -22,6 +28,7 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.Nullable; +import org.bukkit.util.Vector; import java.awt.Color; import java.time.Duration; @@ -113,7 +120,23 @@ public void tickFlags() { continue; } - if (flag.flag.getCaptureRegion().isInside(player.getLocation().toBlockLocation())) { + Bounds captureRegion = flag.flag.getCaptureRegion(); + if (map.getType() == MapType.DYNAMIC && BattleArena.getInstance().getMainConfig().centerDynamicArena()) { + Bounds mapBounds = map.getBounds(); + int offsetX = (mapBounds.getMinX() + mapBounds.getMaxX()) / 2; + int offsetZ = (mapBounds.getMinZ() + mapBounds.getMaxZ()) / 2; + + captureRegion = new Bounds( + captureRegion.getMinX() - offsetX, + captureRegion.getMinY(), + captureRegion.getMinZ() - offsetZ, + captureRegion.getMaxX() - offsetX, + captureRegion.getMaxY(), + captureRegion.getMaxZ() - offsetZ + ); + } + + if (captureRegion.isInside(player.getLocation().toBlockLocation())) { if (flag.team.equals(arenaPlayer.getTeam())) { // Check to see if a player is holding the opposite team's flag if (this.capturedFlags.containsKey(arenaPlayer)) { @@ -312,6 +335,18 @@ public void placeFlag(float yaw) { return; } + if (map.getType() == MapType.DYNAMIC && BattleArena.getInstance().getMainConfig().centerDynamicArena()) { + Bounds bounds = map.getBounds(); + Vector center = new Vector( + (bounds.getMinX() + bounds.getMaxX()) / 2.0, + bounds.getMinY(), + (bounds.getMinZ() + bounds.getMaxZ()) / 2.0 + ); + + // Offset the flag location by the dynamic map's center + this.flagLocation = this.flagLocation.clone().subtract(center.getX(), 0, center.getZ()); + } + Rotatable rotatable = (Rotatable) bannerMaterial.createBlockData(); rotatable.setRotation(this.flag.getBlockFace(yaw)); this.flagLocation.getBlock().setBlockData(rotatable);