Skip to content

Commit

Permalink
It works
Browse files Browse the repository at this point in the history
  • Loading branch information
OoLunar committed Jan 1, 2023
1 parent 536b52e commit 9896c41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
35 changes: 10 additions & 25 deletions src/main/java/com/dubfib/autoutils/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.dubfib.autoutils.config.Config;
import com.dubfib.autoutils.events.ChatEvent;
Expand All @@ -22,6 +24,8 @@

@Mod(name = Config.NAME, modid = Config.ID, version = Config.VERSION)
public class Main {
public static Pattern textFormattingPattern = Pattern.compile("§[0-9a-fk-or]");

@EventHandler
public void init(FMLInitializationEvent event) {
// Read the languages file as a stream
Expand Down Expand Up @@ -67,30 +71,11 @@ public void onChat(ClientChatReceivedEvent event) {
ChatEvent.AutoGG(getPlainText(event.message));
};

private String getPlainText(IChatComponent component) {
String baseString = component.getUnformattedTextForChat();
StringBuilder stringBuilder = new StringBuilder();
char[] chars = baseString.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
// If this is not the last character in the string
if (i < chars.length - 1) {
// If this is a formatting code
// Or a double space
if ((c == '§' && "0123456789abcdefklmnor".indexOf(chars[i + 1]) > -1)
|| c == ' ' && chars[i + 1] == ' ') {
// This skips the current character and the next character (the formatting code)
i++;
continue;
}
} else if (c == ' ') {
// If the last character is a space, skip it
continue;
}

stringBuilder.append(c);
}

return stringBuilder.toString();
private String getPlainText(IChatComponent message) {
String baseString = message.getUnformattedText();
Matcher m = textFormattingPattern.matcher(baseString);
baseString = m.replaceAll("");
baseString = baseString.replace(" ", "");
return baseString;
}
};
1 change: 0 additions & 1 deletion src/main/java/com/dubfib/autoutils/events/ChatEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static void AutoGL(String message) {
};

public static void AutoGG(String message) {
System.out.println("AutoGG called with message: " + message);
if (goodGameMessages.containsKey(message.trim())) {
Minecraft.getMinecraft().thePlayer.sendChatMessage("/ac " + goodGameMessages.get(message));
}
Expand Down

0 comments on commit 9896c41

Please sign in to comment.