Skip to content

Commit c12297d

Browse files
committed
/unmute-all command implemented.
`notifyAllAboutUnmuteAll` setting added into `mute` section. Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 49ff1e1 commit c12297d

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mairwunnx.projectessentials.chat
33
import com.mairwunnx.projectessentials.chat.api.MuteAPI
44
import com.mairwunnx.projectessentials.chat.commands.ClearChatCommand
55
import com.mairwunnx.projectessentials.chat.commands.MuteCommand
6+
import com.mairwunnx.projectessentials.chat.commands.UnmuteAllCommand
67
import com.mairwunnx.projectessentials.chat.commands.UnmuteCommand
78
import com.mairwunnx.projectessentials.chat.models.ChatModelUtils
89
import com.mairwunnx.projectessentials.core.EssBase
@@ -73,6 +74,7 @@ class EntryPoint : EssBase() {
7374
ClearChatCommand.register(it.commandDispatcher)
7475
MuteCommand.register(it.commandDispatcher)
7576
UnmuteCommand.register(it.commandDispatcher)
77+
UnmuteAllCommand.register(it.commandDispatcher)
7678
}
7779

7880
@Suppress("UNUSED_PARAMETER")
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.chat.models.ChatModelUtils
6+
import com.mairwunnx.projectessentials.core.extensions.isPlayerSender
7+
import com.mairwunnx.projectessentials.core.extensions.playerName
8+
import com.mairwunnx.projectessentials.core.extensions.sendMsg
9+
import com.mojang.brigadier.CommandDispatcher
10+
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
11+
import com.mojang.brigadier.context.CommandContext
12+
import net.minecraft.command.CommandSource
13+
import net.minecraft.util.text.TranslationTextComponent
14+
import org.apache.logging.log4j.LogManager
15+
16+
object UnmuteAllCommand {
17+
private val logger = LogManager.getLogger()
18+
19+
fun register(dispatcher: CommandDispatcher<CommandSource>) {
20+
logger.info("Register \"/unmute-all\" command")
21+
22+
dispatcher.register(
23+
literal<CommandSource>("unmute-all").executes(::execute)
24+
)
25+
}
26+
27+
private fun execute(
28+
context: CommandContext<CommandSource>
29+
): Int {
30+
if (context.isPlayerSender() && !EntryPoint.hasPermission(
31+
context.source.asPlayer(),
32+
"ess.chat.unmute.all",
33+
3
34+
)
35+
) {
36+
sendMsg("chat", context.source, "chat.unmute_all_restricted")
37+
return 0
38+
}
39+
40+
MuteAPI.unmuteAll()
41+
42+
if (ChatModelUtils.chatModel.mute.notifyAllAboutUnmuteAll) {
43+
context.source.server.playerList.sendMessage(
44+
TranslationTextComponent(
45+
"project_essentials_chat.notify_unmuted_all",
46+
context.playerName()
47+
)
48+
)
49+
}
50+
51+
sendMsg(
52+
"chat",
53+
context.source,
54+
"chat.unmute_all_success"
55+
)
56+
return 0
57+
}
58+
}

src/main/kotlin/com/mairwunnx/projectessentials/chat/models/ChatModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ data class ChatModel(
5454
var defaultReason: String = "Reason was not provided.",
5555
var ignoredPlayers: List<String> = listOf(),
5656
var notifyAllAboutMute: Boolean = true,
57-
var notifyAllAboutUnmute: Boolean = true
57+
var notifyAllAboutUnmute: Boolean = true,
58+
var notifyAllAboutUnmuteAll: Boolean = true
5859
)
5960
}

0 commit comments

Comments
 (0)