Skip to content

Commit

Permalink
fix /fmsg without anything breaking & cleanup ChatThread
Browse files Browse the repository at this point in the history
  • Loading branch information
mist475 committed Oct 17, 2023
1 parent 314e571 commit 52013be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion latest
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.1
1.12.2
42 changes: 31 additions & 11 deletions src/main/java/acs/tabbychat/threads/BackgroundChatThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ public class BackgroundChatThread extends Thread {
String sendChat;
String knownPrefix;

final Minecraft mc;

public BackgroundChatThread(String _send) {
this.sendChat = _send;
mc = Minecraft.getMinecraft();
}

public BackgroundChatThread(String _send, String _prefix) {
this.sendChat = _send;
this.knownPrefix = _prefix;
mc = Minecraft.getMinecraft();
}

@Override
public synchronized void run() {
Minecraft mc = Minecraft.getMinecraft();
mc.ingameGUI.getChatGUI().addToSentMessages(this.sendChat);
String cmdPrefix = "";
String[] toSplit;
Expand All @@ -35,20 +38,29 @@ public synchronized void run() {
else {
toSplit = this.sendChat.split(" ");
start = 0;
// command
if (toSplit.length > 0 && toSplit[0].startsWith("/")) {
if (toSplit[0].startsWith("/msg")) {
cmdPrefix = toSplit[0] + " " + toSplit[1] + " ";
start = 2;
}

// /fmsg is added by lotr to message groups of players
// /fmsg bind or unbind sets a default fellowship and should not be parsed as a multiline comment
else if (toSplit[0].startsWith("/fmsg") && !(toSplit.length > 2 && toSplit[1].contains("bind"))) {
//targeted name is contained with double quotes
String[] fShipNameArray = this.sendChat.split("\"");
if (fShipNameArray.length > 1) {
cmdPrefix = toSplit[0] + " \"" + fShipNameArray[1] + "\" ";
//count number of spaces in fShipNameArray and set start accordingly
start = 2 + StringUtils.countMatches(fShipNameArray[1], " ");
else if (toSplit[0].startsWith("/fmsg") && toSplit.length > 1) {
// /fmsg bind or unbind sets a default fellowship and should not be parsed as a multiline comment
if (!toSplit[1].endsWith("bind")) {
String[] fShipNameArray = this.sendChat.split("\"");
//targeted name is contained with double quotes
if (fShipNameArray.length > 1) {
cmdPrefix = toSplit[0] + " \"" + fShipNameArray[1] + "\" ";
//count number of spaces in fShipNameArray and set start accordingly
start = 2 + StringUtils.countMatches(fShipNameArray[1], " ");
}
// default
else {
cmdPrefix = "/fmsg ";
start = 1;
}
}
}
else if (!toSplit[0].trim().equals("/")) {
Expand All @@ -57,14 +69,21 @@ else if (!toSplit[0].trim().equals("/")) {
}
}
}


sendChat(start,toSplit,cmdPrefix);

}

private void sendChat(int start, String[] toSplit, String cmdPrefix) {
int suffix = cmdPrefix.length();
StringBuilder sendPart = new StringBuilder(119);
for (int word = start; word < toSplit.length; word++) {
if (sendPart.length() + toSplit[word].length() + suffix > 100) {
mc.thePlayer.sendChatMessage(cmdPrefix + sendPart.toString().trim());
try {
Thread.sleep(Integer.parseInt(TabbyChat.advancedSettings.multiChatDelay
.getValue()));
.getValue()));
}
catch (InterruptedException e) {
e.printStackTrace();
Expand All @@ -75,7 +94,8 @@ else if (!toSplit[0].trim().equals("/")) {
}
sendPart.append(toSplit[word]).append(" ");
}
if (sendPart.length() > 0 || cmdPrefix.length() > 0) {

if (!(sendPart.length() == 0) || !(cmdPrefix.length() == 0)) {
String message = cmdPrefix + sendPart.toString().trim();
message = ChatAllowedCharacters.filerAllowedCharacters(message);

Expand Down

0 comments on commit 52013be

Please sign in to comment.