blob: fc30e3651a8f5652bdeac6f16c79ae3de4d54e7a (
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
68
69
70
71
72
73
74
|
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
class GardenWarpCommands {
private val config get() = GardenAPI.config.gardenCommands
private val tpPlotPattern by RepoPattern.pattern(
"garden.warpcommand.tpplot",
"/tp (?<plot>.*)"
)
private var lastWarpTime = SimpleTimeMark.farPast()
@SubscribeEvent
fun onMessageSendToServer(event: MessageSendToServerEvent) {
if (!config.warpCommands) return
if (!GardenAPI.inGarden()) return
val message = event.message.lowercase()
if (message == "/home") {
event.isCanceled = true
LorenzUtils.sendCommandToServer("warp garden")
ChatUtils.chat("§aTeleported you to the spawn location!", prefix = false)
}
if (message == "/barn") {
event.isCanceled = true
LorenzUtils.sendCommandToServer("tptoplot barn")
LockMouseLook.autoDisable()
}
tpPlotPattern.matchMatcher(event.message) {
event.isCanceled = true
val plotName = group("plot")
LorenzUtils.sendCommandToServer("tptoplot $plotName")
LockMouseLook.autoDisable()
}
}
@SubscribeEvent
fun onKeyClick(event: LorenzKeyPressEvent) {
if (!GardenAPI.inGarden()) return
if (Minecraft.getMinecraft().currentScreen != null) return
if (NEUItems.neuHasFocus()) return
val command = when (event.keyCode) {
config.homeHotkey -> "warp garden"
config.sethomeHotkey -> "sethome"
config.barnHotkey -> "tptoplot barn"
else -> return
}
if (lastWarpTime.passedSince() < 2.seconds) return
lastWarpTime = SimpleTimeMark.now()
if (command == "tptoplot barn") {
LockMouseLook.autoDisable()
}
LorenzUtils.sendCommandToServer(command)
}
}
|