Fixed chat formatting - Mostly ¯\_(ツ)_/¯ #59
2 changed files with 38 additions and 31 deletions
|
@ -135,6 +135,7 @@ public class ChatProcessing {
|
|||
namesb.append(")");
|
||||
StringBuilder nicksb = new StringBuilder();
|
||||
nicksb.append("(?i)(");
|
||||
boolean addNickFormatter = false;
|
||||
{
|
||||
final int size = Bukkit.getOnlinePlayers().size();
|
||||
int index = 0;
|
||||
|
@ -144,6 +145,7 @@ public class ChatProcessing {
|
|||
nicksb.append(nick);
|
||||
if (index < size - 1) {
|
||||
nicksb.append("|");
|
||||
addNickFormatter = true;
|
||||
}
|
||||
}
|
||||
index++;
|
||||
|
@ -169,26 +171,27 @@ public class ChatProcessing {
|
|||
return color + p.getName() + "§r";
|
||||
}).setPriority(Priority.High).build());
|
||||
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString())).setColor(Color.Aqua)
|
||||
.setOnmatch((String match) -> {
|
||||
if (PlayerListener.nicknames.containsKey(match)) {
|
||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
||||
if (p == null) {
|
||||
PluginMain.Instance.getLogger().warning(
|
||||
"Error: Can't find player nicknamed " + match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
if (addNickFormatter)
|
||||
formatters.add(new ChatFormatterBuilder().setRegex(Pattern.compile(nicksb.toString()))
|
||||
.setColor(Color.Aqua).setOnmatch((String match) -> {
|
||||
if (PlayerListener.nicknames.containsKey(match)) {
|
||||
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
|
||||
if (p == null) {
|
||||
PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
|
||||
+ match + " but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
return PluginMain.essentials.getUser(p).getNickname();
|
||||
}
|
||||
if (PlayerListener.NotificationSound == null)
|
||||
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f);
|
||||
else
|
||||
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f,
|
||||
(float) PlayerListener.NotificationPitch);
|
||||
return PluginMain.essentials.getUser(p).getNickname();
|
||||
}
|
||||
Bukkit.getServer().getLogger().warning(
|
||||
"Player nicknamed " + match + " not found in nickname map but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}).setPriority(Priority.High).build());
|
||||
Bukkit.getServer().getLogger().warning("Player nicknamed " + match
|
||||
+ " not found in nickname map but was reported as online.");
|
||||
return "§c" + match + "§r";
|
||||
}).setPriority(Priority.High).build());
|
||||
}
|
||||
|
||||
pingedconsole = false; // Will set it to true onmatch (static constructor)
|
||||
|
@ -198,15 +201,16 @@ public class ChatProcessing {
|
|||
json.addExtra(new TellrawPart("[C]").setHoverEvent(
|
||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
||||
}
|
||||
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "") + currentchannel.DisplayName)
|
||||
+ "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
|
||||
final String channelidentifier = ("[" + (sender instanceof IDiscordSender ? "d|" : "")
|
||||
+ currentchannel.DisplayName) + "]" + (mp != null && !mp.RPMode ? "[OOC]" : "");
|
||||
json.addExtra(
|
||||
new TellrawPart(channelidentifier).setHoverEvent(
|
||||
new TellrawPart(channelidentifier)
|
||||
.setHoverEvent(
|
||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
||||
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
||||
+ "Copy message").setColor(Color.Blue)))
|
||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
|
||||
TellrawEvent.ClickAction.SUGGEST_COMMAND, suggestmsg)));
|
||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
|
||||
TellrawEvent.ClickAction.SUGGEST_COMMAND, suggestmsg)));
|
||||
json.addExtra(new TellrawPart(" <"));
|
||||
json.addExtra(
|
||||
new TellrawPart(
|
||||
|
@ -381,9 +385,8 @@ public class ChatProcessing {
|
|||
player.sendMessage("§cAn error occured while sending the message.");
|
||||
return true;
|
||||
}
|
||||
PluginMain.Instance.getServer().getConsoleSender()
|
||||
.sendMessage(String.format("%s <%s> %s", channelidentifier,
|
||||
(player != null ? player.getDisplayName() : sender.getName()), message));
|
||||
PluginMain.Instance.getServer().getConsoleSender().sendMessage(String.format("%s <%s> %s", channelidentifier,
|
||||
(player != null ? player.getDisplayName() : sender.getName()), message));
|
||||
DebugCommand.SendDebugMessage(
|
||||
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
||||
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
||||
|
|
|
@ -72,8 +72,10 @@ public final class ChatFormatter {
|
|||
final FormattedSection section = sections.get(i);
|
||||
if (!section.IsRange) {
|
||||
escaped = section.Formatters.contains(ChatProcessing.ESCAPE_FORMATTER) && !escaped; // Enable escaping on first \, disable on second
|
||||
if (!escaped) // Don't add the escape character
|
||||
combined.add(section);
|
||||
if (escaped) // Don't add the escape character
|
||||
section.RemCharFromStart = 1;
|
||||
combined.add(section);
|
||||
DebugCommand.SendDebugMessage("Added " + (!escaped ? "not " : "") + "escaped section: " + section);
|
||||
continue;
|
||||
} // TODO: Actually combine overlapping sections
|
||||
if (!escaped) {
|
||||
|
@ -87,8 +89,10 @@ public final class ChatFormatter {
|
|||
DebugCommand.SendDebugMessage("Adding next section: " + 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 '\*'
|
||||
}
|
||||
}
|
||||
sections = combined;
|
||||
boolean cont = true;
|
||||
|
@ -225,6 +229,6 @@ public final class ChatFormatter {
|
|||
@Override
|
||||
public String toString() {
|
||||
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