Skip to content

Commit

Permalink
Fix spectators not being properly cleared/removed from competitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 18, 2024
1 parent 1bfcd6a commit 7b30c27
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;

import java.util.Set;

class CompetitionListener<T extends Competition<T>> implements ArenaListener, CompetitionLike<T> {

private final LiveCompetition<T> competition;
Expand All @@ -27,7 +29,18 @@ public CompetitionListener(LiveCompetition<T> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 7b30c27

Please sign in to comment.