Refine ChatPlugin and improve "vote to mute" logic
Modified ChatPlugin to include "thisPlugin" within the ShutdownListener initialization. Additionally, adjusted the mute vote failure message color from green to red in ActiveVoteToMute file and added a condition to return false if there are no votes. Also, made improvements to the pagination logic in the VoteToMuteStarter file. Lastly, improved the chat logging mechanics in ChatLogHandler by adding and refining various log information for capturing action details.
This commit is contained in:
+5
-3
@@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.awt.*;
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -97,7 +96,7 @@ public class ActiveVoteToMute {
|
||||
mutePlayer();
|
||||
return;
|
||||
}
|
||||
Component message = Utility.parseMiniMessage("<prefix> <red>The vote to mute <player> has failed, they will not be muted.</green>",
|
||||
Component message = Utility.parseMiniMessage("<prefix> <red>The vote to mute <player> has failed, they will not be muted.</red>",
|
||||
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
@@ -128,7 +127,10 @@ public class ActiveVoteToMute {
|
||||
|
||||
public boolean votePassed() {
|
||||
double totalVotes = (votedFor.size() + votedAgainst.size());
|
||||
if (totalVotes / totalEligibleVoters < 0.6) {
|
||||
if (totalVotes == 0) {
|
||||
return false;
|
||||
}
|
||||
if (totalVotes / totalEligibleVoters < 0.6) {
|
||||
return false;
|
||||
}
|
||||
return votedFor.size() / totalVotes > 0.6;
|
||||
|
||||
+5
-5
@@ -73,19 +73,19 @@ public class VoteToMuteStarter {
|
||||
}
|
||||
|
||||
public void showPage(int page) {
|
||||
List<Component> collect = parsedChatLogs.stream().skip(page * 10L).limit(page).toList();
|
||||
List<Component> collect = parsedChatLogs.stream().skip((page - 1) * 10L).limit(10L).toList();
|
||||
Component chatLogsComponent = Component.join(JoinConfiguration.newlines(), collect);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<prefix> ChatLogs for <player>\n<logs>\n");
|
||||
if (page != 0) {
|
||||
stringBuilder.append("<click:run_command:/votetomute page ")
|
||||
if (page > 1) {
|
||||
stringBuilder.append("<click:run_command:/votetomutehelper page ")
|
||||
.append(page - 1)
|
||||
.append("><hover:show_text:'<gold>Click to go to previous page'><gold><previous page></gold></hover></click> ");
|
||||
}
|
||||
if (parsedChatLogs.size() > page * 10) {
|
||||
stringBuilder.append("<click:run_command:/votetomute page ")
|
||||
stringBuilder.append("<click:run_command:/votetomutehelper page ")
|
||||
.append(page + 1)
|
||||
.append("><hover:show_text:'<gold>Click to go to next page'><gold><previous page></gold></hover></click> ");
|
||||
.append("><hover:show_text:'<gold>Click to go to next page'><gold><next page></gold></hover></click> ");
|
||||
}
|
||||
commandSource.sendMessage(Utility.parseMiniMessage(stringBuilder.toString(),
|
||||
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||
|
||||
Reference in New Issue
Block a user