Probably fixed #46
This commit is contained in:
parent
4a454da723
commit
bda72749cd
2 changed files with 26 additions and 10 deletions
|
@ -45,6 +45,7 @@ public class ChatProcessing {
|
||||||
|
|
||||||
// Returns e.setCancelled
|
// Returns e.setCancelled
|
||||||
public static boolean ProcessChat(CommandSender sender, String message) {
|
public static boolean ProcessChat(CommandSender sender, String message) {
|
||||||
|
long processstart = System.nanoTime();
|
||||||
if (PlayerListener.essentials == null)
|
if (PlayerListener.essentials == null)
|
||||||
PlayerListener.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
PlayerListener.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
|
||||||
Player player = (sender instanceof Player ? (Player) sender : null);
|
Player player = (sender instanceof Player ? (Player) sender : null);
|
||||||
|
@ -230,7 +231,9 @@ public class ChatProcessing {
|
||||||
+ PlayerListener.AlphaDeaths
|
+ PlayerListener.AlphaDeaths
|
||||||
: "")))))));
|
: "")))))));
|
||||||
json.addExtra(new TellrawPart("> "));
|
json.addExtra(new TellrawPart("> "));
|
||||||
|
long combinetime = System.nanoTime();
|
||||||
ChatFormatter.Combine(formatters, formattedmessage, json);
|
ChatFormatter.Combine(formatters, formattedmessage, json);
|
||||||
|
combinetime = System.nanoTime() - combinetime;
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
||||||
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
||||||
|
@ -399,6 +402,8 @@ public class ChatProcessing {
|
||||||
.sendMessage(String.format("[%s] <%s%s> %s", currentchannel.DisplayName,
|
.sendMessage(String.format("[%s] <%s%s> %s", currentchannel.DisplayName,
|
||||||
(player != null ? player.getDisplayName() : sender.getName()),
|
(player != null ? player.getDisplayName() : sender.getName()),
|
||||||
(mp != null ? mp.GetFormattedFlair() : ""), message));
|
(mp != null ? mp.GetFormattedFlair() : ""), message));
|
||||||
|
DebugCommand.SendDebugMessage("-- Full ChatProcessing time: " + (System.nanoTime() - processstart));
|
||||||
|
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ 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()) {
|
||||||
|
@ -47,6 +48,12 @@ 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);
|
||||||
|
removecharpositions.add(section.End - formatter.removecharcount);
|
||||||
|
}
|
||||||
|
if (formatter.removecharpos != -1)
|
||||||
|
removecharpositions.add(section.Start + (int) formatter.removecharpos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sections.sort((s1, s2) -> {
|
sections.sort((s1, s2) -> {
|
||||||
|
@ -55,6 +62,7 @@ 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;) {
|
||||||
|
@ -124,15 +132,25 @@ public final class ChatFormatter {
|
||||||
cont = false;
|
cont = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int nextremcharpospos = 0;
|
||||||
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);
|
||||||
String originaltext = str.substring(section.Start, section.End + 1);
|
int nextremcharpos = -1;
|
||||||
|
if (removecharpositions.size() > nextremcharpospos)
|
||||||
|
nextremcharpos = removecharpositions.get(nextremcharpospos);
|
||||||
|
String originaltext;
|
||||||
|
int start = section.Start, end = section.End + 1;
|
||||||
|
if (nextremcharpos == section.Start)
|
||||||
|
start++;
|
||||||
|
if (nextremcharpos == section.End)
|
||||||
|
end--;
|
||||||
|
originaltext = str.substring(start, end);
|
||||||
|
nextremcharpospos++;
|
||||||
DebugCommand.SendDebugMessage("Originaltext: " + originaltext);
|
DebugCommand.SendDebugMessage("Originaltext: " + originaltext);
|
||||||
Color color = null;
|
Color color = null;
|
||||||
Format format = null;
|
Format format = null;
|
||||||
String openlink = null;
|
String openlink = null;
|
||||||
List<Integer> removecharpositions = new ArrayList<Integer>();
|
|
||||||
section.Formatters.sort((cf2, cf1) -> cf1.priority.compareTo(cf2.priority));
|
section.Formatters.sort((cf2, cf1) -> cf1.priority.compareTo(cf2.priority));
|
||||||
for (ChatFormatter formatter : section.Formatters) {
|
for (ChatFormatter formatter : section.Formatters) {
|
||||||
DebugCommand.SendDebugMessage("Applying formatter: " + formatter);
|
DebugCommand.SendDebugMessage("Applying formatter: " + formatter);
|
||||||
|
@ -144,16 +162,9 @@ public final class ChatFormatter {
|
||||||
format = formatter.format;
|
format = formatter.format;
|
||||||
if (formatter.openlink != null)
|
if (formatter.openlink != null)
|
||||||
openlink = formatter.openlink;
|
openlink = formatter.openlink;
|
||||||
if (formatter.removecharcount != 0) {
|
|
||||||
removecharpositions.add(section.Start + formatter.removecharcount); // TODO: Do this before combining the sections
|
|
||||||
removecharpositions.add(section.End - formatter.removecharcount);
|
|
||||||
}
|
|
||||||
if (formatter.removecharpos != -1)
|
|
||||||
removecharpositions.add((int) formatter.removecharpos);
|
|
||||||
}
|
}
|
||||||
TellrawPart newtp = new TellrawPart("");
|
TellrawPart newtp = new TellrawPart("");
|
||||||
StringBuilder origtextsb = new StringBuilder(originaltext); // TODO
|
newtp.setText(originaltext);
|
||||||
newtp.setText(origtextsb.toString());
|
|
||||||
if (color != null)
|
if (color != null)
|
||||||
newtp.setColor(color);
|
newtp.setColor(color);
|
||||||
if (format != null)
|
if (format != null)
|
||||||
|
|
Loading…
Reference in a new issue