Probably fixed #46

This commit is contained in:
Norbi Peti 2016-09-24 17:31:55 +02:00
parent 4a454da723
commit bda72749cd
2 changed files with 26 additions and 10 deletions

View file

@ -45,6 +45,7 @@ public class ChatProcessing {
// Returns e.setCancelled
public static boolean ProcessChat(CommandSender sender, String message) {
long processstart = System.nanoTime();
if (PlayerListener.essentials == null)
PlayerListener.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials"));
Player player = (sender instanceof Player ? (Player) sender : null);
@ -230,7 +231,9 @@ public class ChatProcessing {
+ PlayerListener.AlphaDeaths
: "")))))));
json.addExtra(new TellrawPart("> "));
long combinetime = System.nanoTime();
ChatFormatter.Combine(formatters, formattedmessage, json);
combinetime = System.nanoTime() - combinetime;
Gson gson = new GsonBuilder()
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
@ -399,6 +402,8 @@ public class ChatProcessing {
.sendMessage(String.format("[%s] <%s%s> %s", currentchannel.DisplayName,
(player != null ? player.getDisplayName() : sender.getName()),
(mp != null ? mp.GetFormattedFlair() : ""), message));
DebugCommand.SendDebugMessage("-- Full ChatProcessing time: " + (System.nanoTime() - processstart));
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime);
return true;
}
}

View file

@ -35,6 +35,7 @@ public final class ChatFormatter {
* This method assumes that there is always a global formatter
*/
ArrayList<FormattedSection> sections = new ArrayList<FormattedSection>();
List<Integer> removecharpositions = new ArrayList<Integer>();
for (ChatFormatter formatter : formatters) {
Matcher matcher = formatter.regex.matcher(str);
while (matcher.find()) {
@ -47,6 +48,12 @@ public final class ChatFormatter {
DebugCommand.SendDebugMessage("First group: " + groups.get(0));
FormattedSection section = new FormattedSection(formatter, matcher.start(), matcher.end() - 1, groups);
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) -> {
@ -55,6 +62,7 @@ public final class ChatFormatter {
else
return Integer.compare(s1.Start, s2.Start);
});
removecharpositions.sort(null);
boolean cont = true;
boolean found = false;
for (int i = 1; cont;) {
@ -124,15 +132,25 @@ public final class ChatFormatter {
cont = false;
}
}
int nextremcharpospos = 0;
for (int i = 0; i < sections.size(); i++) {
FormattedSection section = sections.get(i);
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);
Color color = null;
Format format = null;
String openlink = null;
List<Integer> removecharpositions = new ArrayList<Integer>();
section.Formatters.sort((cf2, cf1) -> cf1.priority.compareTo(cf2.priority));
for (ChatFormatter formatter : section.Formatters) {
DebugCommand.SendDebugMessage("Applying formatter: " + formatter);
@ -144,16 +162,9 @@ public final class ChatFormatter {
format = formatter.format;
if (formatter.openlink != null)
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("");
StringBuilder origtextsb = new StringBuilder(originaltext); // TODO
newtp.setText(origtextsb.toString());
newtp.setText(originaltext);
if (color != null)
newtp.setColor(color);
if (format != null)