Added debug mode and fixes.
This commit is contained in:
parent
12963b58cb
commit
7a39a0bc7d
2 changed files with 18 additions and 18 deletions
|
@ -1,5 +1,7 @@
|
||||||
package io.github.norbipeti.thebuttonmcchat;
|
package io.github.norbipeti.thebuttonmcchat;
|
||||||
|
|
||||||
|
import io.github.norbipeti.thebuttonmcchat.commands.ucmds.admin.DebugCommand;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -76,14 +78,14 @@ public final class ChatFormatter {
|
||||||
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()) {
|
||||||
System.out.println("Found match from " + matcher.start()
|
DebugCommand.SendDebugMessage("Found match from " + matcher.start()
|
||||||
+ " to " + (matcher.end() - 1));
|
+ " to " + (matcher.end() - 1));
|
||||||
System.out.println("With formatter:" + formatter);
|
DebugCommand.SendDebugMessage("With formatter:" + formatter);
|
||||||
ArrayList<String> groups = new ArrayList<String>();
|
ArrayList<String> groups = new ArrayList<String>();
|
||||||
for (int i = 0; i < matcher.groupCount(); i++)
|
for (int i = 0; i < matcher.groupCount(); i++)
|
||||||
groups.add(matcher.group(i + 1));
|
groups.add(matcher.group(i + 1));
|
||||||
if (groups.size() > 0)
|
if (groups.size() > 0)
|
||||||
System.out.println("First group: " + groups.get(0));
|
DebugCommand.SendDebugMessage("First group: " + groups.get(0));
|
||||||
FormattedSection section = formatter.new FormattedSection(
|
FormattedSection section = formatter.new FormattedSection(
|
||||||
formatter, matcher.start(), matcher.end() - 1, groups);
|
formatter, matcher.start(), matcher.end() - 1, groups);
|
||||||
sections.add(section);
|
sections.add(section);
|
||||||
|
@ -101,10 +103,10 @@ public final class ChatFormatter {
|
||||||
int nextindex = i + 1;
|
int nextindex = i + 1;
|
||||||
if (sections.size() < 2)
|
if (sections.size() < 2)
|
||||||
break;
|
break;
|
||||||
System.out.println("i: " + i);
|
DebugCommand.SendDebugMessage("i: " + i);
|
||||||
if (sections.get(i - 1).End > sections.get(i).Start
|
if (sections.get(i - 1).End > sections.get(i).Start
|
||||||
&& sections.get(i - 1).Start < sections.get(i).End) {
|
&& sections.get(i - 1).Start < sections.get(i).End) {
|
||||||
System.out.println("Combining sections " + sections.get(i - 1)
|
DebugCommand.SendDebugMessage("Combining sections " + sections.get(i - 1)
|
||||||
+ " and " + sections.get(i));
|
+ " and " + sections.get(i));
|
||||||
int origend = sections.get(i - 1).End;
|
int origend = sections.get(i - 1).End;
|
||||||
sections.get(i - 1).End = sections.get(i).Start - 1;
|
sections.get(i - 1).End = sections.get(i).Start - 1;
|
||||||
|
@ -124,25 +126,25 @@ public final class ChatFormatter {
|
||||||
nextindex++;
|
nextindex++;
|
||||||
sections.get(i + 1).Start = origend + 1;
|
sections.get(i + 1).Start = origend + 1;
|
||||||
sections.get(i + 1).End = origend2;
|
sections.get(i + 1).End = origend2;
|
||||||
System.out.println("To sections 1:" + sections.get(i - 1) + "");
|
DebugCommand.SendDebugMessage("To sections 1:" + sections.get(i - 1) + "");
|
||||||
System.out.println(" 2:" + section + "");
|
DebugCommand.SendDebugMessage(" 2:" + section + "");
|
||||||
System.out.println(" 3:" + sections.get(i + 1));
|
DebugCommand.SendDebugMessage(" 3:" + sections.get(i + 1));
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (sections.get(i - 1).Start == sections.get(i).Start
|
if (sections.get(i - 1).Start == sections.get(i).Start
|
||||||
&& sections.get(i - 1).End == sections.get(i).End) {
|
&& sections.get(i - 1).End == sections.get(i).End) {
|
||||||
System.out.println("Combining sections " + sections.get(i - 1)
|
DebugCommand.SendDebugMessage("Combining sections " + sections.get(i - 1)
|
||||||
+ " and " + sections.get(i));
|
+ " and " + sections.get(i));
|
||||||
sections.get(i - 1).Formatters
|
sections.get(i - 1).Formatters
|
||||||
.addAll(sections.get(i).Formatters);
|
.addAll(sections.get(i).Formatters);
|
||||||
sections.get(i - 1).Matches.addAll(sections.get(i).Matches);
|
sections.get(i - 1).Matches.addAll(sections.get(i).Matches);
|
||||||
System.out.println("To section " + sections.get(i - 1));
|
DebugCommand.SendDebugMessage("To section " + sections.get(i - 1));
|
||||||
sections.remove(i);
|
sections.remove(i);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (i < sections.size()
|
if (i < sections.size()
|
||||||
&& sections.get(i).End < sections.get(i).Start) {
|
&& sections.get(i).End < sections.get(i).Start) {
|
||||||
System.out.println("Removing section: " + sections.get(i));
|
DebugCommand.SendDebugMessage("Removing section: " + sections.get(i));
|
||||||
sections.remove(i);
|
sections.remove(i);
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
|
@ -165,9 +167,9 @@ public final class ChatFormatter {
|
||||||
StringBuilder finalstring = new StringBuilder();
|
StringBuilder finalstring = new StringBuilder();
|
||||||
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);
|
||||||
System.out.println("Applying section: " + section);
|
DebugCommand.SendDebugMessage("Applying section: " + section);
|
||||||
String originaltext = str.substring(section.Start, section.End + 1);
|
String originaltext = str.substring(section.Start, section.End + 1);
|
||||||
System.out.println("Originaltext: " + originaltext);
|
DebugCommand.SendDebugMessage("Originaltext: " + originaltext);
|
||||||
finalstring.append(",{\"text\":\""); // TODO: Bool replace
|
finalstring.append(",{\"text\":\""); // TODO: Bool replace
|
||||||
finalstring.append(originaltext);
|
finalstring.append(originaltext);
|
||||||
finalstring.append("\"");
|
finalstring.append("\"");
|
||||||
|
@ -176,7 +178,7 @@ public final class ChatFormatter {
|
||||||
String openlink = null;
|
String openlink = null;
|
||||||
Priority priority = null;
|
Priority priority = null;
|
||||||
for (ChatFormatter formatter : section.Formatters) {
|
for (ChatFormatter formatter : section.Formatters) {
|
||||||
System.out.println("Applying formatter: " + formatter);
|
DebugCommand.SendDebugMessage("Applying formatter: " + formatter);
|
||||||
if (formatter.onmatch == null
|
if (formatter.onmatch == null
|
||||||
|| formatter.onmatch.test(originaltext)) {
|
|| formatter.onmatch.test(originaltext)) {
|
||||||
if (priority == null
|
if (priority == null
|
||||||
|
@ -190,7 +192,7 @@ public final class ChatFormatter {
|
||||||
priority = formatter.priority;
|
priority = formatter.priority;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
System.out.println("Onmatch predicate returned false.");
|
DebugCommand.SendDebugMessage("Onmatch predicate returned false.");
|
||||||
}
|
}
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
finalstring.append(",\"color\":\"");
|
finalstring.append(",\"color\":\"");
|
||||||
|
|
|
@ -80,7 +80,6 @@ public class ChatProcessing {
|
||||||
formattedmessage = formattedmessage.replace("\\", "\\\\");
|
formattedmessage = formattedmessage.replace("\\", "\\\\");
|
||||||
formattedmessage = formattedmessage.replace("\"", "\\\"");
|
formattedmessage = formattedmessage.replace("\"", "\\\"");
|
||||||
// ^ Tellraw support, needed for both the message and suggestmsg
|
// ^ Tellraw support, needed for both the message and suggestmsg
|
||||||
// TODO: Only apply after the formatters, or escaping won't work
|
|
||||||
|
|
||||||
String suggestmsg = formattedmessage;
|
String suggestmsg = formattedmessage;
|
||||||
|
|
||||||
|
@ -93,13 +92,12 @@ public class ChatProcessing {
|
||||||
ChatFormatter.Format.Italic, "$1"));
|
ChatFormatter.Format.Italic, "$1"));
|
||||||
formatters.add(new ChatFormatter(Pattern
|
formatters.add(new ChatFormatter(Pattern
|
||||||
.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_"),
|
.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_"),
|
||||||
ChatFormatter.Format.Italic, "$1"));
|
ChatFormatter.Format.Underlined, "$1"));
|
||||||
|
|
||||||
// URLs + Rainbow text
|
// URLs + Rainbow text
|
||||||
formatters.add(new ChatFormatter(Pattern
|
formatters.add(new ChatFormatter(Pattern
|
||||||
.compile("(http[\\w:/?=$\\-_.+!*'(),]+)"),
|
.compile("(http[\\w:/?=$\\-_.+!*'(),]+)"),
|
||||||
ChatFormatter.Format.Underlined, "$1"));
|
ChatFormatter.Format.Underlined, "$1"));
|
||||||
// TODO: Only format name mentions outisde open_url
|
|
||||||
/*
|
/*
|
||||||
* formattedmessage = formattedmessage .replace( item, String.format(
|
* 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\":\""
|
* "\",\"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\":\""
|
||||||
|
|
Loading…
Reference in a new issue