Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement notifications HUD #488

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.lambda.client.commons.interfaces.DisplayEnum
import com.lambda.client.commons.interfaces.Nameable
import com.lambda.client.event.LambdaEventBus
import com.lambda.client.gui.rgui.windows.BasicWindow
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.modules.client.GuiColors
import com.lambda.client.module.modules.client.Hud
import com.lambda.client.setting.GuiConfig
Expand All @@ -16,7 +17,6 @@ import com.lambda.client.util.graphics.VertexHelper
import com.lambda.client.util.graphics.font.FontRenderAdapter
import com.lambda.client.util.math.Vec2d
import com.lambda.client.util.math.Vec2f
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.threads.safeListener
import net.minecraftforge.fml.common.gameevent.TickEvent
import org.lwjgl.opengl.GL11.glScalef
Expand Down Expand Up @@ -97,7 +97,7 @@ abstract class AbstractHudElement(
if (it) {
settingList.filter { it != visibleSetting && it != default }.forEach { it.resetValue() }
default.value = false
MessageSendHelper.sendChatMessage("$name Set to defaults!")
NotificationManager.registerNotification("$name Set to defaults!")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package com.lambda.client.manager.managers

import com.lambda.client.manager.Manager
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.module.modules.client.Notifications
import com.lambda.client.util.notifications.Notification
import com.lambda.client.util.notifications.NotificationType
import com.lambda.client.util.threads.safeListener
import net.minecraftforge.fml.common.gameevent.TickEvent
import java.util.*

object NotificationManager : Manager {
private val pendingNotifications: Queue<String> = LinkedList()
private val pendingNotifications: Queue<Notification> = LinkedList()

init {
safeListener<TickEvent.ClientTickEvent> {
while (pendingNotifications.isNotEmpty()) {
MessageSendHelper.sendErrorMessage(pendingNotifications.poll())
val notification = pendingNotifications.poll()
Notifications.addNotification(notification)
}
}
}

fun registerNotification(message: String) {
pendingNotifications.add(message)
pendingNotifications.add(Notification(message, NotificationType.INFO))
}

fun registerNotification(message: String, type: NotificationType) {
pendingNotifications.add(Notification(message, type))
}
}
9 changes: 7 additions & 2 deletions src/main/kotlin/com/lambda/client/module/AbstractModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.lambda.client.commons.interfaces.Nameable
import com.lambda.client.event.LambdaEventBus
import com.lambda.client.event.events.ModuleToggleEvent
import com.lambda.client.gui.clickgui.LambdaClickGui
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.modules.client.ClickGUI
import com.lambda.client.setting.configs.NameableConfig
import com.lambda.client.setting.settings.AbstractSetting
Expand All @@ -13,7 +14,7 @@ import com.lambda.client.setting.settings.impl.number.IntegerSetting
import com.lambda.client.setting.settings.impl.other.BindSetting
import com.lambda.client.setting.settings.impl.primitive.BooleanSetting
import com.lambda.client.util.Bind
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.notifications.NotificationType
import net.minecraft.client.Minecraft

@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -59,6 +60,10 @@ abstract class AbstractModule(
enabled.value = !enabled.value
isPaused = false
if (enabled.value) clicks.value++

if (this.category != Category.CLIENT) {
NotificationManager.registerNotification("$name ${if (enabled.value) "Enabled" else "Disabled"}", NotificationType.INFO)
}
}

fun enable() {
Expand Down Expand Up @@ -131,7 +136,7 @@ abstract class AbstractModule(
if (it) {
settingList.forEach { it.resetValue() }
default.value = false
MessageSendHelper.sendChatMessage("$chatName Set to defaults!")
NotificationManager.registerNotification("$chatName Set to defaults!")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.lambda.client.LambdaMod
import com.lambda.client.commons.extension.synchronized
import com.lambda.client.event.SafeClientEvent
import com.lambda.client.event.events.PacketEvent
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.FolderUtils
Expand Down Expand Up @@ -115,7 +116,7 @@ object AutoExcuse : Module(

try {
file.forEachLine { if (it.isNotBlank()) loadedExcuses.add(it.trim()) }
MessageSendHelper.sendChatMessage("$chatName Loaded excuse messages!")
NotificationManager.registerNotification("$chatName Loaded excuse messages!")
} catch (e: Exception) {
MessageSendHelper.sendErrorMessage("$chatName Failed loading excuses, $e")
disable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.lambda.client.module.modules.chat

import com.lambda.client.event.listener.listener
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.notifications.NotificationType
import com.lambda.client.util.text.MessageDetection
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.text.formatValue
Expand All @@ -26,7 +28,7 @@ object ChatFilter : Module(
init {
onEnable {
try {
MessageSendHelper.sendChatMessage("$chatName Trying to find '&7chat_filter.txt&f'")
NotificationManager.registerNotification("$chatName Trying to find '&7chat_filter.txt&f'")
chatFilter.clear()

file.bufferedReader().forEachLine {
Expand All @@ -41,9 +43,9 @@ object ChatFilter : Module(
}
}

MessageSendHelper.sendChatMessage("$chatName Loaded '&7chat_filter.txt&f'!")
NotificationManager.registerNotification("$chatName Loaded '&7chat_filter.txt&f'!")
} catch (exception: FileNotFoundException) {
MessageSendHelper.sendErrorMessage("$chatName Couldn't find a file called '&7chat_filter.txt&f' inside your '&7.minecraft/lambda&f' folder, disabling")
NotificationManager.registerNotification("$chatName Couldn't find a file called '&7chat_filter.txt&f' inside your '&7.minecraft/lambda&f' folder, disabling", NotificationType.ERROR)
disable()
} catch (exception: Exception) {
MessageSendHelper.sendErrorMessage(exception.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.lambda.client.module.modules.chat

import com.lambda.client.event.events.ConnectionEvent
import com.lambda.client.event.listener.listener
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.MovementUtils.isMoving
import com.lambda.client.util.notifications.NotificationType
import com.lambda.client.util.text.MessageDetection
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
Expand Down Expand Up @@ -39,9 +41,10 @@ object LoginMessage : Module(
file.forEachLine {
if (it.isNotBlank()) loginMessages.add(it.trim())
}
MessageSendHelper.sendChatMessage("$chatName Loaded ${loginMessages.size} login messages!")
NotificationManager.registerNotification("$chatName Loaded ${loginMessages.size} login messages!")
} catch (e: Exception) {
MessageSendHelper.sendErrorMessage("$chatName Failed loading login messages, $e")
NotificationManager.registerNotification("$chatName Failed loading login messages, $e",
NotificationType.ERROR)
disable()
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/com/lambda/client/module/modules/chat/Spammer.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.lambda.client.module.modules.chat

import com.lambda.client.commons.extension.synchronized
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.FolderUtils
import com.lambda.client.util.TickTimer
import com.lambda.client.util.TimeUnit
import com.lambda.client.util.notifications.NotificationType
import com.lambda.client.util.text.MessageDetection
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.text.MessageSendHelper.sendServerMessage
Expand Down Expand Up @@ -59,9 +61,10 @@ object Spammer : Module(
val text = URL(url).readText()
spammer.addAll(text.split("\n"))

MessageSendHelper.sendChatMessage("$chatName Loaded remote spammer messages!")
NotificationManager.registerNotification("$chatName Loaded remote spammer messages!")
} catch (e: Exception) {
MessageSendHelper.sendErrorMessage("$chatName Failed loading remote spammer, $e")
NotificationManager.registerNotification("$chatName Failed loading remote spammer, $e",
NotificationType.ERROR)
disable()
}
}
Expand All @@ -71,9 +74,10 @@ object Spammer : Module(
if (file.exists()) {
try {
file.forEachLine { if (it.isNotBlank()) spammer.add(it.trim()) }
MessageSendHelper.sendChatMessage("$chatName Loaded spammer messages!")
NotificationManager.registerNotification("$chatName Loaded spammer messages!")
} catch (e: Exception) {
MessageSendHelper.sendErrorMessage("$chatName Failed loading spammer, $e")
NotificationManager.registerNotification("$chatName Failed loading remote spammer, $e",
NotificationType.ERROR)
disable()
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.lambda.client.commons.interfaces.DisplayEnum
import com.lambda.client.event.events.ConnectionEvent
import com.lambda.client.event.listener.listener
import com.lambda.client.gui.AbstractLambdaGui
import com.lambda.client.manager.managers.NotificationManager
import com.lambda.client.module.AbstractModule
import com.lambda.client.module.Category
import com.lambda.client.setting.ConfigManager
Expand All @@ -17,6 +18,7 @@ import com.lambda.client.setting.settings.impl.primitive.StringSetting
import com.lambda.client.util.ConfigUtils
import com.lambda.client.util.TickTimer
import com.lambda.client.util.TimeUnit
import com.lambda.client.util.notifications.NotificationType
import com.lambda.client.util.text.MessageSendHelper
import com.lambda.client.util.text.formatValue
import com.lambda.client.util.threads.BackgroundScope
Expand Down Expand Up @@ -55,7 +57,7 @@ internal object Configurations : AbstractModule(
init {
BackgroundScope.launchLooping("Config Auto Saving", 60000L) {
if (autoSaving && mc.currentScreen !is AbstractLambdaGui<*, *> && timer.tick(savingInterval.toLong())) {
if (savingFeedBack) MessageSendHelper.sendChatMessage("Auto saving settings...")
if (savingFeedBack) NotificationManager.registerNotification("Auto saving settings...")
else LambdaMod.LOG.info("Auto saving settings...")
ConfigUtils.saveAll()
}
Expand Down Expand Up @@ -85,7 +87,8 @@ internal object Configurations : AbstractModule(
val nameWithExtension = "$nameWithoutExtension.json"

return if (!ConfigUtils.isPathValid(nameWithExtension)) {
MessageSendHelper.sendChatMessage("${formatValue(nameWithoutExtension)} is not a valid preset name")
NotificationManager.registerNotification("${formatValue(nameWithoutExtension)} is not a valid preset name",
NotificationType.ERROR)
false
} else {
true
Expand Down Expand Up @@ -174,7 +177,7 @@ internal object Configurations : AbstractModule(
var loaded = ConfigManager.load(GenericConfig)
loaded = ConfigManager.load(config) || loaded

if (loaded) MessageSendHelper.sendChatMessage("${formatValue(config.name)} config reloaded!")
if (loaded) NotificationManager.registerNotification("${formatValue(config.name)} config reloaded!")
else MessageSendHelper.sendErrorMessage("Failed to load ${formatValue(config.name)} config!")
}
}
Expand All @@ -184,7 +187,7 @@ internal object Configurations : AbstractModule(
var saved = ConfigManager.save(GenericConfig)
saved = ConfigManager.save(config) || saved

if (saved) MessageSendHelper.sendChatMessage("${formatValue(config.name)} config saved!")
if (saved) NotificationManager.registerNotification("${formatValue(config.name)} config saved!")
else MessageSendHelper.sendErrorMessage("Failed to load ${formatValue(config.name)} config!")
}
}
Expand Down
Loading