diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionListener.java b/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionListener.java index bb6a5342..471a52a2 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionListener.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionListener.java @@ -17,6 +17,8 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import java.util.Set; + class CompetitionListener> implements ArenaListener, CompetitionLike { private final LiveCompetition competition; @@ -27,7 +29,18 @@ public CompetitionListener(LiveCompetition competition) { @ArenaEventHandler(priority = EventPriority.HIGHEST) public void onPhaseComplete(ArenaPhaseCompleteEvent event) { - if (event.getCompetition().getMap().getType() == MapType.DYNAMIC && event.getPhase() instanceof VictoryPhase) { + if (!(event.getPhase() instanceof VictoryPhase)) { + return; + } + + // Kick all spectators once the game is over + if (event.getCompetition() instanceof LiveCompetition liveCompetition) { + for (ArenaPlayer spectator : Set.copyOf(liveCompetition.getSpectators())) { + spectator.getCompetition().leave(spectator, ArenaLeaveEvent.Cause.GAME); + } + } + + if (event.getCompetition().getMap().getType() == MapType.DYNAMIC) { Arena arena = event.getArena(); // Teardown if we are in a dynamic map diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionManager.java b/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionManager.java index 048ca8c6..6cdd8026 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionManager.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/CompetitionManager.java @@ -181,6 +181,11 @@ public void removeCompetition(Arena arena, Competition competition) { } } + // Remove spectators + for (ArenaPlayer player : Set.copyOf(liveCompetition.getSpectators())) { + liveCompetition.leave(player, ArenaLeaveEvent.Cause.SHUTDOWN); + } + liveCompetition.destroy(); }