feat(ModuleNotifier): Add Module to get feedback in chat when modules toggle#258
feat(ModuleNotifier): Add Module to get feedback in chat when modules toggle#258IceTank wants to merge 2 commits intolambda-client:1.21.11from
Conversation
|
I refactored the ModuleNotifier so it listens to events produced by the module when toggling |
beanbag44
left a comment
There was a problem hiding this comment.
I dont know, just assuming but if portions of this pr and others are written with ai, please try to clean up the code (unused imports, old comments, etc), and test it to make sure it has the desired outcome
| import com.lambda.util.text.styled | ||
| import com.lambda.util.text.text | ||
| import net.minecraft.client.toast.SystemToast | ||
| import net.minecraft.text.MutableText |
| } | ||
|
|
||
| /** | ||
| * Logs messages to the in game chat if available while stripping the message styles |
| } | ||
|
|
||
| fun toggle() { | ||
| if (ModuleEvent.Toggle(this@Module, !isEnabled).post().isCanceled()) { |
There was a problem hiding this comment.
Enabled and Disabled dont seem to get called when the module is toggled. The toggle event should be posted first, then the corresponding event for the new value
|
|
||
| fun disable() { | ||
| if (ModuleEvent.Disabled(this@Module).post().isCanceled()) { | ||
| return |
There was a problem hiding this comment.
just a styling choice but i typically omit the brackets for early returns and small one-liner if blocks. The return can just be placed at the end of the if statement without the brackets, or just on the next line
| } | ||
|
|
||
| private fun logToTargets(message: Text) { | ||
| if (notifyTarget.contains(NotifyTarget.Chat)) { |
There was a problem hiding this comment.
could use NotifyTarget.Chat in notifyTarget
| object ModuleNotifier : Module( | ||
| name = "ModuleNotifier", | ||
| description = "Notifies you when a module is enabled or disabled", | ||
| tag = com.lambda.module.tag.ModuleTag.CLIENT |
There was a problem hiding this comment.
use an import instead of the full qualified reference
| init { | ||
| listen<ModuleEvent.Enabled> { | ||
| runSafe { | ||
| logToTargets(Text.literal("on").withColor(Colors.GREEN)) |
There was a problem hiding this comment.
we have a text dsl builder for stuff like this
Adds chat feedback when modules toggle