From 6c2463f9637dcab8bdfd5918c25bcb89e1a22e75 Mon Sep 17 00:00:00 2001 From: Pablete1234 Date: Fri, 22 Apr 2022 07:43:09 +0200 Subject: [PATCH] Display shared cores & destroyables as shared Signed-off-by: Pablete1234 --- .../java/tc/oc/pgm/command/MatchCommand.java | 95 +++++++++++-------- core/src/main/java/tc/oc/pgm/core/Core.java | 4 +- .../tc/oc/pgm/destroyable/Destroyable.java | 6 +- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/core/src/main/java/tc/oc/pgm/command/MatchCommand.java b/core/src/main/java/tc/oc/pgm/command/MatchCommand.java index 9485b3c10a..aa9760d9d1 100644 --- a/core/src/main/java/tc/oc/pgm/command/MatchCommand.java +++ b/core/src/main/java/tc/oc/pgm/command/MatchCommand.java @@ -7,16 +7,18 @@ import static tc.oc.pgm.util.text.TemporalComponent.clock; import app.ashcon.intake.Command; -import com.google.common.collect.HashMultimap; +import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; +import net.md_5.bungee.api.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import tc.oc.pgm.api.match.Match; @@ -114,52 +116,57 @@ public void match(Audience viewer, CommandSender sender, Match match) { viewer.sendMessage(join(text(" | ", NamedTextColor.DARK_GRAY), teamCountParts)); + if (!haveGameInfo) return; + GoalMatchModule gmm = match.getModule(GoalMatchModule.class); - if (haveGameInfo && gmm != null) { - if (tmm != null && gmm.getGoalsByCompetitor().size() > 0) { - Multimap teamGoalTexts = HashMultimap.create(); - - MatchPlayer player = getMatchPlayer(sender, match); - - for (Team team : tmm.getParticipatingTeams()) { - for (Goal goal : gmm.getGoals(team)) { - if (goal.isVisible()) { - if (player != null) { - teamGoalTexts.put( - team, renderGoal(goal, player.getCompetitor(), player.getParty())); - } else { - teamGoalTexts.put(team, renderGoal(goal, null, match.getDefaultParty())); - } + if (gmm != null && tmm != null && gmm.getGoalsByCompetitor().size() > 0) { + Multimap teamGoalTexts = LinkedHashMultimap.create(); + Map, Component> sharedGoalTexts = new LinkedHashMap<>(); + + MatchPlayer player = getMatchPlayer(sender, match); + Party viewingParty = player == null ? match.getDefaultParty() : player.getParty(); + + for (Team team : tmm.getParticipatingTeams()) { + for (Goal goal : gmm.getGoals(team)) { + if (goal.isVisible()) { + if (goal.isShared()) { + sharedGoalTexts.computeIfAbsent(goal, g -> renderGoal(g, null, viewingParty)); + } else if (player != null) { + teamGoalTexts.put(team, renderGoal(goal, player.getCompetitor(), viewingParty)); + } else { + teamGoalTexts.put(team, renderGoal(goal, null, viewingParty)); } } } + } + + if (!teamGoalTexts.isEmpty() || !sharedGoalTexts.isEmpty()) { + viewer.sendMessage( + translatable("match.info.goals").append(text(":")).color(NamedTextColor.DARK_PURPLE)); + + // Team goals + for (Map.Entry> entry : teamGoalTexts.asMap().entrySet()) { + Team team = entry.getKey(); + Collection goalTexts = entry.getValue(); - if (!teamGoalTexts.isEmpty()) { viewer.sendMessage( - translatable("match.info.goals").append(text(":")).color(NamedTextColor.DARK_PURPLE)); - - for (Map.Entry> entry : teamGoalTexts.asMap().entrySet()) { - Team team = entry.getKey(); - Collection goalTexts = entry.getValue(); - - viewer.sendMessage( - text() - .append(space()) - .append(space()) - .append(team.getName()) - .append(text(": ", NamedTextColor.GRAY)) - .append(join(text(" "), goalTexts)) - .build()); - } - } - } else { - // FIXME: this is not the best way to handle scores - ScoreMatchModule smm = match.getModule(ScoreMatchModule.class); - if (smm != null) { - viewer.sendMessage(smm.getStatusMessage(getMatchPlayer(sender, match))); + text() + .append(space()) + .append(space()) + .append(team.getName()) + .append(text(": ", NamedTextColor.GRAY)) + .append(join(text(" "), goalTexts)) + .build()); } + // Shared goals + viewer.sendMessage(join(text(" "), sharedGoalTexts.values())); } } + + ScoreMatchModule smm = match.getModule(ScoreMatchModule.class); + if (smm != null) { + viewer.sendMessage(smm.getStatusMessage(getMatchPlayer(sender, match))); + } } private MatchPlayer getMatchPlayer(CommandSender sender, Match match) { @@ -176,13 +183,17 @@ private static Component renderGoal( goal.renderSidebarStatusText(competitor, viewingParty), TextFormatter.convert(goal.renderSidebarStatusColor(competitor, viewingParty)))); + sb.append(space()); if (goal instanceof ProximityGoal) { - sb.append(space()); - // Show teams their own proximity on shared goals - sb.append(text(((ProximityGoal) goal).renderProximity(competitor, viewingParty))); + ProximityGoal proxGoal = (ProximityGoal) goal; + String proximityText = proxGoal.renderProximity(competitor, viewingParty); + if (proximityText != null && !proximityText.isEmpty()) { + ChatColor proximityColor = proxGoal.renderProximityColor(competitor, viewingParty); + sb.append(text(proximityText, TextFormatter.convert(proximityColor))); + sb.append(space()); + } } - sb.append(space()); sb.append( goal.renderSidebarLabelText(competitor, viewingParty) .color(TextFormatter.convert(goal.renderSidebarLabelColor(competitor, viewingParty)))); diff --git a/core/src/main/java/tc/oc/pgm/core/Core.java b/core/src/main/java/tc/oc/pgm/core/Core.java index 74b47c83cd..17df539b3a 100644 --- a/core/src/main/java/tc/oc/pgm/core/Core.java +++ b/core/src/main/java/tc/oc/pgm/core/Core.java @@ -45,6 +45,7 @@ public class Core extends TouchableGoal protected final FiniteBlockRegion lavaRegion; protected final Region leakRegion; protected final int leakRequired; + protected final boolean isShared; protected MaterialData material; protected int leak = 0; @@ -88,6 +89,7 @@ public Core(CoreFactory definition, Match match) { this.leakRegion = new CuboidRegion(min, max); this.leakRequired = lavaRegion.getBounds().getMin().getBlockY() - max.getBlockY() + 1; + this.isShared = match.getCompetitors().stream().filter(this::canComplete).count() != 1; } // Remove @Nullable @@ -172,7 +174,7 @@ public boolean hasLeaked() { @Override public boolean isShared() { - return false; + return isShared; } @Override diff --git a/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java b/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java index 17f5738d7e..f211fd49eb 100644 --- a/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java +++ b/core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java @@ -67,6 +67,7 @@ public class Destroyable extends TouchableGoal protected final FiniteBlockRegion blockRegion; protected final Set materialPatterns = new HashSet<>(); protected final Set materials = new HashSet<>(); + protected final boolean isShared; // The percentage of blocks that must be broken for the entire Destroyable to be destroyed. protected double destructionRequired; @@ -127,6 +128,7 @@ public Destroyable(DestroyableFactory definition, Match match) { } this.recalculateHealth(); + this.isShared = match.getCompetitors().stream().filter(this::canComplete).count() != 1; } // Remove @Nullable @@ -517,7 +519,7 @@ public String renderPreciseCompletion() { @Override public String renderSidebarStatusText(@Nullable Competitor competitor, Party viewer) { - if (this.getShowProgress() || viewer.isObserving()) { + if (this.getShowProgress() || (viewer.isObserving() && this.getBreaksRequired() > 1)) { String text = this.renderCompletion(); if (PGM.get().getConfiguration().showProximity()) { String precise = this.renderPreciseCompletion(); @@ -542,7 +544,7 @@ public boolean isDestroyed() { @Override public boolean isShared() { - return false; + return isShared; } @Override