Skip to content

Commit

Permalink
Fix team swapping or blitz death joining obs in pugs (#42)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
Co-authored-by: Pugzy <[email protected]>
  • Loading branch information
Pablete1234 and Pugzy authored Apr 23, 2023
1 parent d85a53b commit fc2167e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/main/java/rip/bolt/ingame/managers/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand All @@ -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();
}
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/rip/bolt/ingame/pugs/PugListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/rip/bolt/ingame/pugs/PugManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/rip/bolt/ingame/ranked/RankedManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fc2167e

Please sign in to comment.