From c4e22a779e55dccf605c776e667be7ed1da357ca Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 1 Oct 2016 19:10:50 +0200 Subject: [PATCH] Fixed #46! The char remove still WIP --- .../chat/formatting/ChatFormatter.java | 36 ++++++++++--------- .../chat/formatting/FormattedSection.java | 2 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java index cad97fd..0c35f03 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java @@ -63,7 +63,19 @@ public final class ChatFormatter { if (sections.size() < 2) break; DebugCommand.SendDebugMessage("i: " + i); - if (sections.get(i - 1).End > sections.get(i).Start && sections.get(i - 1).Start < sections.get(i).End) { + if (sections.get(i - 1).Start == sections.get(i).Start && sections.get(i - 1).End == sections.get(i).End) { + DebugCommand.SendDebugMessage("Combining sections " + sections.get(i - 1) + " and " + sections.get(i)); + sections.get(i - 1).Formatters.addAll(sections.get(i).Formatters); + sections.get(i - 1).Matches.addAll(sections.get(i).Matches); + 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; + DebugCommand.SendDebugMessage("To section " + sections.get(i - 1)); + sections.remove(i); + found = true; + } else if (sections.get(i - 1).End > sections.get(i).Start + && sections.get(i - 1).Start < sections.get(i).End) { DebugCommand.SendDebugMessage("Combining sections " + sections.get(i - 1) + " and " + sections.get(i)); int origend = sections.get(i - 1).End; sections.get(i - 1).End = sections.get(i).Start - 1; @@ -75,7 +87,7 @@ 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, sections.get(i - 1).RemCharFromStart, + origend, sections.get(i - 1).Matches, sections.get(i).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 @@ -87,8 +99,12 @@ 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; + short remchar = section.RemCharFromEnd; + section.RemCharFromEnd = thirdFormattedSection.RemCharFromEnd; + thirdFormattedSection.RemCharFromEnd = remchar; } + sections.get(i - 1).RemCharFromEnd = 0; + thirdFormattedSection.RemCharFromStart = 0; thirdFormattedSection.Start = origend + 1; thirdFormattedSection.End = origend2; DebugCommand.SendDebugMessage("To sections 1:" + sections.get(i - 1) + ""); @@ -96,18 +112,6 @@ public final class ChatFormatter { DebugCommand.SendDebugMessage(" 3:" + thirdFormattedSection); found = true; } - if (sections.get(i - 1).Start == sections.get(i).Start && sections.get(i - 1).End == sections.get(i).End) { - DebugCommand.SendDebugMessage("Combining sections " + sections.get(i - 1) + " and " + sections.get(i)); - sections.get(i - 1).Formatters.addAll(sections.get(i).Formatters); - 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++) { if (j < sections.size() && sections.get(j).End < sections.get(j).Start) { DebugCommand.SendDebugMessage("Removing section: " + sections.get(j)); @@ -135,7 +139,7 @@ public final class ChatFormatter { FormattedSection section = sections.get(i); DebugCommand.SendDebugMessage("Applying section: " + section); String originaltext; - int start = section.Start - section.RemCharFromStart, end = section.End + 1 - section.RemCharFromEnd; // TODO: RemCharPos + 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 63b22ec..b78433d 100644 --- a/src/main/java/buttondevteam/chat/formatting/FormattedSection.java +++ b/src/main/java/buttondevteam/chat/formatting/FormattedSection.java @@ -37,7 +37,7 @@ class FormattedSection { @Override public String toString() { return new StringBuilder("Section(").append(Start).append(", ").append(End).append(", formatters: ") - .append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append("RemChars: ") + .append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append(", RemChars: ") .append(RemCharFromStart).append(", ").append(RemCharFromEnd).append(", ").append(RemCharPos) .append(")").toString(); }