#46 is harder than I thought

This commit is contained in:
Norbi Peti 2016-09-24 19:00:37 +02:00
parent 0e54ce1fed
commit 85a1defb6a
3 changed files with 3 additions and 19 deletions

View file

@ -110,12 +110,6 @@ public class ChatProcessing {
// URLs + Rainbow text // URLs + Rainbow text
formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(ChatFormatter.Format.Underlined) formatters.add(new ChatFormatterBuilder().setRegex(URL_PATTERN).setFormat(ChatFormatter.Format.Underlined)
.setOpenlink("$1").build()); .setOpenlink("$1").build());
/*
* formattedmessage = formattedmessage .replace( item, String.format(
* "\",\"color\":\"%s\"},{\"text\":\"%s\",\"color\":\"%s\",\"underlined\":\"true\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"%s\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"Open URL\",\"color\":\"blue\"}]}}},{\"text\":\""
* , colormode, url, colormode, url));
*/
if (PluginMain.GetPlayers().size() > 0) { if (PluginMain.GetPlayers().size() > 0) {
StringBuilder namesb = new StringBuilder(); StringBuilder namesb = new StringBuilder();
namesb.append("(?i)("); namesb.append("(?i)(");

View file

@ -35,7 +35,6 @@ public final class ChatFormatter {
* This method assumes that there is always a global formatter * This method assumes that there is always a global formatter
*/ */
ArrayList<FormattedSection> sections = new ArrayList<FormattedSection>(); ArrayList<FormattedSection> sections = new ArrayList<FormattedSection>();
List<Integer> removecharpositions = new ArrayList<Integer>();
for (ChatFormatter formatter : formatters) { for (ChatFormatter formatter : formatters) {
Matcher matcher = formatter.regex.matcher(str); Matcher matcher = formatter.regex.matcher(str);
while (matcher.find()) { while (matcher.find()) {
@ -48,12 +47,6 @@ public final class ChatFormatter {
DebugCommand.SendDebugMessage("First group: " + groups.get(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);
sections.add(section); sections.add(section);
if (formatter.removecharcount != 0) {
removecharpositions.add(section.Start + formatter.removecharcount - 1);
removecharpositions.add(section.End - formatter.removecharcount - 1);
}
if (formatter.removecharpos != -1)
removecharpositions.add(section.Start + (int) formatter.removecharpos);
} }
} }
sections.sort((s1, s2) -> { sections.sort((s1, s2) -> {
@ -62,7 +55,6 @@ public final class ChatFormatter {
else else
return Integer.compare(s1.Start, s2.Start); return Integer.compare(s1.Start, s2.Start);
}); });
removecharpositions.sort(null);
boolean cont = true; boolean cont = true;
boolean found = false; boolean found = false;
for (int i = 1; cont;) { for (int i = 1; cont;) {
@ -83,7 +75,7 @@ public final class ChatFormatter {
} }
FormattedSection section = new FormattedSection(sections.get(i - 1).Formatters, sections.get(i).Start, FormattedSection section = new FormattedSection(sections.get(i - 1).Formatters, sections.get(i).Start,
origend, sections.get(i - 1).Matches); origend, sections.get(i - 1).Matches);
section.Formatters.addAll(sections.get(i).Formatters); section.Formatters.addAll(sections.get(i).Formatters); // TODO: Process remove positions here
section.Matches.addAll(sections.get(i).Matches); section.Matches.addAll(sections.get(i).Matches);
sections.add(i, section); sections.add(i, section);
nextindex++; nextindex++;
@ -133,7 +125,6 @@ public final class ChatFormatter {
} }
} }
int nextremcharpospos = 0; int nextremcharpospos = 0;
DebugCommand.SendDebugMessage("RemoveCharPositions size: " + removecharpositions.size());
for (int i = 0; i < sections.size(); i++) { for (int i = 0; i < sections.size(); i++) {
FormattedSection section = sections.get(i); FormattedSection section = sections.get(i);
DebugCommand.SendDebugMessage("Applying section: " + section); DebugCommand.SendDebugMessage("Applying section: " + section);
@ -147,7 +138,7 @@ public final class ChatFormatter {
start++; start++;
nextremcharpospos++; nextremcharpospos++;
if (removecharpositions.size() > nextremcharpospos) if (removecharpositions.size() > nextremcharpospos)
nextremcharpos = removecharpositions.get(nextremcharpospos); //TODO: Section.RemoveCharCountStart/End nextremcharpos = removecharpositions.get(nextremcharpospos); // TODO: Section.RemoveCharCountStart/End
} }
if (nextremcharpos == section.End) { if (nextremcharpos == section.End) {
end--; end--;

View file

@ -26,7 +26,6 @@ class FormattedSection {
@Override @Override
public String toString() { public String toString() {
return new StringBuilder("Section(").append(Start).append(", ").append(End).append(", formatters: ") return new StringBuilder("Section(").append(Start).append(", ").append(End).append(", formatters: ")
.append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append(")") .append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append(")").toString();
.toString();
} }
} }