Skip to content

Commit

Permalink
Remove commented code & authors/pools/objective from finish
Browse files Browse the repository at this point in the history
  • Loading branch information
TBG1000 committed Jul 23, 2022
1 parent 8810f7d commit a7ce44a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 225 deletions.
75 changes: 0 additions & 75 deletions src/main/java/me/tbg/match/bot/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,58 +75,6 @@ public void sendMatchEmbed(EmbedBuilder embed, Match match) {
}
}

/*
public void sendMatchFinishEmbeds(
EmbedBuilder matchInfo, EmbedBuilder teamStats, EmbedBuilder matchStats) {
List<EmbedBuilder> 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);
Expand Down Expand Up @@ -204,21 +143,7 @@ public long getOnlineStaffCount(Match match) {
player -> (player.getBukkit().hasPermission(Permissions.STAFF) && !player.isVanished()))
.count();
}
/*
public Map.Entry<Map<UUID, String>, Integer> sortStats(Map<Map<UUID, String>, Integer> map) {
return map.entrySet().stream().max(Comparator.comparingInt(Map.Entry::getValue)).orElse(null);
}

public String getPlayerName(Map.Entry<Map<UUID, String>, ?> map) {
return map.getKey().entrySet().stream().map(Map.Entry::getValue).collect(Collectors.joining());
}
public Map.Entry<Map<UUID, String>, Double> sortStatsDouble(Map<Map<UUID, String>, Double> map) {
return map.entrySet().stream()
.max(Comparator.comparingDouble(Map.Entry::getValue))
.orElse(null);
}
*/
public void reload() {
if (this.api != null && !config.isEnabled()) {
disable();
Expand Down
150 changes: 0 additions & 150 deletions src/main/java/me/tbg/match/bot/MatchFinishListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,145 +29,6 @@ public void onMatchFinish(MatchFinishEvent event) {
ScoreMatchModule scoreModule = match.getModule(ScoreMatchModule.class);
TeamMatchModule teamModule = match.getModule(TeamMatchModule.class);
Collection<Competitor> teams = match.getCompetitors();
/*
StatsMatchModule statsModule = match.getModule(StatsMatchModule.class);
Map<UUID, String> matchPlayer = new HashMap<>();
Map<Map<UUID, String>, Integer> allKills = new HashMap<>();
Map<Map<UUID, String>, Integer> allStreaks = new HashMap<>();
Map<Map<UUID, String>, Integer> allDeaths = new HashMap<>();
Map<Map<UUID, String>, Integer> allShots = new HashMap<>();
Map<Map<UUID, String>, 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<Map<UUID, String>, Integer> highestKills = bot.sortStats(allKills);
Map.Entry<Map<UUID, String>, Integer> highestStreak = bot.sortStats(allStreaks);
Map.Entry<Map<UUID, String>, Integer> mostDeaths = bot.sortStats(allDeaths);
Map.Entry<Map<UUID, String>, Integer> longestShot = bot.sortStats(allShots);
Map.Entry<Map<UUID, String>, Double> highestDamage = bot.sortStatsDouble(allDamage);
EmbedBuilder matchStats =
new EmbedBuilder()
.setTitle("Match #" + match.getId() + " Stats")
.setColor(Color.BLACK)
.setDescription(
"Match ended at <t:"
+ Instant.now().getEpochSecond()
+ ":f> 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<String, Integer> 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<String, Integer> 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 <t:"
+ Instant.now().getEpochSecond()
+ ":f> 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()) {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit a7ce44a

Please sign in to comment.