Skip to content

Commit

Permalink
Maybe fix NPE on SpamHider?
Browse files Browse the repository at this point in the history
Not sure why message.message.stripControlCodes throws NPE
  • Loading branch information
My-Name-Is-Jeff committed Sep 24, 2023
1 parent 0dd230b commit 9baff57
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
return false
}

class SpamMessage(var message: String, var time: Long, var height: Double)
data class SpamMessage(var message: String, var time: Long, var height: Double)
class SpamGuiElement : GuiElement("Spam Gui", scale = 1.0f, x = 0.65f, y = 0.925f) {
/**
* Based off of Soopyboo32's SoopyApis module
Expand All @@ -730,10 +730,11 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
lastTimeRender = now
var i = 0
val reversed = spamMessages.asReversed()
val leftAlign = scaleX < sr.scaledWidth / 2f
while (i in spamMessages.indices) {
val message = reversed[i]
val messageWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(
message.message.stripControlCodes()
val messageWidth = ScreenRenderer.fontRenderer.getStringWidth(
message?.message?.stripControlCodes()
)
if (scaleY > sr.scaledHeight / 2f) {
message.height = message.height + (i * 10 - message.height) * (animDiv * 5)
Expand All @@ -753,18 +754,18 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
animOnOff = sin(animOnOff)
animOnOff *= -1.0
animOnOff += 1.0
val x = animOnOff * (messageWidth + 30) * if (scaleX < sr.scaledWidth / 2f) -1 else 1
val x = animOnOff * (messageWidth + 30) * if (leftAlign) -1 else 1
val y = -1 * message.height
val shadow: TextShadow = when (Skytils.config.spamShadow) {
1 -> TextShadow.NONE
2 -> TextShadow.OUTLINE
else -> TextShadow.NORMAL
}
val alignment =
if (scaleX < sr.scaledWidth / 2f) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT
if (leftAlign) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT
ScreenRenderer.fontRenderer.drawString(
message.message,
(if (scaleX < sr.scaledWidth / 2f) x else x + width).toFloat(),
(if (leftAlign) x else x + width).toFloat(),
y.toFloat(),
CommonColors.WHITE,
alignment,
Expand Down Expand Up @@ -823,8 +824,8 @@ object SpamHider : PersistentSave(File(Skytils.modDir, "spamhider.json")) {
if (addToSpam) newMessage(event.packet.chatComponent.formattedText)
}

private fun newMessage(message: String) {
spamMessages.add(SpamMessage(message, 0, 0.0))
private fun newMessage(message: String?) {
spamMessages.add(SpamMessage(message ?: return, 0, 0.0))
}

init {
Expand Down

0 comments on commit 9baff57

Please sign in to comment.