Mostly fixed chat formatting #60
2 changed files with 38 additions and 31 deletions
|
@ -135,6 +135,7 @@ public class ChatProcessing {
|
||||||
namesb.append(")");
|
namesb.append(")");
|
||||||
StringBuilder nicksb = new StringBuilder();
|
StringBuilder nicksb = new StringBuilder();
|
||||||
nicksb.append("(?i)(");
|
nicksb.append("(?i)(");
|
||||||
|
boolean addNickFormatter = false;
|
||||||
{
|
{
|
||||||
final int size = Bukkit.getOnlinePlayers().size();
|
final int size = Bukkit.getOnlinePlayers().size();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -144,6 +145,7 @@ public class ChatProcessing {
|
||||||
nicksb.append(nick);
|
nicksb.append(nick);
|
||||||
if (index < size - 1) {
|
if (index < size - 1) {
|
||||||
nicksb.append("|");
|
nicksb.append("|");
|
||||||
|
addNickFormatter = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
@ -169,13 +171,14 @@ public class ChatProcessing {
|
||||||
return color + p.getName() + "§r";
|
return color + p.getName() + "§r";
|
||||||
}).setPriority(Priority.High).build());
|
}).setPriority(Priority.High).build());
|
||||||
|
|
||||||
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString())).setColor(Color.Aqua)
|
if (addNickFormatter)
|
||||||
.setOnmatch((String match) -> {
|
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString()))
|
||||||
|
.setColor(Color.Aqua).setOnmatch((String match) -> {
|
||||||
if (PlayerListener.nicknames.containsKey(match)) {
|
if (PlayerListener.nicknames.containsKey(match)) {
|
||||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
PluginMain.Instance.getLogger().warning(
|
PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
|
||||||
"Error: Can't find player nicknamed " + match + " but was reported as online.");
|
+ match + " but was reported as online.");
|
||||||
return "§c" + match + "§r";
|
return "§c" + match + "§r";
|
||||||
}
|
}
|
||||||
if (PlayerListener.NotificationSound == null)
|
if (PlayerListener.NotificationSound == null)
|
||||||
|
@ -185,8 +188,8 @@ public class ChatProcessing {
|
||||||
(float) PlayerListener.NotificationPitch);
|
(float) PlayerListener.NotificationPitch);
|
||||||
return PluginMain.essentials.getUser(p).getNickname();
|
return PluginMain.essentials.getUser(p).getNickname();
|
||||||
}
|
}
|
||||||
Bukkit.getServer().getLogger().warning(
|
Bukkit.getServer().getLogger().warning("Player nicknamed " + match
|
||||||
"Player nicknamed " + match + " not found in nickname map but was reported as online.");
|
+ " not found in nickname map but was reported as online.");
|
||||||
return "§c" + match + "§r";
|
return "§c" + match + "§r";
|
||||||
}).setPriority(Priority.High).build());
|
}).setPriority(Priority.High).build());
|
||||||
}
|
}
|
||||||
|
@ -198,10 +201,11 @@ public class ChatProcessing {
|
||||||
json.addExtra(new TellrawPart("[C]").setHoverEvent(
|
json.addExtra(new TellrawPart("[C]").setHoverEvent(
|
||||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
||||||
}
|
}
|
||||||
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + currentchannel.DisplayName)
|
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "")
|
||||||
+ "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
|
+ currentchannel.DisplayName) + "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
|
||||||
json.addExtra(
|
json.addExtra(
|
||||||
new TellrawPart(channelidentifier).setHoverEvent(
|
new TellrawPart(channelidentifier)
|
||||||
|
.setHoverEvent(
|
||||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
||||||
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
||||||
+ "Copy message").setColor(Color.Blue)))
|
+ "Copy message").setColor(Color.Blue)))
|
||||||
|
@ -381,8 +385,7 @@ public class ChatProcessing {
|
||||||
player.sendMessage("§cAn error occured while sending the message.");
|
player.sendMessage("§cAn error occured while sending the message.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PluginMain.Instance.getServer().getConsoleSender()
|
PluginMain.Instance.getServer().getConsoleSender().sendMessage(String.format("%s <%s> %s", channelidentifier,
|
||||||
.sendMessage(String.format("%s <%s> %s", channelidentifier,
|
|
||||||
(player != null ? player.getDisplayName() : sender.getName()), message));
|
(player != null ? player.getDisplayName() : sender.getName()), message));
|
||||||
DebugCommand.SendDebugMessage(
|
DebugCommand.SendDebugMessage(
|
||||||
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
||||||
|
|
|
@ -72,8 +72,10 @@ public final class ChatFormatter {
|
||||||
final FormattedSection section = sections.get(i);
|
final FormattedSection section = sections.get(i);
|
||||||
if (!section.IsRange) {
|
if (!section.IsRange) {
|
||||||
escaped = section.Formatters.contains(ChatProcessing.ESCAPE_FORMATTER) && !escaped; // Enable escaping on first \, disable on second
|
escaped = section.Formatters.contains(ChatProcessing.ESCAPE_FORMATTER) && !escaped; // Enable escaping on first \, disable on second
|
||||||
if (!escaped) // Don't add the escape character
|
if (escaped) // Don't add the escape character
|
||||||
|
section.RemCharFromStart = 1;
|
||||||
combined.add(section);
|
combined.add(section);
|
||||||
|
DebugCommand.SendDebugMessage("Added " + (!escaped ? "not " : "") + "escaped section: " + section);
|
||||||
continue;
|
continue;
|
||||||
} // TODO: Actually combine overlapping sections
|
} // TODO: Actually combine overlapping sections
|
||||||
if (!escaped) {
|
if (!escaped) {
|
||||||
|
@ -87,9 +89,11 @@ public final class ChatFormatter {
|
||||||
DebugCommand.SendDebugMessage("Adding next section: " + section);
|
DebugCommand.SendDebugMessage("Adding next section: " + section);
|
||||||
nextSection.put(section.Formatters.get(0), section);
|
nextSection.put(section.Formatters.get(0), section);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
|
DebugCommand.SendDebugMessage("Skipping section: " + section);
|
||||||
escaped = false; // Reset escaping if applied, like if we're at the '*' in '\*'
|
escaped = false; // Reset escaping if applied, like if we're at the '*' in '\*'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sections = combined;
|
sections = combined;
|
||||||
boolean cont = true;
|
boolean cont = true;
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
@ -225,6 +229,6 @@ public final class ChatFormatter {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new StringBuilder("F(").append(color).append(", ").append(format).append(", ").append(openlink)
|
return new StringBuilder("F(").append(color).append(", ").append(format).append(", ").append(openlink)
|
||||||
.append(", ").append(priority).append(")").toString();
|
.append(", ").append(priority).append(", ").append(regex).append(")").toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue