Update vote-to-mute feature
The vote-to-mute feature is updated to include information about the vote initiating player. Also, the duration to retrieve chat logs increased from 5 minutes to 10 minutes. Lastly, eligible players are now notified live about the voting progress.
This commit is contained in:
parent
782c7df4ef
commit
8393d12c6d
|
|
@ -16,6 +16,7 @@ import com.velocitypowered.api.proxy.Player;
|
|||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import jdk.jshell.execution.Util;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
|
|
@ -29,6 +30,8 @@ import java.util.stream.IntStream;
|
|||
|
||||
public class VoteToMuteHelper {
|
||||
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
|
||||
public VoteToMuteHelper(ProxyServer proxyServer) {
|
||||
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
|
||||
.<CommandSource, String>argument("player", StringArgumentType.string())
|
||||
|
|
@ -162,7 +165,7 @@ public class VoteToMuteHelper {
|
|||
RegisteredServer server = currentServer.get().getServer();
|
||||
long count = getTotalEligiblePlayers(server, voteToMuteStarter.countLowerRanks());
|
||||
new ActiveVoteToMute(voteToMuteStarter.getVotedPlayer(), server, proxyServer, Duration.ofMinutes(5),
|
||||
(int) count, voteToMuteStarter.countLowerRanks(), chatLogs)
|
||||
(int) count, voteToMuteStarter.countLowerRanks(), chatLogs, player)
|
||||
.start();
|
||||
return 1;
|
||||
})
|
||||
|
|
@ -176,11 +179,11 @@ public class VoteToMuteHelper {
|
|||
.then(playerNode
|
||||
.then(yesNoNode
|
||||
.executes(commandContext -> {
|
||||
if (!(commandContext.getSource() instanceof Player)) {
|
||||
if (!(commandContext.getSource() instanceof Player player)) {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red>Only players are allowed to vote</red>"));
|
||||
return 1;
|
||||
}
|
||||
Player source = (Player) commandContext.getSource();
|
||||
String playerName = commandContext.getArgument("player", String.class);
|
||||
Optional<ActiveVoteToMute> optionalActiveVoteToMute = ActiveVoteToMute.getInstance(playerName);
|
||||
if (optionalActiveVoteToMute.isEmpty()) {
|
||||
|
|
@ -191,8 +194,8 @@ public class VoteToMuteHelper {
|
|||
ActiveVoteToMute activeVoteToMute = optionalActiveVoteToMute.get();
|
||||
|
||||
if (!activeVoteToMute.countLowerRanks()) {
|
||||
if (!source.hasPermission("chat.vote-to-mute")) {
|
||||
source.sendMessage(Utility.parseMiniMessage("<red>You are not eligible to vote.</red>"));
|
||||
if (!player.hasPermission("chat.vote-to-mute")) {
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>You are not eligible to vote.</red>"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -200,12 +203,13 @@ public class VoteToMuteHelper {
|
|||
String vote = commandContext.getArgument("yesNo", String.class);
|
||||
switch (vote.toLowerCase()) {
|
||||
case "yes" -> {
|
||||
activeVoteToMute.vote(source.getUniqueId(), true);
|
||||
activeVoteToMute.vote(player.getUniqueId(), true);
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<green>You voted to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||
player.getCurrentServer().ifPresent(serverConnection -> notifyEligiblePlayers(serverConnection.getServer(), activeVoteToMute));
|
||||
}
|
||||
case "no" -> {
|
||||
activeVoteToMute.vote(source.getUniqueId(), false);
|
||||
activeVoteToMute.vote(player.getUniqueId(), false);
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<green>You voted <red>not</red> to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||
}
|
||||
|
|
@ -249,6 +253,18 @@ public class VoteToMuteHelper {
|
|||
.count();
|
||||
}
|
||||
|
||||
private void notifyEligiblePlayers(RegisteredServer server, ActiveVoteToMute activeVoteToMute) {
|
||||
Component message = Utility.parseMiniMessage("<prefix><green><voted_for> out of <total_votes> players have voted to mute <player></green>",
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.parsed("voted_for", String.valueOf(activeVoteToMute.getVotedFor())),
|
||||
Placeholder.parsed("total_votes", String.valueOf(activeVoteToMute.getTotalEligibleVoters())),
|
||||
Placeholder.parsed("player", activeVoteToMute.getVotedPlayer().getUsername()));
|
||||
boolean countLowerRanks = activeVoteToMute.countLowerRanks();
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
}
|
||||
|
||||
private void sendHelpMessage(CommandSource commandSource) {
|
||||
commandSource.sendMessage(Utility.parseMiniMessage("<red>Use: <gold>/votetomutehelper <player></gold>.</red>"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ public class ActiveVoteToMute {
|
|||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
|
||||
private final Player votedPlayer;
|
||||
private final Player startedByPlayer;
|
||||
private HashSet<UUID> votedFor = new HashSet<>();
|
||||
private HashSet<UUID> votedAgainst = new HashSet<>();
|
||||
private int totalEligibleVoters;
|
||||
|
|
@ -74,7 +75,7 @@ public class ActiveVoteToMute {
|
|||
}
|
||||
|
||||
public ActiveVoteToMute(@NotNull Player votedPlayer, @NotNull RegisteredServer server, ProxyServer proxyServer, Duration duration,
|
||||
int totalEligibleVoters, boolean countLowerRanks, Component chatLogs) {
|
||||
int totalEligibleVoters, boolean countLowerRanks, Component chatLogs, @NotNull Player startedByPlayer) {
|
||||
this.chatLogs = chatLogs;
|
||||
this.votedPlayer = votedPlayer;
|
||||
this.totalEligibleVoters = totalEligibleVoters;
|
||||
|
|
@ -85,6 +86,7 @@ public class ActiveVoteToMute {
|
|||
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||
executorService.schedule(this::endVote,
|
||||
duration.toMinutes(), TimeUnit.MINUTES);
|
||||
this.startedByPlayer = startedByPlayer;
|
||||
}
|
||||
|
||||
private RegisteredServer getServer() {
|
||||
|
|
@ -151,7 +153,7 @@ public class ActiveVoteToMute {
|
|||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(),
|
||||
String.format("tempmute %s 1h Muted by the community - under review.", votedPlayer.getUsername()));
|
||||
String.format("tempmute %s 1h Muted by the community - under review. -p", votedPlayer.getUsername()));
|
||||
|
||||
|
||||
String chatLogsString = PlainTextComponentSerializer.plainText().serialize(chatLogs);
|
||||
|
|
@ -179,7 +181,10 @@ public class ActiveVoteToMute {
|
|||
false);
|
||||
embedBuilder.addField("Server",
|
||||
server.getServerInfo().getName().substring(0, 1).toUpperCase() + server.getServerInfo().getName().substring(1),
|
||||
false);
|
||||
true);
|
||||
embedBuilder.addField("Started by",
|
||||
String.format("Username: %s\nUUID: %s", startedByPlayer.getUsername(), startedByPlayer.getUniqueId().toString()),
|
||||
true);
|
||||
return embedBuilder;
|
||||
}
|
||||
|
||||
|
|
@ -218,4 +223,16 @@ public class ActiveVoteToMute {
|
|||
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||
Placeholder.component("logs", chatLogs));
|
||||
}
|
||||
|
||||
public Player getVotedPlayer() {
|
||||
return votedPlayer;
|
||||
}
|
||||
|
||||
public int getVotedFor() {
|
||||
return votedFor.size();
|
||||
}
|
||||
|
||||
public int getTotalEligibleVoters() {
|
||||
return totalEligibleVoters;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class VoteToMuteStarter {
|
|||
}
|
||||
|
||||
public void start() {
|
||||
chatLogHandler.retrieveChatLogs(votedPlayer.getUniqueId(), Duration.ofMinutes(5), serverName).whenCompleteAsync((chatLogs, throwable) -> {
|
||||
chatLogHandler.retrieveChatLogs(votedPlayer.getUniqueId(), Duration.ofMinutes(10), serverName).whenCompleteAsync((chatLogs, throwable) -> {
|
||||
if (throwable != null) {
|
||||
commandSource.sendMessage(Utility.parseMiniMessage("<prefix> <red>Unable to retrieve messages</red> for player <player>",
|
||||
Placeholder.component("prefix", prefix),
|
||||
|
|
@ -59,14 +59,15 @@ public class VoteToMuteStarter {
|
|||
|
||||
private void parseChatLogs(List<ChatLog> chatLogs) {
|
||||
TagResolver.Single playerTag = Placeholder.parsed("player", votedPlayer.getUsername());
|
||||
TagResolver.Single prefixTag = Placeholder.component("prefix", prefix);
|
||||
chatLogs.sort(Comparator.comparing(ChatLog::getTimestamp));
|
||||
parsedChatLogs = IntStream.range(0, chatLogs.size())
|
||||
.mapToObj(i -> Utility.parseMiniMessage(
|
||||
"<number>. [ChatLog] <player>: <message>",
|
||||
"<number>. <prefix> <player>: <message>",
|
||||
TagResolver.resolver(
|
||||
Placeholder.unparsed("message", chatLogs.get(i).getMessage()),
|
||||
Placeholder.parsed("number", String.valueOf(i + 1)),
|
||||
playerTag
|
||||
playerTag, prefixTag
|
||||
))
|
||||
)
|
||||
.toList();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user