Skip to content

Commit 6bccdb4

Browse files
committed
/muted-players command implemented.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent c12297d commit 6bccdb4

2 files changed

Lines changed: 71 additions & 4 deletions

File tree

src/main/kotlin/com/mairwunnx/projectessentials/chat/EntryPoint.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.mairwunnx.projectessentials.chat
22

33
import com.mairwunnx.projectessentials.chat.api.MuteAPI
4-
import com.mairwunnx.projectessentials.chat.commands.ClearChatCommand
5-
import com.mairwunnx.projectessentials.chat.commands.MuteCommand
6-
import com.mairwunnx.projectessentials.chat.commands.UnmuteAllCommand
7-
import com.mairwunnx.projectessentials.chat.commands.UnmuteCommand
4+
import com.mairwunnx.projectessentials.chat.commands.*
85
import com.mairwunnx.projectessentials.chat.models.ChatModelUtils
96
import com.mairwunnx.projectessentials.core.EssBase
107
import com.mairwunnx.projectessentials.core.extensions.empty
@@ -75,6 +72,7 @@ class EntryPoint : EssBase() {
7572
MuteCommand.register(it.commandDispatcher)
7673
UnmuteCommand.register(it.commandDispatcher)
7774
UnmuteAllCommand.register(it.commandDispatcher)
75+
MutedPlayersCommand.register(it.commandDispatcher)
7876
}
7977

8078
@Suppress("UNUSED_PARAMETER")
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.mairwunnx.projectessentials.chat.commands
2+
3+
import com.mairwunnx.projectessentials.chat.EntryPoint
4+
import com.mairwunnx.projectessentials.chat.api.MuteAPI
5+
import com.mairwunnx.projectessentials.core.extensions.isPlayerSender
6+
import com.mairwunnx.projectessentials.core.extensions.sendMsg
7+
import com.mojang.brigadier.CommandDispatcher
8+
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
9+
import com.mojang.brigadier.context.CommandContext
10+
import net.minecraft.command.CommandSource
11+
import net.minecraft.util.text.TextComponentUtils
12+
import net.minecraft.util.text.TranslationTextComponent
13+
import org.apache.logging.log4j.LogManager
14+
15+
object MutedPlayersCommand {
16+
private val logger = LogManager.getLogger()
17+
private val locMessageMutedPlayer = TranslationTextComponent(
18+
"project_essentials_chat.chat.out_muted_players"
19+
).formattedText
20+
private val locMessageMutedBy = TranslationTextComponent(
21+
"project_essentials_chat.chat.out_muted_by"
22+
).formattedText
23+
private val locMessageReason = TranslationTextComponent(
24+
"project_essentials_chat.chat.out_reason"
25+
).formattedText
26+
27+
fun register(dispatcher: CommandDispatcher<CommandSource>) {
28+
logger.info("Register \"/muted-players\" command")
29+
30+
dispatcher.register(
31+
literal<CommandSource>("muted-players").executes(::execute)
32+
)
33+
}
34+
35+
private fun execute(
36+
context: CommandContext<CommandSource>
37+
): Int {
38+
if (context.isPlayerSender() && !EntryPoint.hasPermission(
39+
context.source.asPlayer(),
40+
"ess.chat.muted",
41+
3
42+
)
43+
) {
44+
sendMsg("chat", context.source, "chat.muted_restricted")
45+
return 0
46+
}
47+
48+
val mutedPlayers = MuteAPI.getMutedPlayers()
49+
val message = buildString {
50+
this.append("§7$locMessageMutedPlayer:\n")
51+
mutedPlayers.forEach {
52+
val mutedBy = MuteAPI.getMuteInitiator(it)!!
53+
val reason = MuteAPI.getMuteReason(it)!!
54+
55+
this.append(
56+
"§7- §c$it§7, $locMessageMutedBy §c$mutedBy§7, $locMessageReason: §c$reason"
57+
)
58+
}
59+
}
60+
61+
context.source.sendFeedback(
62+
TextComponentUtils.toTextComponent {
63+
message
64+
}, false
65+
)
66+
67+
return 0
68+
}
69+
}

0 commit comments

Comments
 (0)