From a7ce44aac56ccdb8a24a15c0c1b8295c7d23693f Mon Sep 17 00:00:00 2001 From: TBG <46306028+TBG1000@users.noreply.github.com> Date: Sat, 23 Jul 2022 13:42:28 -0500 Subject: [PATCH] Remove commented code & authors/pools/objective from finish --- .../java/me/tbg/match/bot/DiscordBot.java | 75 --------- .../me/tbg/match/bot/MatchFinishListener.java | 150 ------------------ 2 files changed, 225 deletions(-) diff --git a/src/main/java/me/tbg/match/bot/DiscordBot.java b/src/main/java/me/tbg/match/bot/DiscordBot.java index 1d5fd97..76723aa 100644 --- a/src/main/java/me/tbg/match/bot/DiscordBot.java +++ b/src/main/java/me/tbg/match/bot/DiscordBot.java @@ -18,15 +18,6 @@ import tc.oc.pgm.rotation.MapPoolManager; import tc.oc.pgm.rotation.pools.MapPool; -// import tc.oc.pgm.api.player.MatchPlayer; -// import org.javacord.api.entity.channel.TextChannel; -// import org.javacord.api.entity.message.MessageBuilder; -// import org.javacord.api.entity.message.MessageFlag; -// import org.javacord.api.entity.message.component.ActionRow; -// import org.javacord.api.entity.message.component.Button; -// import java.util.*; -// import java.util.List; - public class DiscordBot { private DiscordApi api; @@ -84,58 +75,6 @@ public void sendMatchEmbed(EmbedBuilder embed, Match match) { } } - /* - public void sendMatchFinishEmbeds( - EmbedBuilder matchInfo, EmbedBuilder teamStats, EmbedBuilder matchStats) { - List matchEmbeds = new ArrayList<>(); - matchEmbeds.add(matchInfo); - if (teamStats != null) { - matchEmbeds.add(teamStats); - } - matchEmbeds.add(matchStats); - TextChannel textChannel = - api.getServerById(config.getServerId()) - .flatMap(serverById -> serverById.getChannelById(config.getMatchChannel())) - .flatMap(Channel::asTextChannel) - .orElse(null); - MessageBuilder embeds = new MessageBuilder(); - embeds.setEmbed(matchEmbeds.get(0)); - if (teamStats != null) { - embeds.addComponents( - ActionRow.of( - Button.primary("team", "Team Stats"), Button.primary("match", "Match Stats"))); - } else { - embeds.addComponents(ActionRow.of(Button.primary("match", "Match Stats"))); - } - if (textChannel != null) { - embeds - .send(textChannel) - .thenAccept( - message -> - message.addButtonClickListener( - buttonClickEvent -> { - if (buttonClickEvent.getButtonInteractionWithCustomId("team").isPresent()) { - buttonClickEvent - .getInteraction() - .createImmediateResponder() - .setFlags(MessageFlag.EPHEMERAL) - .addEmbed(matchEmbeds.get(1)) - .respond(); - } else if (buttonClickEvent - .getButtonInteractionWithCustomId("match") - .isPresent()) { - buttonClickEvent - .getInteraction() - .createImmediateResponder() - .setFlags(MessageFlag.EPHEMERAL) - .addEmbed(matchEmbeds.get(2)) - .respond(); - } - })); - } - } - */ - public String parseDuration(Duration duration) { long hours = duration.toHours(); long minutes = duration.toMinutes() - (hours * 60); @@ -204,21 +143,7 @@ public long getOnlineStaffCount(Match match) { player -> (player.getBukkit().hasPermission(Permissions.STAFF) && !player.isVanished())) .count(); } - /* - public Map.Entry, Integer> sortStats(Map, Integer> map) { - return map.entrySet().stream().max(Comparator.comparingInt(Map.Entry::getValue)).orElse(null); - } - public String getPlayerName(Map.Entry, ?> map) { - return map.getKey().entrySet().stream().map(Map.Entry::getValue).collect(Collectors.joining()); - } - - public Map.Entry, Double> sortStatsDouble(Map, Double> map) { - return map.entrySet().stream() - .max(Comparator.comparingDouble(Map.Entry::getValue)) - .orElse(null); - } - */ public void reload() { if (this.api != null && !config.isEnabled()) { disable(); diff --git a/src/main/java/me/tbg/match/bot/MatchFinishListener.java b/src/main/java/me/tbg/match/bot/MatchFinishListener.java index 32acc1d..8ea88cf 100644 --- a/src/main/java/me/tbg/match/bot/MatchFinishListener.java +++ b/src/main/java/me/tbg/match/bot/MatchFinishListener.java @@ -14,13 +14,6 @@ import tc.oc.pgm.score.ScoreMatchModule; import tc.oc.pgm.teams.TeamMatchModule; -// import tc.oc.pgm.stats.PlayerStats; -// import tc.oc.pgm.stats.StatsMatchModule; -// import tc.oc.pgm.stats.TeamStats; -// import tc.oc.pgm.api.player.MatchPlayer; -// import tc.oc.pgm.api.Datastore; -// import tc.oc.pgm.api.PGM; - public class MatchFinishListener implements Listener { private final DiscordBot bot; @@ -36,145 +29,6 @@ public void onMatchFinish(MatchFinishEvent event) { ScoreMatchModule scoreModule = match.getModule(ScoreMatchModule.class); TeamMatchModule teamModule = match.getModule(TeamMatchModule.class); Collection teams = match.getCompetitors(); - /* - StatsMatchModule statsModule = match.getModule(StatsMatchModule.class); - Map matchPlayer = new HashMap<>(); - - Map, Integer> allKills = new HashMap<>(); - Map, Integer> allStreaks = new HashMap<>(); - Map, Integer> allDeaths = new HashMap<>(); - Map, Integer> allShots = new HashMap<>(); - Map, Double> allDamage = new HashMap<>(); - - for (MatchPlayer player : match.getPlayers()) { - if (statsModule != null) { - UUID playerUUID = player.getId(); - String playerName = player.getNameLegacy(); - PlayerStats playerStats = statsModule.getPlayerStat(player.getId()); - matchPlayer.put(playerUUID, playerName); - allKills.put(matchPlayer, playerStats.getKills()); - allStreaks.put(matchPlayer, playerStats.getMaxKillstreak()); - allDeaths.put(matchPlayer, playerStats.getDeaths()); - allShots.put(matchPlayer, playerStats.getLongestBowKill()); - allDamage.put(matchPlayer, playerStats.getDamageDone()); - } - } - - Map.Entry, Integer> highestKills = bot.sortStats(allKills); - Map.Entry, Integer> highestStreak = bot.sortStats(allStreaks); - Map.Entry, Integer> mostDeaths = bot.sortStats(allDeaths); - Map.Entry, Integer> longestShot = bot.sortStats(allShots); - Map.Entry, Double> highestDamage = bot.sortStatsDouble(allDamage); - - EmbedBuilder matchStats = - new EmbedBuilder() - .setTitle("Match #" + match.getId() + " Stats") - .setColor(Color.BLACK) - .setDescription( - "Match ended at with **" - + match.getPlayers().size() - + (match.getPlayers().size() == 1 ? " player" : " players") - + "** online.\nPlayed on **" - + map.getName() - + " (v" - + map.getVersion() - + ")**."); - if (scoreModule != null) { - if (teamModule != null) { - Map teamScores = new HashMap<>(); - for (Competitor team : teams) { - teamScores.put(team.getNameLegacy(), (int) scoreModule.getScore(team)); - } - matchStats.addField( - "Scores :trophy:", - teamScores.entrySet().stream() - .map(e -> e.getKey() + ": " + e.getValue() + " points") - .collect(Collectors.joining("\n"))); - } else { - Map playerScores = new HashMap<>(); - for (Competitor player : match.getCompetitors()) { - playerScores.put(player.getNameLegacy(), (int) scoreModule.getScore(player)); - } - matchStats.addField( - "Podium :trophy:", - playerScores.entrySet().stream() - .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) - .limit(3) - .map(e -> ":medal: " + e.getKey() + ": " + e.getValue() + " points") - .collect(Collectors.joining("\n"))); - } - } - - matchStats.addField( - "Kills :dagger:", highestKills.getValue() + " by " + bot.getPlayerName(highestKills)); - matchStats.addField( - "Deaths :coffin:", mostDeaths.getValue() + " by " + bot.getPlayerName(mostDeaths)); - matchStats.addField( - "Killstreak :bar_chart:", - highestStreak.getValue() + " by " + bot.getPlayerName(highestStreak)); - matchStats.addField( - "Longest shot :bow_and_arrow:", - longestShot.getValue() + " blocks by " + bot.getPlayerName(longestShot)); - matchStats.addField( - "Damage :heart:", highestDamage.getValue() + " by " + bot.getPlayerName(highestDamage)); - - EmbedBuilder teamStats = - new EmbedBuilder() - .setColor(Color.CYAN) - .setTitle("Match #" + match.getId() + " Team Stats") - .setDescription( - "Finished at with **" - + match.getPlayers().size() - + (match.getPlayers().size() == 1 ? " player" : " players") - + "** online on **" - + map.getName() - + " (v" - + map.getVersion() - + ")**"); - - if (teamModule != null) { - for (Competitor team : teams) { - teamStats.addField( - team.getNameLegacy() + ": " + team.getPlayers().size(), - team.getPlayers().isEmpty() - ? "_No players_" - : team.getPlayers().stream() - .map(MatchPlayer::getNameLegacy) - .collect(Collectors.joining(", "))); - TeamStats teamStatsTracker = new TeamStats(team, statsModule); - teamStats.addInlineField("Kills", ":dagger: " + teamStatsTracker.getTeamKills()); - teamStats.addInlineField("Deaths", ":coffin: " + teamStatsTracker.getTeamDeaths()); - teamStats.addInlineField("K/D", ":bar_chart: " + teamStatsTracker.getTeamKD()); - teamStats.addInlineField( - "DMG Dealt", - ":crossed_swords: " - + teamStatsTracker.getDamageDone() - + "\n:bow_and_arrow: " - + teamStatsTracker.getBowDamage()); - teamStats.addInlineField( - "DMG Received", - ":crossed_swords: " - + teamStatsTracker.getDamageTaken() - + "\n:bow_and_arrow: " - + teamStatsTracker.getBowDamageTaken()); - teamStats.addInlineField( - "Bow hits", - ":dart: " - + teamStatsTracker.getShotsHit() - + "/" - + teamStatsTracker.getShotsTaken() - + "\n:bar_chart: " - + teamStatsTracker.getTeamBowAcc() - + "%"); - } - } else { - teamStats = null; - } - */ String winner = ""; for (Competitor competitor : match.getCompetitors()) { @@ -231,14 +85,10 @@ public void onMatchFinish(MatchFinishEvent event) { .addInlineField("Map", map.getName()) .addInlineField("Version", map.getVersion().toString()) .addInlineField("Gamemodes", bot.getMapGamemodes(match).toUpperCase()) - .addInlineField("Created by", bot.getMapAuthors(match)) - .addInlineField("Pools", bot.getMapPools(match)) - .addField("Objective", map.getDescription()) .addInlineField("Participants", String.valueOf(match.getParticipants().size())) .addInlineField("Observers", String.valueOf(match.getDefaultParty().getPlayers().size())) .addInlineField("Staff", String.valueOf(bot.getOnlineStaffCount(match))) .setFooter("Map tags: " + map.getTags().toString()); bot.sendMatchEmbed(matchInfo, match); - // bot.sendMatchFinishEmbeds(matchInfo, teamStats, matchStats); } }