From fc2167e3f6b8ec5c0c3775ef17602d02a621d54e Mon Sep 17 00:00:00 2001 From: Pablo Herrera Date: Sun, 23 Apr 2023 17:56:16 +0200 Subject: [PATCH] Fix team swapping or blitz death joining obs in pugs (#42) Signed-off-by: Pablo Herrera Co-authored-by: Pugzy --- .../rip/bolt/ingame/managers/GameManager.java | 8 +++++++- .../java/rip/bolt/ingame/pugs/PugListener.java | 17 +++++++++++------ .../java/rip/bolt/ingame/pugs/PugManager.java | 1 + .../rip/bolt/ingame/ranked/RankedManager.java | 1 + 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/rip/bolt/ingame/managers/GameManager.java b/src/main/java/rip/bolt/ingame/managers/GameManager.java index d077605..0ec93c7 100644 --- a/src/main/java/rip/bolt/ingame/managers/GameManager.java +++ b/src/main/java/rip/bolt/ingame/managers/GameManager.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable; import rip.bolt.ingame.Ingame; import rip.bolt.ingame.api.definitions.BoltMatch; +import rip.bolt.ingame.api.definitions.Series; import rip.bolt.ingame.pugs.PugManager; import rip.bolt.ingame.ranked.RankedManager; @@ -50,7 +51,11 @@ public void enable(MatchManager manager) { Bukkit.getPluginManager().registerEvents(this, Ingame.get()); } - public abstract void setup(BoltMatch match); + public void setup(@Nullable BoltMatch match) { + boolean allowSpectators = + (match != null && match.getSeries().getService() != Series.Service.TM); + EventsPlugin.get().getConfig().set("allow-spectators", allowSpectators); + } /** Called when the game manager is removed. */ public void disable() { @@ -67,6 +72,7 @@ public void enable(MatchManager manager) {} @Override public void setup(BoltMatch match) { + super.setup(match); EventsPlugin.get().getTeamManager().clear(); EventsPlugin.get().getTournamentManager().deleteTournament(); } diff --git a/src/main/java/rip/bolt/ingame/pugs/PugListener.java b/src/main/java/rip/bolt/ingame/pugs/PugListener.java index ea6e9b1..b1ffc26 100644 --- a/src/main/java/rip/bolt/ingame/pugs/PugListener.java +++ b/src/main/java/rip/bolt/ingame/pugs/PugListener.java @@ -21,6 +21,7 @@ import rip.bolt.ingame.events.BoltMatchStatusChangeEvent; import tc.oc.pgm.api.match.event.MatchLoadEvent; import tc.oc.pgm.api.party.Competitor; +import tc.oc.pgm.api.party.Party; import tc.oc.pgm.api.party.event.PartyRenameEvent; import tc.oc.pgm.api.player.event.PlayerVanishEvent; import tc.oc.pgm.events.PlayerParticipationStartEvent; @@ -124,15 +125,19 @@ public void onParticipate(PlayerParticipationStartEvent event) { @EventHandler(priority = EventPriority.HIGHEST) public void onLeaveParticipate(PlayerParticipationStopEvent event) { - // Can't ignore not-cancelled, as blitz is not cancelled but still should move to obs on ws. - // However, events still sets a cancel reason which is convenient. + if (!event.isCancelled()) return; // Events should expose this constant. It'll still be dirty, but will survive updates. - if (isMessage(event.getCancelReason(), "You may not leave in a tournament setting!")) { - pugManager.write(PugCommand.joinObs(event.getPlayer().getBukkit())); + if (!isMessage(event.getCancelReason(), "You may not leave in a tournament setting!")) return; + event.cancel(Component.empty()); - // If event was cancelled, clear the component - if (event.isCancelled()) event.cancel(Component.empty()); + Party nextParty = event.getNextParty(); + + if (nextParty instanceof Competitor) { + PugTeam team = pugManager.findPugTeam(nextParty); + if (team != null) pugManager.write(PugCommand.joinTeam(event.getPlayer().getBukkit(), team)); + } else if (nextParty != null) { + pugManager.write(PugCommand.joinObs(event.getPlayer().getBukkit())); } } diff --git a/src/main/java/rip/bolt/ingame/pugs/PugManager.java b/src/main/java/rip/bolt/ingame/pugs/PugManager.java index 799e2ff..e439082 100644 --- a/src/main/java/rip/bolt/ingame/pugs/PugManager.java +++ b/src/main/java/rip/bolt/ingame/pugs/PugManager.java @@ -83,6 +83,7 @@ public void enable(MatchManager manager) { @Override public void setup(BoltMatch match) { + super.setup(match); if (this.pugLobby != null) teamManager.setupTeams(match); } diff --git a/src/main/java/rip/bolt/ingame/ranked/RankedManager.java b/src/main/java/rip/bolt/ingame/ranked/RankedManager.java index c5f36ba..16b3a90 100644 --- a/src/main/java/rip/bolt/ingame/ranked/RankedManager.java +++ b/src/main/java/rip/bolt/ingame/ranked/RankedManager.java @@ -47,6 +47,7 @@ public void enable(MatchManager manager) { @Override public void setup(BoltMatch match) { + super.setup(match); EventsPlugin.get().getTeamManager().clear(); for (TournamentTeam team : match.getTeams()) EventsPlugin.get().getTeamManager().addTeam(team); playerWatcher.addPlayers(