diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index c86dd3688..9e8fc6b8e 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.MayorElection import at.hannibal2.skyhanni.data.TitleManager +import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.features.dungeon.DungeonAPI import at.hannibal2.skyhanni.mixins.transformers.AccessorGuiEditSign import at.hannibal2.skyhanni.test.TestBingo @@ -26,6 +27,7 @@ import net.minecraft.event.HoverEvent import net.minecraft.launchwrapper.Launch import net.minecraft.util.ChatComponentText import net.minecraftforge.fml.common.FMLCommonHandler +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import java.awt.Color import java.lang.reflect.Constructor import java.lang.reflect.Field @@ -34,6 +36,8 @@ import java.text.DecimalFormat import java.text.NumberFormat import java.text.SimpleDateFormat import java.util.Collections +import java.util.LinkedList +import java.util.Queue import java.util.Timer import java.util.TimerTask import java.util.WeakHashMap @@ -48,6 +52,7 @@ import kotlin.reflect.full.memberProperties import kotlin.reflect.full.starProjectedType import kotlin.reflect.jvm.isAccessible import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds object LorenzUtils { @@ -371,18 +376,28 @@ object LorenzUtils { return this } - private var lastMessageSent = 0L + private var lastMessageSent = SimpleTimeMark.farPast() + private val sendQueue: Queue<String> = LinkedList() + + @SubscribeEvent + fun sendQueuedChatMessages(event: LorenzTickEvent) { + val player = Minecraft.getMinecraft().thePlayer + if (player == null) { + sendQueue.clear() + return + } + if (lastMessageSent.passedSince() > 300.milliseconds) { + player.sendChatMessage(sendQueue.poll() ?: return) + lastMessageSent = SimpleTimeMark.now() + } + } fun sendCommandToServer(command: String) { sendMessageToServer("/$command") } fun sendMessageToServer(message: String) { - if (System.currentTimeMillis() > lastMessageSent + 1_000) { - lastMessageSent = System.currentTimeMillis() - val thePlayer = Minecraft.getMinecraft().thePlayer - thePlayer.sendChatMessage(message) - } + sendQueue.add(message) } // MoulConfig is in Java, I don't want to downgrade this logic |