Skip to content

Commit

Permalink
Allow teammates to see vetoes
Browse files Browse the repository at this point in the history
  • Loading branch information
dentmaged committed Jan 5, 2022
1 parent b5705b1 commit 5e66350
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/main/java/rip/bolt/nerve/match/listeners/VetoManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,18 @@ public void vetoMap(Player player, Match match, String query) {

BoltResponse response = api.veto(match, player.getUniqueId(), new Veto(found));
if (response.isSuccess()) {
player.sendMessage(Messages.vetoed(found, vetoed.contains(player.getUniqueId())));
player.sendMessage(Messages.vetoed(found, null, vetoed.contains(player.getUniqueId())));
for (User user : match.getPlayerTeam(player).getPlayers()) {
if (user.getUniqueId().equals(player.getUniqueId()))
continue;

Optional<Player> viewer = server.getPlayer(user.getUniqueId());
if (!viewer.isPresent())
continue;

viewer.get().sendMessage(Messages.vetoed(found, player.getUsername(), vetoed.contains(player.getUniqueId())));
}

vetoed.add(player.getUniqueId());
} else {
player.sendMessage(Component.text(response.getError()).color(NamedTextColor.RED));
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/rip/bolt/nerve/utils/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.List;

import javax.annotation.Nullable;
import javax.inject.Inject;

import net.kyori.adventure.text.Component;
Expand All @@ -24,7 +25,8 @@ public class Messages {
public static final TextComponent PREFIX = text().append(colour(NamedTextColor.DARK_GRAY, "[")).append(bold(colour(NamedTextColor.YELLOW, "\u26A1")), colour(NamedTextColor.DARK_GRAY, "]")).append(colour(NamedTextColor.WHITE, " ")).build();
public static final TextComponent DASH = colour(NamedTextColor.DARK_GRAY, " - ");

@Inject private static PrivateServerConfig privateServerConfig;
@Inject
private static PrivateServerConfig privateServerConfig;

public static TextComponent privateServerStarted(String server) {
return text().append(PREFIX).append(colour(NamedTextColor.GREEN, "Your private server has started up! Run ")).append(command(NamedTextColor.YELLOW, "server", server)).append(colour(NamedTextColor.GREEN, " to connect.")).build();
Expand Down Expand Up @@ -64,8 +66,27 @@ public static TextComponent mapNotFound(String map) {
return text().append(colour(NamedTextColor.RED, "Map ")).append(colour(NamedTextColor.RED, map)).append(colour(NamedTextColor.RED, " not found.")).build();
}

public static TextComponent vetoed(String map, boolean vetoedBefore) {
return text().append(PREFIX).append(colour(NamedTextColor.GOLD, vetoedBefore ? "You have changed your veto to " : "You have vetoed ")).append(colour(NamedTextColor.YELLOW, map)).append(colour(NamedTextColor.GOLD, "!")).build();
public static TextComponent vetoed(String map, @Nullable String teammateName, boolean vetoedBefore) {
TextComponent.Builder builder = text().append(PREFIX);

String displayName = teammateName;
String verb = "has";
String determiner = "their";

if (teammateName == null) {
displayName = "You";
verb = "have";
determiner = "your";
}

String sentence;
if (vetoedBefore)
sentence = String.format(" %s changed %s veto to ", verb, determiner);
else
sentence = String.format(" %s veteoed ", verb);

builder.append(colour(NamedTextColor.YELLOW, displayName)).append(colour(NamedTextColor.GOLD, sentence));
return builder.append(colour(NamedTextColor.YELLOW, map)).append(colour(NamedTextColor.GOLD, "!")).build();
}

public static TextComponent mapDecided(String map) {
Expand Down

0 comments on commit 5e66350

Please sign in to comment.