From 782c7df4ef3104dcc77b311dc44dca3189bf0483 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Sun, 5 May 2024 15:42:59 +0200 Subject: [PATCH] Update vote to mute functionality in chat system Several changes were made to update the vote to mute functionality in the chat system. The threshold for eligible players online for vote has been changed from 10 to 6. In addition, improvements have been made to prevent the vote from ending prematurely. Lastly, feedback messages to users when they cast their vote and an update to the vote start message format have been implemented. --- .../alttd/velocitychat/commands/VoteToMute.java | 4 ++-- .../velocitychat/commands/VoteToMuteHelper.java | 16 ++++++++++++---- .../commands/vote_to_mute/ActiveVoteToMute.java | 6 +++++- .../commands/vote_to_mute/VoteToMuteStarter.java | 4 ++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMute.java b/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMute.java index 872ef0b..7a7e260 100644 --- a/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMute.java +++ b/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMute.java @@ -110,10 +110,10 @@ public class VoteToMute { } boolean countLowerRanks = false; long count = getTotalEligiblePlayers(server, false); - if (count < 10) { + if (count < 6) { countLowerRanks = true; count = getTotalEligiblePlayers(server, true); - if (count < 10) { + if (count < 6) { commandContext.getSource().sendMessage(Utility.parseMiniMessage("Not enough eligible players online to vote.")); return 1; } diff --git a/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMuteHelper.java b/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMuteHelper.java index 34effdc..0b26984 100644 --- a/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMuteHelper.java +++ b/velocity/src/main/java/com/alttd/velocitychat/commands/VoteToMuteHelper.java @@ -116,7 +116,7 @@ public class VoteToMuteHelper { return 1; }); - LiteralArgumentBuilder enterPageNode = LiteralArgumentBuilder + LiteralArgumentBuilder enterMessagesNode = LiteralArgumentBuilder .literal("messages") .requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute")) .then(RequiredArgumentBuilder.argument("list of messages", StringArgumentType.greedyString()) @@ -199,8 +199,16 @@ public class VoteToMuteHelper { String vote = commandContext.getArgument("yesNo", String.class); switch (vote.toLowerCase()) { - case "yes" -> activeVoteToMute.vote(source.getUniqueId(), true); - case "no" -> activeVoteToMute.vote(source.getUniqueId(), false); + case "yes" -> { + activeVoteToMute.vote(source.getUniqueId(), true); + commandContext.getSource().sendMessage(Utility.parseMiniMessage( + "You voted to mute. Thanks for voting, staff will be online soon to review!")); + } + case "no" -> { + activeVoteToMute.vote(source.getUniqueId(), false); + commandContext.getSource().sendMessage(Utility.parseMiniMessage( + "You voted not to mute. Thanks for voting, staff will be online soon to review!")); + } default -> commandContext.getSource().sendMessage(Utility.parseMiniMessage( " is not a valid vote option", Placeholder.parsed("vote", vote))); } @@ -219,7 +227,7 @@ public class VoteToMuteHelper { .requires(commandSource -> commandSource instanceof Player) .then(voteNode) .then(pageNode) - .then(enterPageNode) + .then(enterMessagesNode) .executes(context -> { sendHelpMessage(context.getSource()); return 1; diff --git a/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/ActiveVoteToMute.java b/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/ActiveVoteToMute.java index 4448a50..9d629f1 100644 --- a/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/ActiveVoteToMute.java +++ b/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/ActiveVoteToMute.java @@ -35,6 +35,7 @@ public class ActiveVoteToMute { private final RegisteredServer server; private final ProxyServer proxyServer; private final Component chatLogs; + private boolean endedVote = false; public static Optional getInstance(String username) { if (!instances.containsKey(username)) @@ -91,6 +92,8 @@ public class ActiveVoteToMute { } private void endVote() { + if (endedVote) + return; instances.remove(votedPlayer.getUsername()); if (votePassed()) { mutePlayer(); @@ -117,6 +120,7 @@ public class ActiveVoteToMute { if (!votePassed()) { return; } + endedVote = true; instances.remove(votedPlayer.getUsername()); mutePlayer(); } else { @@ -206,7 +210,7 @@ public class ActiveVoteToMute { private Component getVoteStartMessage() { return Utility.parseMiniMessage( String.format(""" - [VoteMute] A vote to mute for one hour has been started, please read the logs below before voting. + A vote to mute for one hour has been started, please read the logs below before voting. Click: Mute --- Don't mute""", votedPlayer.getUsername(), votedPlayer.getUsername()), diff --git a/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/VoteToMuteStarter.java b/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/VoteToMuteStarter.java index b08927e..66ea87e 100644 --- a/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/VoteToMuteStarter.java +++ b/velocity/src/main/java/com/alttd/velocitychat/commands/vote_to_mute/VoteToMuteStarter.java @@ -52,8 +52,8 @@ public class VoteToMuteStarter { parseChatLogs(chatLogs); commandSource.sendMessage(Utility.parseMiniMessage( " Please select up to 10 messages other players should see to decide their vote, seperated by comma's. " + - "Example: /votetomutehelper messages 1, 2, 5, 8")); - showPage(0); + "Example: /votetomutehelper messages 1, 2, 5, 8", Placeholder.component("prefix", prefix))); + showPage(1); }); }