Fixes! Escape logic again...

- Made the escape chars disappear
- Fixed empty nickname list matching empty strings
This commit is contained in:
Norbi Peti 2016-12-30 21:22:34 +01:00
parent 0f74ad4cb1
commit 2594721152
2 changed files with 38 additions and 31 deletions

View file

@ -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,26 +171,27 @@ 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()))
if (PlayerListener.nicknames.containsKey(match)) { .setColor(Color.Aqua).setOnmatch((String match) -> {
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match)); if (PlayerListener.nicknames.containsKey(match)) {
if (p == null) { Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match));
PluginMain.Instance.getLogger().warning( if (p == null) {
"Error: Can't find player nicknamed " + match + " but was reported as online."); PluginMain.Instance.getLogger().warning("Error: Can't find player nicknamed "
return "§c" + match + "§r"; + 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) Bukkit.getServer().getLogger().warning("Player nicknamed " + match
p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); + " not found in nickname map but was reported as online.");
else return "§c" + match + "§r";
p.playSound(p.getLocation(), PlayerListener.NotificationSound, 1.0f, }).setPriority(Priority.High).build());
(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());
} }
pingedconsole = false; // Will set it to true onmatch (static constructor) pingedconsole = false; // Will set it to true onmatch (static constructor)
@ -198,15 +201,16 @@ 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)))
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC, .setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
TellrawEvent.ClickAction.SUGGEST_COMMAND, suggestmsg))); TellrawEvent.ClickAction.SUGGEST_COMMAND, suggestmsg)));
json.addExtra(new TellrawPart(" <")); json.addExtra(new TellrawPart(" <"));
json.addExtra( json.addExtra(
new TellrawPart( new TellrawPart(
@ -381,9 +385,8 @@ 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");
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms"); DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");

View file

@ -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
combined.add(section); section.RemCharFromStart = 1;
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,8 +89,10 @@ 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;
@ -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();
} }
} }