|
| 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 | +} |
0 commit comments