From bcd6d3f1940a069eb2b529267f120cbdc9f9f81a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 8 Jun 2017 23:36:37 +0200 Subject: [PATCH] Removed RemCharPos, wasn't used It was only used for escaping before --- .../chat/formatting/ChatFormatter.java | 25 +++---------------- .../chat/formatting/ChatFormatterBuilder.java | 17 +------------ .../chat/formatting/FormattedSection.java | 11 +++----- 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java index e9fae16..b901565 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java @@ -1,7 +1,6 @@ package buttondevteam.chat.formatting; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,12 +24,11 @@ public final class ChatFormatter { private String openlink; private Priority priority; private short removecharcount = 0; - private short removecharpos = -1; private boolean isrange; public ChatFormatter(Pattern regex, boolean italic, boolean bold, boolean underlined, boolean strikethrough, boolean obfuscated, Color color, Function onmatch, String openlink, Priority priority, - short removecharcount, short removecharpos, boolean isrange) { + short removecharcount, boolean isrange) { super(); this.regex = regex; this.italic = italic; @@ -46,7 +44,6 @@ public final class ChatFormatter { else this.priority = priority; this.removecharcount = removecharcount; - this.removecharpos = removecharpos; this.isrange = isrange; } @@ -66,8 +63,7 @@ public final class ChatFormatter { if (groups.size() > 0) DebugCommand.SendDebugMessage("First group: " + groups.get(0)); FormattedSection section = new FormattedSection(formatter, matcher.start(), matcher.end() - 1, groups, - formatter.removecharcount, formatter.removecharcount, formatter.removecharpos, - formatter.isrange); + formatter.removecharcount, formatter.removecharcount, formatter.isrange); sections.add(section); } } @@ -141,7 +137,6 @@ public final class ChatFormatter { firstSection.RemCharFromStart = sections.get(i).RemCharFromStart; if (firstSection.RemCharFromEnd < sections.get(i).RemCharFromEnd) firstSection.RemCharFromEnd = sections.get(i).RemCharFromEnd; - firstSection.RemCharPos.addAll(sections.get(i).RemCharPos); DebugCommand.SendDebugMessage("To section " + firstSection); sections.remove(i); found = true; @@ -156,8 +151,7 @@ public final class ChatFormatter { origend2 = tmp; } FormattedSection section = new FormattedSection(firstSection.Formatters, sections.get(i).Start, origend, - firstSection.Matches, sections.get(i).RemCharFromStart, firstSection.RemCharFromEnd, - Collections.emptyList(), false); + firstSection.Matches, sections.get(i).RemCharFromStart, firstSection.RemCharFromEnd, false); section.Formatters.addAll(sections.get(i).Formatters); section.Matches.addAll(sections.get(i).Matches); // TODO: Clean sections.add(i, section); @@ -176,16 +170,6 @@ public final class ChatFormatter { thirdFormattedSection.RemCharFromStart = 0; thirdFormattedSection.Start = origend + 1; thirdFormattedSection.End = origend2; - for (int x = 0; x < firstSection.RemCharPos.size(); x++) { - if (firstSection.RemCharPos.get(x) > firstSection.End) { - if (firstSection.RemCharPos.get(x) > section.End) - thirdFormattedSection.RemCharPos.add( - firstSection.RemCharPos.get(x) - thirdFormattedSection.Start + firstSection.Start); - else - section.RemCharPos.add(firstSection.RemCharPos.get(x) - section.Start + firstSection.Start); - firstSection.RemCharPos.remove(x--); - } - } DebugCommand.SendDebugMessage("To sections 1:" + firstSection + ""); DebugCommand.SendDebugMessage(" 2:" + section + ""); DebugCommand.SendDebugMessage(" 3:" + thirdFormattedSection); @@ -220,9 +204,6 @@ public final class ChatFormatter { String originaltext; int start = section.Start + section.RemCharFromStart, end = section.End + 1 - section.RemCharFromEnd; // TODO: RemCharPos StringBuilder textsb = new StringBuilder(str.substring(start, end)); - for (int x = 0; x < section.RemCharPos.size(); x++) - if (section.RemCharPos.get(x) != -1) - textsb.deleteCharAt(section.RemCharPos.get(x)); originaltext = textsb.toString(); DebugCommand.SendDebugMessage("Section text: " + originaltext); Color color = null; diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java index ab7474c..fea8072 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatterBuilder.java @@ -17,12 +17,11 @@ public class ChatFormatterBuilder { private String openlink; private Priority priority; private short removecharcount = 0; - private short removecharpos = -1; private boolean range = false; public ChatFormatter build() { return new ChatFormatter(regex, italic, bold, underlined, strikethrough, obfuscated, color, onmatch, openlink, - priority, removecharcount, removecharpos, range); + priority, removecharcount, range); } public Pattern getRegex() { @@ -129,20 +128,6 @@ public class ChatFormatterBuilder { return this; } - public short getRemoveCharPos() { - return removecharpos; - } - - /** - * Sets the position where a single character should be removed. Setting -1 will disable it. - * - * @return This instance - */ - public ChatFormatterBuilder setRemoveCharPos(short removecharpos) { - this.removecharpos = removecharpos; - return this; - } - public boolean isRange() { return range; } diff --git a/src/main/java/buttondevteam/chat/formatting/FormattedSection.java b/src/main/java/buttondevteam/chat/formatting/FormattedSection.java index 67aa64e..3c0fc06 100644 --- a/src/main/java/buttondevteam/chat/formatting/FormattedSection.java +++ b/src/main/java/buttondevteam/chat/formatting/FormattedSection.java @@ -10,33 +10,30 @@ class FormattedSection { ArrayList Matches = new ArrayList(); short RemCharFromStart; short RemCharFromEnd; - ArrayList RemCharPos = new ArrayList(); /** * Is it a 1-long section indicating a start or an end */ boolean IsRange; FormattedSection(ChatFormatter formatter, int start, int end, ArrayList matches, short remcharfromstart, - short remcharfromend, int remcharpos, boolean isrange) { + short remcharfromend, boolean isrange) { Start = start; End = end; Formatters.add(formatter); Matches.addAll(matches); RemCharFromStart = remcharfromstart; RemCharFromEnd = remcharfromend; - RemCharPos.add(remcharpos); IsRange = isrange; } FormattedSection(Collection formatters, int start, int end, ArrayList matches, - short remcharfromstart, short remcharfromend, Collection remcharpos, boolean isrange) { + short remcharfromstart, short remcharfromend, boolean isrange) { Start = start; End = end; Formatters.addAll(formatters); Matches.addAll(matches); RemCharFromStart = remcharfromstart; RemCharFromEnd = remcharfromend; - RemCharPos.addAll(remcharpos); IsRange = isrange; } @@ -44,7 +41,7 @@ class FormattedSection { 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(RemCharFromStart).append(", ").append(RemCharFromEnd).append(", ").append(RemCharPos) - .append(", ").append(IsRange).append(")").toString(); + .append(RemCharFromStart).append(", ").append(RemCharFromEnd).append(", ").append(IsRange).append(")") + .toString(); } } \ No newline at end of file