Skip to content

Commit a43ab81

Browse files
SychicMy-Name-Is-Jeff
authored andcommitted
chore: document namespaced commands
1 parent 7fd9fcf commit a43ab81

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/kotlin/gg/skytils/skytilsmod/features/impl/handlers/NamespacedCommands.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ import net.minecraftforge.client.ClientCommandHandler
3131
import net.minecraftforge.fml.common.Loader
3232
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
3333

34+
/**
35+
* Namespaced commands is a feature which generates namespaces for commands.
36+
*
37+
* For example, when a mod adds reparty, namespaced commands will generate
38+
* a command that includes the id/name of the mod
39+
*
40+
* `/mod:reparty`
41+
*
42+
* This is useful when multiple mods register a command with the same name
43+
*/
3444
object NamespacedCommands {
3545
val cch by lazy {
3646
ClientCommandHandler.instance as AccessorCommandHandler
@@ -61,6 +71,9 @@ object NamespacedCommands {
6171
}
6272
}
6373

74+
/**
75+
* This method takes a command and registers the command's namespaced version.
76+
*/
6477
fun registerCommandHelper(command: ICommand) {
6578
val owners = Loader.instance().modList.filter { command.javaClass.`package`.name in it.ownedPackages }
6679
if (owners.size != 1) {
@@ -77,6 +90,12 @@ object NamespacedCommands {
7790
aliasMap[command] = helper
7891
}
7992

93+
/**
94+
* Handles the actual sending of the command.
95+
*
96+
* When a command is sent using the `server` namespace, it is passed directly to the server
97+
* instead of running a client command.
98+
*/
8099
@SubscribeEvent
81100
fun onSendChat(event: SendChatMessageEvent) {
82101
if (event.message.startsWith("/server:")) {

0 commit comments

Comments
 (0)