summaryrefslogtreecommitdiff
path: root/src/main/kotlin/commands/Commands.kt
blob: de6ded34611ed6e21d17e1df0e592de0a5d89878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package moe.nea.ultranotifier.commands

import com.mojang.brigadier.builder.LiteralArgumentBuilder
import moe.nea.ultranotifier.UltraNotifier
import moe.nea.ultranotifier.event.CommandRegistrationEvent
import moe.nea.ultranotifier.event.SubscriptionTarget
import moe.nea.ultranotifier.event.UltraNotifierEvents
import moe.nea.ultranotifier.event.UltraSubscribe
import net.minecraft.text.Text

interface CustomSource {
	fun sendFeedback(text: Text)
}


typealias UltraCommandSource =
//#if FORGE
//$$	CustomSource
//#elseif MC > 1.18
	net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource
//#else
//$$    net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource
//#endif


fun translatableText(key: String, vararg args: String) =
//#if MC > 1.17
	Text.translatable(key, *args)
//#else
//$$	net.minecraft.text.TranslatableText(key, *args)
//#endif

fun literalText(string: String): Text =
//#if MC > 1.17
	Text.literal(string)
//#else
//$$	net.minecraft.text.LiteralText(string)
//#endif

object Commands : SubscriptionTarget {
	@UltraSubscribe
	fun registerTestCommand(event: CommandRegistrationEvent) {
		event.dispatcher.register(LiteralArgumentBuilder.literal<UltraCommandSource>("hello")
			                          .executes {
				                          it.source.sendFeedback(literalText("Hello World"))
				                          0
			                          })
	}

//#if MC <= 1.18 && FABRIC
//$$	@UltraSubscribe
//$$	fun registerEverythingOnce(event: moe.nea.ultranotifier.event.RegistrationFinishedEvent) {
//$$		CommandRegistrationEvent(net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.DISPATCHER).post()
//$$	}
//#endif

	override fun init() {
//#if FORGE
//$$		UltraNotifierEvents.register(BrigadierPatchbay)
//#elseif MC > 1.18
		net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback.EVENT.register { dispatcher, registryAccess ->
			UltraNotifierEvents.post(CommandRegistrationEvent(dispatcher))
		}
//#endif
		UltraNotifier.logger.info("Initialized command subsystem")
	}
}