Skip to content

Commit

Permalink
Add link to match stats on match end
Browse files Browse the repository at this point in the history
  • Loading branch information
Pugzy authored Apr 1, 2021
1 parent 5866562 commit 4312a28
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import rip.bolt.ingame.Ingame;
import rip.bolt.ingame.api.definitions.BoltMatch;
import rip.bolt.ingame.api.definitions.Punishment;
import rip.bolt.ingame.config.AppData;
import rip.bolt.ingame.ranked.MatchStatus;
import rip.bolt.ingame.ranked.RankedManager;
import rip.bolt.ingame.utils.Messages;
Expand Down Expand Up @@ -78,7 +79,9 @@ public void match(CommandSender sender) throws CommandException {
if (boltMatch == null)
throw new CommandException(ChatColor.RED + "No Bolt match currently loaded.");

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

@Command(
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/rip/bolt/ingame/config/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public static String getServerName() {
}
}

public static class Web {

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

public static String getProfile() {
return Ingame.get().getConfig().getString("web.profile", null);
}
}

public static long absentSecondsLimit() {
return Ingame.get().getConfig().getLong("absence-time-seconds", 120);
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/rip/bolt/ingame/ranked/RankManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rip.bolt.ingame.ranked;

import static tc.oc.pgm.lib.net.kyori.adventure.text.Component.empty;
import static tc.oc.pgm.lib.net.kyori.adventure.text.Component.text;

import java.util.ArrayList;
Expand All @@ -21,8 +22,11 @@
import rip.bolt.ingame.api.definitions.Participation;
import rip.bolt.ingame.api.definitions.Team;
import rip.bolt.ingame.api.definitions.User;
import rip.bolt.ingame.config.AppData;
import rip.bolt.ingame.utils.Messages;
import tc.oc.pgm.api.PGM;
import tc.oc.pgm.api.event.NameDecorationChangeEvent;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchManager;
import tc.oc.pgm.api.match.event.MatchStatsEvent;
import tc.oc.pgm.api.party.Competitor;
Expand Down Expand Up @@ -86,9 +90,13 @@ public void handleMatchUpdate(@Nonnull BoltMatch oldMatch, @Nonnull BoltMatch ne

if (updates.isEmpty()) return;

Bukkit.getServer()
.getPluginManager()
.callEvent(new MatchStatsEvent(updates.get(0).player.getMatch(), true, true));
Match match = updates.get(0).player.getMatch();
Bukkit.getServer().getPluginManager().callEvent(new MatchStatsEvent(match, true, true));

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

updates.forEach(update -> notifyUpdate(update.old, update.updated, update.player));
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/rip/bolt/ingame/utils/Components.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public static Component command(Style style, String command, String... args) {
.append(Component.text(command, style)));
}

public static Component link(Style style, String url) {
return Component.text(url, style)
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, url))
.hoverEvent(
Component.text("Click to visit ", NamedTextColor.YELLOW)
.append(Component.text(url, style)));
}

static String toArgument(String input) {
if (input == null) return null;
return input.replace(" ", "┈");
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/rip/bolt/ingame/utils/Messages.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package rip.bolt.ingame.utils;

import static rip.bolt.ingame.utils.Components.command;
import static rip.bolt.ingame.utils.Components.link;
import static tc.oc.pgm.lib.net.kyori.adventure.text.Component.newline;
import static tc.oc.pgm.lib.net.kyori.adventure.text.Component.text;

import rip.bolt.ingame.api.definitions.BoltMatch;
import rip.bolt.ingame.config.AppData;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.lib.net.kyori.adventure.text.Component;
import tc.oc.pgm.lib.net.kyori.adventure.text.format.NamedTextColor;
import tc.oc.pgm.lib.net.kyori.adventure.text.format.Style;
Expand All @@ -25,4 +29,18 @@ public static Component forfeit() {
command(
Style.style(NamedTextColor.YELLOW, TextDecoration.UNDERLINED), "forfeit")));
}

public static Component matchLink(BoltMatch match) {
String url = AppData.Web.getMatch().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());

return text("Profile link: ", NamedTextColor.WHITE)
.append(link(Style.style(NamedTextColor.BLUE, TextDecoration.UNDERLINED), url));
}
}
6 changes: 6 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ allow-forfeit: true
# duration to countdown before starting match
match-start-duration: "300s"

# website page links (remove section to remove references)
web:
match: https://localhost:3000/matches/{matchId}
profile: https://localhost:3000/{name}

# api connection details
api:
url: https://localhost:3000/v1/
key: authorisation-key
Expand Down

0 comments on commit 4312a28

Please sign in to comment.