From 9e1b1152c192f8a1edc36c387c6cbf39c7e16c9b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 25 Sep 2016 21:54:22 +0200 Subject: [PATCH] Hopefully about to fix #46 --- .../chat/formatting/ChatFormatter.java | 32 +++++++------------ .../chat/formatting/FormattedSection.java | 27 ++++++++++++---- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java index 1cbb7b6..cad97fd 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java @@ -45,7 +45,8 @@ public final class ChatFormatter { groups.add(matcher.group(i + 1)); if (groups.size() > 0) DebugCommand.SendDebugMessage("First group: " + groups.get(0)); - FormattedSection section = new FormattedSection(formatter, matcher.start(), matcher.end() - 1, groups); + FormattedSection section = new FormattedSection(formatter, matcher.start(), matcher.end() - 1, groups, + formatter.removecharcount, formatter.removecharcount, formatter.removecharpos); sections.add(section); } } @@ -74,9 +75,10 @@ public final class ChatFormatter { origend2 = tmp; } FormattedSection section = new FormattedSection(sections.get(i - 1).Formatters, sections.get(i).Start, - origend, sections.get(i - 1).Matches); - section.Formatters.addAll(sections.get(i).Formatters); // TODO: Process remove positions here - section.Matches.addAll(sections.get(i).Matches); + origend, sections.get(i - 1).Matches, sections.get(i - 1).RemCharFromStart, + sections.get(i - 1).RemCharFromEnd, sections.get(i - 1).RemCharPos); // TODO: RemCharPos + section.Formatters.addAll(sections.get(i).Formatters); // TODO: Add remove counts to every part, then check if they have duplicates + section.Matches.addAll(sections.get(i).Matches); // TODO: Clean sections.add(i, section); nextindex++; FormattedSection thirdFormattedSection = sections.get(i + 1); @@ -85,6 +87,7 @@ public final class ChatFormatter { thirdFormattedSection.Formatters.addAll(sections.get(i - 1).Formatters); thirdFormattedSection.Matches.clear(); thirdFormattedSection.Matches.addAll(sections.get(i - 1).Matches); + thirdFormattedSection.RemCharFromEnd = sections.get(i - 1).RemCharFromEnd; } thirdFormattedSection.Start = origend + 1; thirdFormattedSection.End = origend2; @@ -99,6 +102,10 @@ public final class ChatFormatter { sections.get(i - 1).Matches.addAll(sections.get(i).Matches); DebugCommand.SendDebugMessage("To section " + sections.get(i - 1)); sections.remove(i); + if (sections.get(i - 1).RemCharFromStart < sections.get(i).RemCharFromStart) + sections.get(i - 1).RemCharFromStart = sections.get(i).RemCharFromStart; + if (sections.get(i - 1).RemCharFromEnd < sections.get(i).RemCharFromEnd) + sections.get(i - 1).RemCharFromEnd = sections.get(i).RemCharFromEnd; found = true; } for (int j = i - 1; j <= i + 1; j++) { @@ -124,26 +131,11 @@ public final class ChatFormatter { cont = false; } } - int nextremcharpospos = 0; for (int i = 0; i < sections.size(); i++) { FormattedSection section = sections.get(i); DebugCommand.SendDebugMessage("Applying section: " + section); - int nextremcharpos = -1; - if (removecharpositions.size() > nextremcharpospos) - nextremcharpos = removecharpositions.get(nextremcharpospos); String originaltext; - int start = section.Start, end = section.End + 1; - DebugCommand.SendDebugMessage("Next remove char pos: " + nextremcharpos); - if (nextremcharpos == section.Start) { - start++; - nextremcharpospos++; - if (removecharpositions.size() > nextremcharpospos) - nextremcharpos = removecharpositions.get(nextremcharpospos); // TODO: Section.RemoveCharCountStart/End - } - if (nextremcharpos == section.End) { - end--; - nextremcharpospos++; - } + int start = section.Start - section.RemCharFromStart, end = section.End + 1 - section.RemCharFromEnd; // TODO: RemCharPos originaltext = str.substring(start, end); DebugCommand.SendDebugMessage("Originaltext: " + originaltext); Color color = null; diff --git a/src/main/java/buttondevteam/chat/formatting/FormattedSection.java b/src/main/java/buttondevteam/chat/formatting/FormattedSection.java index 0ab55ba..63b22ec 100644 --- a/src/main/java/buttondevteam/chat/formatting/FormattedSection.java +++ b/src/main/java/buttondevteam/chat/formatting/FormattedSection.java @@ -4,28 +4,41 @@ import java.util.ArrayList; import java.util.Collection; class FormattedSection { - public int Start; - public int End; - public ArrayList Formatters = new ArrayList(); - public ArrayList Matches = new ArrayList(); + int Start; + int End; + ArrayList Formatters = new ArrayList(); + ArrayList Matches = new ArrayList(); + short RemCharFromStart; + short RemCharFromEnd; + int RemCharPos; - public FormattedSection(ChatFormatter formatter, int start, int end, ArrayList matches) { + FormattedSection(ChatFormatter formatter, int start, int end, ArrayList matches, short remcharfromstart, + short remcharfromend, int remcharpos) { Start = start; End = end; Formatters.add(formatter); Matches.addAll(matches); + RemCharFromStart = remcharfromstart; + RemCharFromEnd = remcharfromend; + RemCharPos = remcharpos; } - public FormattedSection(Collection formatters, int start, int end, ArrayList matches) { + FormattedSection(Collection formatters, int start, int end, ArrayList matches, + short remcharfromstart, short remcharfromend, int remcharpos) { Start = start; End = end; Formatters.addAll(formatters); Matches.addAll(matches); + RemCharFromStart = remcharfromstart; + RemCharFromEnd = remcharfromend; + RemCharPos = remcharpos; } @Override public String toString() { return new StringBuilder("Section(").append(Start).append(", ").append(End).append(", formatters: ") - .append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append(")").toString(); + .append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append("RemChars: ") + .append(RemCharFromStart).append(", ").append(RemCharFromEnd).append(", ").append(RemCharPos) + .append(")").toString(); } } \ No newline at end of file