|
1 | | -package com.mairwunnx.projectessentials.chat.commands |
2 | | - |
3 | | -import com.mairwunnx.projectessentials.chat.EntryPoint |
4 | | -import com.mairwunnx.projectessentials.chat.sendMessage |
5 | | -import com.mairwunnx.projectessentials.cooldown.essentials.CommandsAliases |
6 | | -import com.mairwunnx.projectessentials.core.extensions.isPlayerSender |
7 | | -import com.mairwunnx.projectessentials.core.extensions.playerName |
8 | | -import com.mairwunnx.projectessentials.core.helpers.throwPermissionLevel |
9 | | -import com.mojang.brigadier.CommandDispatcher |
10 | | -import com.mojang.brigadier.arguments.BoolArgumentType |
11 | | -import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal |
12 | | -import com.mojang.brigadier.context.CommandContext |
13 | | -import net.minecraft.client.Minecraft |
14 | | -import net.minecraft.command.CommandSource |
15 | | -import net.minecraft.command.Commands |
16 | | -import net.minecraft.util.text.TextComponentUtils |
17 | | -import net.minecraftforge.api.distmarker.Dist |
18 | | -import net.minecraftforge.fml.DistExecutor |
19 | | -import org.apache.logging.log4j.LogManager |
20 | | - |
21 | | -object ClearChatCommand { |
22 | | - private val logger = LogManager.getLogger() |
23 | | - private val aliases = listOf("clearchat", "chat-clear", "chatclear", "cc") |
24 | | - |
25 | | - fun register(dispatcher: CommandDispatcher<CommandSource>) { |
26 | | - logger.info("Register \"/clear-chat\" command") |
27 | | - applyAliases() |
28 | | - |
29 | | - val literalArgument = literal<CommandSource>("clear-chat").then( |
30 | | - Commands.argument( |
31 | | - "only for you", BoolArgumentType.bool() |
32 | | - ).executes { |
33 | | - return@executes execute(it, BoolArgumentType.getBool(it, "only for you")) |
34 | | - } |
35 | | - ) |
36 | | - |
37 | | - val literalNode = dispatcher.register(literalArgument.executes { |
38 | | - execute(it, false) |
39 | | - }) |
40 | | - |
41 | | - aliases.forEach { alias -> |
42 | | - dispatcher.register( |
43 | | - Commands.literal(alias).executes { ctx -> |
44 | | - execute(ctx, false) |
45 | | - }.redirect(literalNode) |
46 | | - ) |
47 | | - } |
48 | | - } |
49 | | - |
50 | | - private fun applyAliases() { |
51 | | - if (!EntryPoint.cooldownInstalled) return |
52 | | - CommandsAliases.aliases["clear-chat"] = aliases.toMutableList() |
53 | | - } |
54 | | - |
55 | | - private fun execute( |
56 | | - context: CommandContext<CommandSource>, |
57 | | - clearOnlyForSender: Boolean |
58 | | - ): Int { |
59 | | - if (clearOnlyForSender) { |
60 | | - if (context.isPlayerSender()) { |
61 | | - if (EntryPoint.hasPermission(context.source.asPlayer(), "ess.chat.clear", 2)) { |
62 | | - DistExecutor.runWhenOn(Dist.CLIENT) { |
63 | | - Runnable { |
64 | | - Minecraft.getInstance().ingameGUI.chatGUI.clearChatMessages(true) |
65 | | - } |
66 | | - } |
67 | | - } else { |
68 | | - throwPermissionLevel(context.playerName(), "clear-chat") |
69 | | - sendMessage(context.source, "chat.clear_restricted") |
70 | | - } |
71 | | - } else { |
72 | | - logger.info("Command with parameter `clearOnlyForSender` can't be executed from server. Type `cls` if you use windows or `/clear` if you use mac os or linux.") |
73 | | - } |
74 | | - } else { |
75 | | - if (!context.isPlayerSender() || EntryPoint.hasPermission( |
76 | | - context.source.asPlayer(), |
77 | | - "ess.chat.clear.other", |
78 | | - 3 |
79 | | - ) |
80 | | - ) { |
81 | | - val message = StringBuilder() |
82 | | - repeat(256) { |
83 | | - message.append("\n") |
84 | | - } |
85 | | - |
86 | | - context.source.server.playerList.sendMessage( |
87 | | - TextComponentUtils.toTextComponent { message.toString() } |
88 | | - ) |
89 | | - |
90 | | - if (context.isPlayerSender()) { |
91 | | - DistExecutor.runWhenOn(Dist.CLIENT) { |
92 | | - Runnable { |
93 | | - Minecraft.getInstance().ingameGUI.chatGUI.clearChatMessages(true) |
94 | | - } |
95 | | - } |
96 | | - } |
97 | | - } else { |
98 | | - sendMessage(context.source, "chat.clear_other_restricted") |
99 | | - return 0 |
100 | | - } |
101 | | - } |
102 | | - return 0 |
103 | | - } |
104 | | -} |
| 1 | +//package com.mairwunnx.projectessentials.chat.commands |
| 2 | +// |
| 3 | +//import com.mairwunnx.projectessentials.chat.EntryPoint |
| 4 | +//import com.mairwunnx.projectessentials.chat.sendMessage |
| 5 | +//import com.mairwunnx.projectessentials.cooldown.essentials.CommandsAliases |
| 6 | +//import com.mairwunnx.projectessentials.core.extensions.isPlayerSender |
| 7 | +//import com.mairwunnx.projectessentials.core.extensions.playerName |
| 8 | +//import com.mairwunnx.projectessentials.core.helpers.throwPermissionLevel |
| 9 | +//import com.mojang.brigadier.CommandDispatcher |
| 10 | +//import com.mojang.brigadier.arguments.BoolArgumentType |
| 11 | +//import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal |
| 12 | +//import com.mojang.brigadier.context.CommandContext |
| 13 | +//import net.minecraft.client.Minecraft |
| 14 | +//import net.minecraft.command.CommandSource |
| 15 | +//import net.minecraft.command.Commands |
| 16 | +//import net.minecraft.util.text.TextComponentUtils |
| 17 | +//import net.minecraftforge.api.distmarker.Dist |
| 18 | +//import net.minecraftforge.fml.DistExecutor |
| 19 | +//import org.apache.logging.log4j.LogManager |
| 20 | +// |
| 21 | +//object ClearChatCommand { |
| 22 | +// private val logger = LogManager.getLogger() |
| 23 | +// private val aliases = listOf("clearchat", "chat-clear", "chatclear", "cc") |
| 24 | +// |
| 25 | +// fun register(dispatcher: CommandDispatcher<CommandSource>) { |
| 26 | +// logger.info("Register \"/clear-chat\" command") |
| 27 | +// applyAliases() |
| 28 | +// |
| 29 | +// val literalArgument = literal<CommandSource>("clear-chat").then( |
| 30 | +// Commands.argument( |
| 31 | +// "only for you", BoolArgumentType.bool() |
| 32 | +// ).executes { |
| 33 | +// return@executes execute(it, BoolArgumentType.getBool(it, "only for you")) |
| 34 | +// } |
| 35 | +// ) |
| 36 | +// |
| 37 | +// val literalNode = dispatcher.register(literalArgument.executes { |
| 38 | +// execute(it, false) |
| 39 | +// }) |
| 40 | +// |
| 41 | +// aliases.forEach { alias -> |
| 42 | +// dispatcher.register( |
| 43 | +// Commands.literal(alias).executes { ctx -> |
| 44 | +// execute(ctx, false) |
| 45 | +// }.redirect(literalNode) |
| 46 | +// ) |
| 47 | +// } |
| 48 | +// } |
| 49 | +// |
| 50 | +// private fun applyAliases() { |
| 51 | +// if (!EntryPoint.cooldownInstalled) return |
| 52 | +// CommandsAliases.aliases["clear-chat"] = aliases.toMutableList() |
| 53 | +// } |
| 54 | +// |
| 55 | +// private fun execute( |
| 56 | +// context: CommandContext<CommandSource>, |
| 57 | +// clearOnlyForSender: Boolean |
| 58 | +// ): Int { |
| 59 | +// if (clearOnlyForSender) { |
| 60 | +// if (context.isPlayerSender()) { |
| 61 | +// if (EntryPoint.hasPermission(context.source.asPlayer(), "ess.chat.clear", 2)) { |
| 62 | +// DistExecutor.runWhenOn(Dist.CLIENT) { |
| 63 | +// Runnable { |
| 64 | +// Minecraft.getInstance().ingameGUI.chatGUI.clearChatMessages(true) |
| 65 | +// } |
| 66 | +// } |
| 67 | +// } else { |
| 68 | +// throwPermissionLevel(context.playerName(), "clear-chat") |
| 69 | +// sendMessage(context.source, "chat.clear_restricted") |
| 70 | +// } |
| 71 | +// } else { |
| 72 | +// logger.info("Command with parameter `clearOnlyForSender` can't be executed from server. Type `cls` if you use windows or `/clear` if you use mac os or linux.") |
| 73 | +// } |
| 74 | +// } else { |
| 75 | +// if (!context.isPlayerSender() || EntryPoint.hasPermission( |
| 76 | +// context.source.asPlayer(), |
| 77 | +// "ess.chat.clear.other", |
| 78 | +// 3 |
| 79 | +// ) |
| 80 | +// ) { |
| 81 | +// val message = StringBuilder() |
| 82 | +// repeat(256) { |
| 83 | +// message.append("\n") |
| 84 | +// } |
| 85 | +// |
| 86 | +// context.source.server.playerList.sendMessage( |
| 87 | +// TextComponentUtils.toTextComponent { message.toString() } |
| 88 | +// ) |
| 89 | +// |
| 90 | +// if (context.isPlayerSender()) { |
| 91 | +// DistExecutor.runWhenOn(Dist.CLIENT) { |
| 92 | +// Runnable { |
| 93 | +// Minecraft.getInstance().ingameGUI.chatGUI.clearChatMessages(true) |
| 94 | +// } |
| 95 | +// } |
| 96 | +// } |
| 97 | +// } else { |
| 98 | +// sendMessage(context.source, "chat.clear_other_restricted") |
| 99 | +// return 0 |
| 100 | +// } |
| 101 | +// } |
| 102 | +// return 0 |
| 103 | +// } |
| 104 | +//} |
0 commit comments