|
| 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