Skip to content

Commit

Permalink
Fix missing match link during PUG games
Browse files Browse the repository at this point in the history
  • Loading branch information
Pugzy committed Sep 17, 2023
1 parent 637d1f2 commit 7fb3549
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/rip/bolt/ingame/commands/AdminCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void match(MatchManager matchManager, CommandSender sender) throws Comman

Audience audience = Audience.get(sender);
audience.sendMessage(text(boltMatch.toString(), NamedTextColor.GRAY));
if (AppData.Web.getMatch() != null) audience.sendMessage(Messages.matchLink(boltMatch));
if (AppData.Web.getMatchLink() != null) audience.sendMessage(Messages.matchLink(boltMatch));
}

@CommandMethod("status")
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rip/bolt/ingame/config/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static String getServerName() {

public static class Web {

public static String getMatch() {
public static String getMatchLink() {
return Ingame.get().getConfig().getString("web.match", null);
}

public static String getProfile() {
public static String getProfileLink() {
return Ingame.get().getConfig().getString("web.profile", null);
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/rip/bolt/ingame/pugs/PugListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package rip.bolt.ingame.pugs;

import static net.kyori.adventure.text.Component.empty;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
Expand All @@ -15,11 +17,17 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import rip.bolt.ingame.api.definitions.BoltMatch;
import rip.bolt.ingame.api.definitions.MatchStatus;
import rip.bolt.ingame.api.definitions.pug.PugCommand;
import rip.bolt.ingame.api.definitions.pug.PugTeam;
import rip.bolt.ingame.commands.PugCommands;
import rip.bolt.ingame.config.AppData;
import rip.bolt.ingame.events.BoltMatchResponseEvent;
import rip.bolt.ingame.events.BoltMatchStatusChangeEvent;
import rip.bolt.ingame.utils.Messages;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.event.MatchLoadEvent;
import tc.oc.pgm.api.match.event.MatchStatsEvent;
import tc.oc.pgm.api.party.Competitor;
import tc.oc.pgm.api.party.Party;
import tc.oc.pgm.api.party.event.PartyRenameEvent;
Expand Down Expand Up @@ -90,6 +98,20 @@ public void onBoltMatchStateChange(BoltMatchStatusChangeEvent event) {
pugManager.write(PugCommand.setMatchStatus(match));
}

@EventHandler(priority = EventPriority.NORMAL)
public void onBoltMatchResponse(BoltMatchResponseEvent event) {
BoltMatch newMatch = event.getResponseMatch();
if (!event.hasMatchFinished() || newMatch.getStatus() != MatchStatus.ENDED) return;

Match match = event.getPgmMatch();
match.callEvent(new MatchStatsEvent(match, true, true));

if (AppData.Web.getMatchLink() != null) {
match.sendMessage(Messages.matchLink(newMatch));
match.sendMessage(empty());
}
}

@EventHandler
public void onTeamChangeSize(TeamResizeEvent event) {
int newMax = event.getTeam().getMaxPlayers();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rip/bolt/ingame/ranked/RankManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public void handleMatchUpdate(
.filter(RankUpdate::isValid)
.collect(Collectors.toList());

Bukkit.getServer().getPluginManager().callEvent(new MatchStatsEvent(match, true, true));
match.callEvent(new MatchStatsEvent(match, true, true));

if (AppData.Web.getMatch() != null) {
if (AppData.Web.getMatchLink() != null) {
match.sendMessage(Messages.matchLink(newMatch));
match.sendMessage(empty());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rip/bolt/ingame/utils/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public static Component participationBan() {
}

public static Component matchLink(BoltMatch match) {
String url = AppData.Web.getMatch().replace("{matchId}", match.getId());
String url = AppData.Web.getMatchLink().replace("{matchId}", match.getId());

return text("Match link: ", NamedTextColor.WHITE)
.append(link(Style.style(NamedTextColor.BLUE, TextDecoration.UNDERLINED), url));
}

public static Component profileLink(MatchPlayer player) {
String url = AppData.Web.getProfile().replace("{name}", player.getNameLegacy());
String url = AppData.Web.getProfileLink().replace("{name}", player.getNameLegacy());

return text("Profile link: ", NamedTextColor.WHITE)
.append(link(Style.style(NamedTextColor.BLUE, TextDecoration.UNDERLINED), url));
Expand Down

0 comments on commit 7fb3549

Please sign in to comment.