Skip to content

Commit

Permalink
Hopefully fix a crash regarding anti-spam and other chat mods
Browse files Browse the repository at this point in the history
  • Loading branch information
Wide-Cat committed Sep 13, 2024
1 parent 5b1a153 commit 99d2eb1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void onAddMessage(Text message, MessageSignatureData signatureData, Mess
for (int i = messages.size() - 1; i > -1; i--) {
if (((IChatHudLine) (Object) messages.get(i)).meteor$getId() == nextId && nextId != 0) {
messages.remove(i);
Modules.get().get(BetterChat.class).lines.removeInt(i);
getBetterChat().removeLine(i);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,32 @@ private void onMessageReceive(ReceiveMessageEvent event) {
event.setMessage(message);
}

@EventHandler
private void onMessageSend(SendMessageEvent event) {
String message = event.message;

if (annoy.get()) message = applyAnnoy(message);

if (fancy.get()) message = applyFancy(message);

message = getPrefix() + message + getSuffix();

if (coordsProtection.get() && containsCoordinates(message)) {
MutableText warningMessage = Text.literal("It looks like there are coordinates in your message! ");

MutableText sendButton = getSendButton(message);
warningMessage.append(sendButton);

ChatUtils.sendMsg(warningMessage);

event.cancel();
return;
}

event.message = message;
}

// Anti Spam

private Text appendAntiSpam(Text text) {
String textString = text.getString();
Expand Down Expand Up @@ -349,29 +375,17 @@ private Text appendAntiSpam(Text text) {
return returnText;
}

@EventHandler
private void onMessageSend(SendMessageEvent event) {
String message = event.message;

if (annoy.get()) message = applyAnnoy(message);

if (fancy.get()) message = applyFancy(message);

message = getPrefix() + message + getSuffix();

if (coordsProtection.get() && containsCoordinates(message)) {
MutableText warningMessage = Text.literal("It looks like there are coordinates in your message! ");

MutableText sendButton = getSendButton(message);
warningMessage.append(sendButton);

ChatUtils.sendMsg(warningMessage);
public void removeLine(int index) {
if (index >= lines.size()) {
if (antiSpam.get()) {
error("Issue detected with the anti-spam system! Likely a compatibility issue with another mod. Disabling anti-spam to protect chat integrity.");
antiSpam.set(false);
}

event.cancel();
return;
}

event.message = message;
lines.removeInt(index);
}

// Player Heads
Expand Down

0 comments on commit 99d2eb1

Please sign in to comment.